Skip to content

Commit

Permalink
[SC-30797] Superadmin provisions (#16)
Browse files Browse the repository at this point in the history
* added provisions for passing shared cookies (credentials)

* replace present with !empty

* rubocop fixes

* fixed typo

* more fixes
  • Loading branch information
phenchaw authored Oct 11, 2023
1 parent 66a840b commit 88a9931
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
20 changes: 10 additions & 10 deletions lib/payroll_hero/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ module Api
define_setting :debug, false
define_setting :application_name, :none

def self.new(token)
def self.new(token, cookies = {})
sections = {
v2: {
worksites: V2::Worksites.new(token),
worksites: V2::Worksites.new(token, cookies),
},
v3: {
day_schedules: V3::DaySchedules.new(token),
employees: V3::Employees.new(token),
attendance_days: V3::AttendanceDays.new(token),
day_schedules: V3::DaySchedules.new(token, cookies),
employees: V3::Employees.new(token, cookies),
attendance_days: V3::AttendanceDays.new(token, cookies),
},
v4: {
employees: V4::Employees.new(token),
leaves: V4::Leaves.new(token),
permissions: V4::Permissions.new(token),
shifts: V4::Shifts.new(token),
schedule_events: V4::ScheduleEvents.new(token),
employees: V4::Employees.new(token, cookies),
leaves: V4::Leaves.new(token, cookies),
permissions: V4::Permissions.new(token, cookies),
shifts: V4::Shifts.new(token, cookies),
schedule_events: V4::ScheduleEvents.new(token, cookies),
}
}
Hashie::Mash.new(sections)
Expand Down
8 changes: 4 additions & 4 deletions lib/payroll_hero/api/base_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module PayrollHero
module Api

class BaseGroup
def initialize(token)
@client = new_client(token, :core)
def initialize(token, cookies = {})
@client = new_client(token, :core, cookies)
end


Expand All @@ -15,8 +15,8 @@ def base_url_for(name)
PayrollHero::Api.send("#{name}_base_url")
end

def new_client(token, name)
Client.new(token, base_url_for(name))
def new_client(token, name, cookies)
Client.new(token, base_url_for(name), cookies)
end

def remove_nil_values_from!(hash)
Expand Down
3 changes: 2 additions & 1 deletion lib/payroll_hero/api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ module Api
class Client
attr_reader :client

def initialize(token, base_url)
def initialize(token, base_url, cookies = {})
headers = {
'User-Agent' => user_agent_string,
}
headers.merge!({ 'Cookie' => cookies.map { |key, value| "#{key}=#{value}" }.join('; ') }) unless cookies.nil? || cookies.empty?
params = {
token: token,
}
Expand Down

0 comments on commit 88a9931

Please sign in to comment.