Class: PaychexAPI::Client
- Inherits:
-
Footrest::Client
- Object
- Footrest::Client
- PaychexAPI::Client
- Defined in:
- lib/paychex_api/client.rb,
lib/paychex_api/client/workers.rb,
lib/paychex_api/client/companies.rb
Defined Under Namespace
Constant Summary collapse
- API_PATH =
""- COMPANIES_PATH =
'/companies'- ORGANIZATIONS_PATH =
'/organizations'- JOB_TITLES_PATH =
'/jobtitles'- WORKER_STATUSES_PATH =
'/workerstatuses'- WORKERS_PATH =
'/workers'- COMMUNICATIONS_PATH =
'/communications'- COMPENSATION_PATH =
'/compensation'- DIRECT_DEPOSITS_PATH =
'/directdeposits'- PAY_PERIODS_PATH =
'/payperiods'- PAY_COMPONENTS_PATH =
'/paycomponents'- CHECKS_PATH =
'/checks'- OAUTH_TOKEN_PATH =
'/auth/oauth/v2/token'
Instance Attribute Summary collapse
-
#authorization ⇒ Object
readonly
Returns the value of attribute authorization.
Instance Method Summary collapse
- #get_default_faraday ⇒ Object
-
#request(method, &block) ⇒ Object
Override Footrest request for ApiArray support.
- #set_connection(config) ⇒ Object
Instance Attribute Details
#authorization ⇒ Object (readonly)
Returns the value of attribute authorization.
29 30 31 |
# File 'lib/paychex_api/client.rb', line 29 def @authorization end |
Instance Method Details
#get_default_faraday ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/paychex_api/client.rb', line 60 def get_default_faraday Faraday.new(url: config[:prefix]) do |faraday| faraday.request :multipart faraday.request :url_encoded if config[:logger] == true faraday.response :logger elsif config[:logger] faraday.use Faraday::Response::Logger, config[:logger] end faraday.use Footrest::FollowRedirects, limit: 5 unless config[:follow_redirects] == false faraday.adapter Faraday.default_adapter faraday.use Footrest::ParseJson, :content_type => /\bjson$/ faraday.use Footrest::RaiseFootrestErrors faraday.use Footrest::Pagination faraday.headers[:accept] = "application/json" faraday.headers[:user_agent] = "Footrest" end end |
#request(method, &block) ⇒ Object
Override Footrest request for ApiArray support
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/paychex_api/client.rb', line 37 def request(method, &block) if @authorization.blank? || @authorization['expiration'] <= DateTime.now - 30.seconds temp_client = get_default_faraday response = temp_client.post( OAUTH_TOKEN_PATH, { client_id: config[:client_id], client_secret: config[:client_secret], grant_type: 'client_credentials' } ) @authorization = response.body @authorization['expiration'] = DateTime.now + @authorization['expires_in'].to_i.seconds end connection.headers[:authorization] = "Bearer #{@authorization['access_token']}" ApiArray::process_response(connection.send(method, &block), self) end |
#set_connection(config) ⇒ Object
55 56 57 58 |
# File 'lib/paychex_api/client.rb', line 55 def set_connection(config) config[:logger] = config[:logging] if config[:logging] @connection = get_default_faraday end |