paychex_api 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 758c001f0cf47cdd37c2e59088fbba2a9ffa8c2e
4
+ data.tar.gz: bde50ccd01aeb9f777074b41ac4fd766cb893437
5
+ SHA512:
6
+ metadata.gz: 005a408302d26519b98a7cfcb04b602d1290e452cebf794880f14350626c3e6983ce0d8fb3b54ba90b698f1d0f2814ed0b25c132c972acc48974c77cd9e09be0
7
+ data.tar.gz: fa0bb1560f60452e3220bd045a2bf383660de76fa5d8436d497ec1cdcab92b0baea68070e823c94e7192c275c4dba06c7d8b51046e1a64abb8ddc89a18beba0b
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+
2
+ /.*.iml
3
+ .idea/
4
+ bridge_api.iml
5
+ .byebug.*
6
+ .byebug_history
7
+ .*.gem
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,85 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bridge_api (0.0.1)
5
+ faraday (~> 0.9.0)
6
+ faraday_middleware (~> 0.9.0)
7
+ footrest (>= 0.5.1)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (5.1.4)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (~> 0.7)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ addressable (2.5.2)
18
+ public_suffix (>= 2.0.2, < 4.0)
19
+ byebug (8.2.5)
20
+ coderay (1.1.2)
21
+ concurrent-ruby (1.0.5)
22
+ crack (0.4.3)
23
+ safe_yaml (~> 1.0.0)
24
+ diff-lcs (1.3)
25
+ faraday (0.9.2)
26
+ multipart-post (>= 1.2, < 3)
27
+ faraday_middleware (0.9.2)
28
+ faraday (>= 0.7.4, < 0.10)
29
+ footrest (0.5.1)
30
+ activesupport (>= 3.0.0)
31
+ faraday (~> 0.9.0)
32
+ link_header (>= 0.0.7)
33
+ hashdiff (0.3.7)
34
+ i18n (0.9.1)
35
+ concurrent-ruby (~> 1.0)
36
+ link_header (0.0.8)
37
+ method_source (0.9.0)
38
+ minitest (5.11.1)
39
+ multipart-post (2.0.0)
40
+ pry (0.11.3)
41
+ coderay (~> 1.1.0)
42
+ method_source (~> 0.9.0)
43
+ public_suffix (3.0.1)
44
+ rack (1.6.8)
45
+ rack-protection (1.5.3)
46
+ rack
47
+ rake (0.9.6)
48
+ rspec (2.99.0)
49
+ rspec-core (~> 2.99.0)
50
+ rspec-expectations (~> 2.99.0)
51
+ rspec-mocks (~> 2.99.0)
52
+ rspec-core (2.99.2)
53
+ rspec-expectations (2.99.2)
54
+ diff-lcs (>= 1.1.3, < 2.0)
55
+ rspec-mocks (2.99.4)
56
+ safe_yaml (1.0.4)
57
+ sinatra (1.4.8)
58
+ rack (~> 1.5)
59
+ rack-protection (~> 1.4)
60
+ tilt (>= 1.3, < 3)
61
+ thread_safe (0.3.6)
62
+ tilt (1.4.1)
63
+ tzinfo (1.2.4)
64
+ thread_safe (~> 0.1)
65
+ webmock (1.22.6)
66
+ addressable (>= 2.3.6)
67
+ crack (>= 0.3.2)
68
+ hashdiff
69
+
70
+ PLATFORMS
71
+ ruby
72
+
73
+ DEPENDENCIES
74
+ bridge_api!
75
+ bundler (~> 1.0, >= 1.0.0)
76
+ byebug (~> 8.2.2)
77
+ pry (~> 0)
78
+ rake (~> 0)
79
+ rspec (~> 2.6)
80
+ sinatra (~> 1.0)
81
+ tilt (~> 1.3, >= 1.3.4)
82
+ webmock (~> 1.22.6)
83
+
84
+ BUNDLED WITH
85
+ 1.16.0
@@ -0,0 +1,2 @@
1
+ require 'paychex_api/version'
2
+ require 'paychex_api/client'
@@ -0,0 +1,143 @@
1
+
2
+ module PaychexAPI
3
+ class ApiArray
4
+ include Enumerable
5
+
6
+ @next_page = nil
7
+ @prev_page = nil
8
+
9
+ attr_reader :status, :headers, :members, :links, :metadata, :members
10
+
11
+ def self.process_response(response, api_client)
12
+ ApiArray.new(response, api_client)
13
+ end
14
+
15
+ def initialize(response, api_client)
16
+ @meta_fields = %w(metadata links)
17
+ @api_client = api_client
18
+ @links = []
19
+ @metadata = {}
20
+ case response.status
21
+ when *((200..206).to_a + [302])
22
+ apply_response_metadata(response)
23
+ @members = get_response_content(response)
24
+ end
25
+ end
26
+
27
+ def length
28
+ @members.length
29
+ end
30
+
31
+ def [](i)
32
+ @members[i]
33
+ end
34
+
35
+ def last
36
+ @members.last
37
+ end
38
+
39
+ def each(&block)
40
+ @members.each { |member| block.call(member) }
41
+ end
42
+
43
+ def pages?
44
+ !@next_page.nil?
45
+ end
46
+
47
+ def next_page
48
+ load_page(@next_page)
49
+ end
50
+
51
+ def each_page(&block)
52
+ block.call(@members, @linked, @meta)
53
+ while @next_page
54
+ response = get_page(@next_page)
55
+ apply_response_metadata(response, false)
56
+ @members = get_response_content(response)
57
+ block.call(@members, @linked, @meta)
58
+ end
59
+ @link_hash = {}
60
+ end
61
+
62
+ def all_pages!
63
+ if pages?
64
+ response = get_page(@next_page)
65
+ apply_response_metadata(response)
66
+ @members.concat(get_response_content(response))
67
+ while @next_page
68
+ response = get_page(@next_page)
69
+ apply_response_metadata(response)
70
+ @members.concat(get_response_content(response))
71
+ end
72
+ end
73
+ self
74
+ end
75
+
76
+ private
77
+
78
+ def get_page(url, params = {})
79
+ query = URI.parse(url).query
80
+ p = CGI.parse(query).merge(params)
81
+ u = url.gsub("?#{query}", '')
82
+ p.each { |k, v| p[k] = v.first if v.is_a?(Array) }
83
+ @api_client.connection.send(:get) do |r|
84
+ r.url(u, p)
85
+ end
86
+ end
87
+
88
+ def load_page(url)
89
+ response = get_page(url)
90
+ ApiArray.process_response(response, @api_client)
91
+ end
92
+
93
+ def get_response_content(response)
94
+ return [] unless response.body.is_a?(Hash)
95
+ content = response.body['content']
96
+ if content.length > 0
97
+ return content
98
+ end
99
+ []
100
+ end
101
+
102
+ def apply_response_metadata(response, concat = true)
103
+ unless concat
104
+ @links = {}
105
+ @metadata = {}
106
+ end
107
+ @status = response.status
108
+ @headers = response.headers
109
+ @method = response.env[:method]
110
+ init_pages(response)
111
+ init_linked(response)
112
+ init_meta(response)
113
+ end
114
+
115
+ def init_linked(response)
116
+ if response.body.is_a?(Hash) && response.body.key?('links')
117
+ @links = @links.concat(response.body['links'])
118
+ end
119
+ end
120
+
121
+ def init_meta(response)
122
+ if response.body.is_a?(Hash) && response.body.key?('metadata')
123
+ @metadata = response.body['metadata']
124
+ end
125
+ end
126
+
127
+ def init_pages(response)
128
+ @next_page = nil
129
+ @prev_page = nil
130
+ if response.body.is_a?(Hash) && response.body.key?('links')
131
+ response.body['links'].each do |link|
132
+ case link['rel']
133
+ when 'next'
134
+ @next_page = link['href']
135
+ when 'prev'
136
+ @prev_page = link['href']
137
+ end
138
+ end
139
+ end
140
+ end
141
+
142
+ end
143
+ end
@@ -0,0 +1,79 @@
1
+ require 'footrest/client'
2
+ require 'faraday'
3
+ require 'footrest'
4
+ require 'footrest/http_error'
5
+ require 'footrest/pagination'
6
+ require 'footrest/follow_redirects'
7
+ require 'footrest/parse_json'
8
+ require 'base64'
9
+ require 'active_support/time'
10
+ require 'paychex_api/api_array'
11
+
12
+ module PaychexAPI
13
+ class Client < Footrest::Client
14
+
15
+ API_PATH = ""
16
+ COMPANIES_PATH = '/companies'
17
+ ORGANIZATIONS_PATH = '/organizations'
18
+ JOB_TITLES_PATH = '/jobtitles'
19
+ WORKER_STATUSES_PATH = '/workerstatuses'
20
+ WORKERS_PATH = '/workers'
21
+ COMMUNICATIONS_PATH = '/communications'
22
+ COMPENSATION_PATH = '/compensation'
23
+ DIRECT_DEPOSITS_PATH = '/directdeposits'
24
+ PAY_PERIODS_PATH = '/payperiods'
25
+ PAY_COMPONENTS_PATH = '/paycomponents'
26
+ CHECKS_PATH = '/checks'
27
+ OAUTH_TOKEN_PATH = '/auth/oauth/v2/token'
28
+
29
+ attr_reader :authorization
30
+
31
+ Dir[File.dirname(__FILE__) + '/client/*.rb'].each do |file|
32
+ require file
33
+ include self.const_get("#{File.basename(file).gsub('.rb','').split("_").map{|ea| ea.capitalize}.join('')}")
34
+ end
35
+
36
+ # Override Footrest request for ApiArray support
37
+ def request(method, &block)
38
+ if @authorization.blank? || @authorization['expiration'] <= DateTime.now - 30.seconds
39
+ temp_client = get_default_faraday
40
+ response = temp_client.post(
41
+ OAUTH_TOKEN_PATH,
42
+ {
43
+ client_id: config[:client_id],
44
+ client_secret: config[:client_secret],
45
+ grant_type: 'client_credentials'
46
+ }
47
+ )
48
+ @authorization = response.body
49
+ @authorization['expiration'] = DateTime.now + @authorization['expires_in'].to_i.seconds
50
+ end
51
+ connection.headers[:authorization] = "Bearer #{@authorization['access_token']}"
52
+ ApiArray::process_response(connection.send(method, &block), self)
53
+ end
54
+
55
+ def set_connection(config)
56
+ config[:logger] = config[:logging] if config[:logging]
57
+ @connection = get_default_faraday
58
+ end
59
+
60
+ def get_default_faraday
61
+ Faraday.new(url: config[:prefix]) do |faraday|
62
+ faraday.request :multipart
63
+ faraday.request :url_encoded
64
+ if config[:logger] == true
65
+ faraday.response :logger
66
+ elsif config[:logger]
67
+ faraday.use Faraday::Response::Logger, config[:logger]
68
+ end
69
+ faraday.use Footrest::FollowRedirects, limit: 5 unless config[:follow_redirects] == false
70
+ faraday.adapter Faraday.default_adapter
71
+ faraday.use Footrest::ParseJson, :content_type => /\bjson$/
72
+ faraday.use Footrest::RaiseFootrestErrors
73
+ faraday.use Footrest::Pagination
74
+ faraday.headers[:accept] = "application/json"
75
+ faraday.headers[:user_agent] = "Footrest"
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,24 @@
1
+ module PaychexAPI
2
+ class Client
3
+ module Companies
4
+
5
+ def get_company(company_id, params = {})
6
+ get("#{API_PATH}#{COMPANIES_PATH}/#{company_id}", params)
7
+ end
8
+
9
+ def get_company_by_display_id(display_id, params = {})
10
+ params = params.merge({displayid: display_id})
11
+ get("#{API_PATH}#{COMPANIES_PATH}", params)
12
+ end
13
+
14
+ def get_organizations(company_id, organization_id, params = {})
15
+ get("#{API_PATH}#{COMPANIES_PATH}/#{company_id}#{ORGANIZATIONS_PATH}", params)
16
+ end
17
+
18
+ def get_organization(company_id, organization_id, params = {})
19
+ get("#{API_PATH}#{COMPANIES_PATH}/#{company_id}#{ORGANIZATIONS_PATH}/#{organization_id}", params)
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ module PaychexAPI
2
+ class Client
3
+ module Workers
4
+
5
+ def get_all_workers(company_id, params = {})
6
+ get("#{API_PATH}#{COMPANIES_PATH}/#{company_id}#{WORKERS_PATH}", params)
7
+ end
8
+
9
+ def get_communications(worker_id, params = {})
10
+ get("#{API_PATH}#{WORKERS_PATH}/#{worker_id}#{COMMUNICATIONS_PATH}", params)
11
+ end
12
+
13
+ def get_communication(worker_id, communication_id, params = {})
14
+ get("#{API_PATH}#{WORKERS_PATH}/#{worker_id}#{COMMUNICATIONS_PATH}/#{communication_id}", params)
15
+ end
16
+
17
+ def create_communication(worker_id, params = {})
18
+ post("#{API_PATH}#{WORKERS_PATH}/#{worker_id}#{COMMUNICATIONS_PATH}", params)
19
+ end
20
+
21
+ def update_communication(worker_id, communication_id, params = {})
22
+ put("#{API_PATH}#{WORKERS_PATH}/#{worker_id}#{COMMUNICATIONS_PATH}/#{communication_id}", params)
23
+ end
24
+
25
+ def delete_communication(worker_id, communication_id, params = {})
26
+ delete("#{API_PATH}#{WORKERS_PATH}/#{worker_id}#{COMMUNICATIONS_PATH}/#{communication_id}", params)
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module PaychexAPI
2
+ VERSION = '0.0.1' unless defined?(PaychexAPI::VERSION)
3
+ end
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'paychex_api/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.authors = ["Jay Shaffer"]
7
+ gem.email = ["jshaffer@instructure.com"]
8
+ gem.description = %q{Interface for interacting with the paychex enterprise API}
9
+ gem.summary = %q{Paychex API}
10
+ gem.homepage = ""
11
+ gem.license = 'MIT'
12
+
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.files += Dir.glob("lib/**/*.rb")
15
+ gem.files += Dir.glob("spec/**/*")
16
+ gem.test_files = Dir.glob("spec/**/*")
17
+ gem.name = "paychex_api"
18
+ gem.require_paths = ["lib"]
19
+ gem.version = PaychexAPI::VERSION
20
+
21
+ gem.add_development_dependency 'rake', '~> 0'
22
+ gem.add_development_dependency 'bundler', '~> 1.0', '>= 1.0.0'
23
+ gem.add_development_dependency 'rspec', '~> 2.6'
24
+ gem.add_development_dependency 'webmock', '~>1.22.6'
25
+ gem.add_development_dependency 'pry', '~> 0'
26
+ gem.add_development_dependency 'tilt', '>= 1.3.4', '~> 1.3'
27
+ gem.add_development_dependency 'sinatra', '~> 1.0'
28
+ gem.add_development_dependency 'byebug', '~> 8.2.2'
29
+
30
+ gem.add_dependency 'footrest', '>= 0.5.1'
31
+ gem.add_dependency 'faraday', '~> 0.9.0'
32
+ gem.add_dependency 'faraday_middleware', '~> 0.9.0'
33
+
34
+ end
@@ -0,0 +1,6 @@
1
+ {
2
+ "access_token": "99f9c30a-8134-4a30-a789-7c7665add41e",
3
+ "token_type": "Bearer",
4
+ "expires_in": 600,
5
+ "scope": "oob"
6
+ }
@@ -0,0 +1,99 @@
1
+ {
2
+ "content": [
3
+ {
4
+ "communicationId": "00Z5V9BTINBT97UMERCA",
5
+ "type": "EMAIL",
6
+ "usageType": "BUSINESS",
7
+ "uri": "jd_work@noreplay.com",
8
+ "links": [
9
+ {
10
+ "rel": "self",
11
+ "href": "https://api.paychex.com/workers/00Z5V9BTIHRQF2CF7BTH/communications/00Z5V9BTINBT97UMERCA"
12
+ }
13
+ ]
14
+ },
15
+ {
16
+ "communicationId": "00Z5V9BTINBT97UMERCB",
17
+ "type": "PHONE",
18
+ "usageType": "BUSINESS",
19
+ "dialCountry": "1",
20
+ "dialArea": "999",
21
+ "dialNumber": "8887777",
22
+ "dialExtension": "6",
23
+ "links": [
24
+ {
25
+ "rel": "self",
26
+ "href": "https://api.paychex.com/workers/00Z5V9BTIHRQF2CF7BTH/communications/00Z5V9BTINBT97UMERCB"
27
+ }
28
+ ]
29
+ },
30
+ {
31
+ "communicationId": "00Z5V9BTINBT97UMERCC",
32
+ "type": "MOBILE_PHONE",
33
+ "usageType": "BUSINESS",
34
+ "dialCountry": "1",
35
+ "dialArea": "777",
36
+ "dialNumber": "6665555",
37
+ "links": [
38
+ {
39
+ "rel": "self",
40
+ "href": "https://api.paychex.com/workers/00Z5V9BTIHRQF2CF7BTH/communications/00Z5V9BTINBT97UMERCC"
41
+ }
42
+ ]
43
+ },
44
+ {
45
+ "communicationId": "00Z5V9BTINBT97UMERCD",
46
+ "type": "FAX",
47
+ "usageType": "BUSINESS",
48
+ "dialCountry": "1",
49
+ "dialArea": "555",
50
+ "dialNumber": "4443333",
51
+ "links": [
52
+ {
53
+ "rel": "self",
54
+ "href": "https://api.paychex.com/workers/00Z5V9BTIHRQF2CF7BTH/communications/00Z5V9BTINBT97UMERCD"
55
+ }
56
+ ]
57
+ },
58
+ {
59
+ "communicationId": "00Z5V9BTINBT97UMERCE",
60
+ "type": "PAGER",
61
+ "usageType": "BUSINESS",
62
+ "dialCountry": "1",
63
+ "dialArea": "666",
64
+ "dialNumber": "5554444",
65
+ "links": [
66
+ {
67
+ "rel": "self",
68
+ "href": "https://api.paychex.com/workers/00Z5V9BTIHRQF2CF7BTH/communications/00Z5V9BTINBT97UMERCE"
69
+ }
70
+ ]
71
+ },
72
+ {
73
+ "communicationId": "00Z5V9BTINBT97UMERCF",
74
+ "type": "STREET_ADDRESS",
75
+ "streetLineOne": "1 Main Street",
76
+ "streetLineTwo": "Office 3",
77
+ "city": "Webster",
78
+ "countrySubdivisionCode": "NEW_YORK",
79
+ "postalCode": "14580",
80
+ "countryCode": "US",
81
+ "links": [
82
+ {
83
+ "rel": "self",
84
+ "href": "https://api.paychex.com/workers/00Z5V9BTIHRQF2CF7BTH/communications/00Z5V9BTINBT97UMERCF"
85
+ }
86
+ ]
87
+ }
88
+ ],
89
+ "links": [
90
+ {
91
+ "rel": "self",
92
+ "href": "https://api.paychex.com/workers/00Z5V9BTIHRQF2CF7BTH/communications"
93
+ },
94
+ {
95
+ "rel": "create",
96
+ "href": "https://api.paychex.com/workers/00Z5V9BTIHRQF2CF7BTH/communications"
97
+ }
98
+ ]
99
+ }
@@ -0,0 +1,38 @@
1
+ {
2
+ "metadata": {"contentItemCount": 1},
3
+ "content": [ {
4
+ "companyId": "99Z5V9BTI8J2FCGESC05",
5
+ "displayId": "09620579",
6
+ "legalName": "Monsters, Inc",
7
+ "legalId": {
8
+ "legalIdType": "FEIN",
9
+ "legalIdValue": "995886885"
10
+ },
11
+ "communications": [ {
12
+ "type": "STREET_ADDRESS",
13
+ "usageType": "BUSINESS",
14
+ "streetLineOne": "Mike St",
15
+ "streetLineTwo": "Sulley Ln",
16
+ "city": "ANAHEIM",
17
+ "countrySubdivisionCode": "CA",
18
+ "postalCode": "92802",
19
+ "countryCode": "US"
20
+ }],
21
+ "links": [
22
+ {
23
+ "rel": "self",
24
+ "href": "https://api.paychex.com/companies/99Z5V9BTI8J2FCGESC05"
25
+ },
26
+ {
27
+ "rel": "workers",
28
+ "href": "https://api.paychex.com/companies/99Z5V9BTI8J2FCGESC05/workers"
29
+ }
30
+ ]
31
+ }],
32
+ "links": [
33
+ {
34
+ "rel": "self",
35
+ "href": "https://api.paychex.com/companies"
36
+ }
37
+ ]
38
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "content": [
3
+ {
4
+ "organizationId": "970000055981384",
5
+ "name": "2 Division B",
6
+ "links": [
7
+ {
8
+ "rel": "self",
9
+ "href": "https://api.paychex.com/companies/99Z5V9BTI8J2FCGESC05/organizations/970000055981384"
10
+ },
11
+ {
12
+ "rel": "parent",
13
+ "href": "https://api.paychex.com/companies/99Z5V9BTI8J2FCGESC05/organizations/970000055981383"
14
+ },
15
+ {
16
+ "rel": "child",
17
+ "href": "https://api.paychex.com/companies/99Z5V9BTI8J2FCGESC05/organizations/970000055981385"
18
+ },
19
+ {
20
+ "rel": "child",
21
+ "href": "https://api.paychex.com/companies/99Z5V9BTI8J2FCGESC05/organizations/970000055981386"
22
+ }
23
+ ]
24
+ }
25
+ ],
26
+ "links": [
27
+ {
28
+ "rel": "self",
29
+ "href": "https://api.paychex.com/companies/99Z5V9BTI8J2FCGESC05/organizations"
30
+ }
31
+ ]
32
+ }
@@ -0,0 +1,85 @@
1
+ {
2
+ "metadata": {
3
+ "contentItemCount": 5,
4
+ "pagination": {
5
+ "offset": 5,
6
+ "limit": 5,
7
+ "itemCount": 56
8
+ }
9
+ },
10
+ "content": [
11
+ {
12
+ "workerId": "00Z5V9BTIHRQF2CF7BTH",
13
+ "employeeId": "3052",
14
+ "workerType": "EMPLOYEE",
15
+ "employmentType": "FULL_TIME",
16
+ "exemptionType": "NON_EXEMPT",
17
+ "birthDate": "1899-07-01T00:00:00Z",
18
+ "clockId": "4321",
19
+ "sex": "MALE",
20
+ "ethnicityCode": "WHITE_NOT_OF_HISPANIC_ORIGIN",
21
+ "hireDate": "2015-06-15T00:00:00Z",
22
+ "name": {
23
+ "familyName": "JONES",
24
+ "middleName": "H",
25
+ "givenName": "INDIANA",
26
+ "preferredName": "Indi",
27
+ "qualificationAffixCode": "Jr",
28
+ "titleAffixCode": "DR"
29
+ },
30
+ "legalId": {
31
+ "legalIdType": "SSN",
32
+ "legalIdValue": "333221111"
33
+ },
34
+ "currentStatus": {
35
+ "workerStatusId": "00DWS906IMW2JSH8AQJ9",
36
+ "statusReason": "HIRED",
37
+ "statusType": "ACTIVE",
38
+ "effectiveDate": "2015-06-15T00:00:00Z"
39
+ },
40
+ "job": {
41
+ "jobTitleId": "00DWS906IMW2JSH8AQJ8",
42
+ "title": "Archaeologist"
43
+ },
44
+ "organization": {
45
+ "organizationId": "970000055981384",
46
+ "name": "2 Division B"
47
+ },
48
+ "supervisor": {
49
+ "workerId": "00H2A1IUJ4IPERJ589YE",
50
+ "name": {
51
+ "familyName": "Scott",
52
+ "givenName": "Willie"
53
+ }
54
+ },
55
+ "links": [
56
+ {
57
+ "rel": "self",
58
+ "href": "https://api.paychex.com/workers/00Z5V9BTIHRQF2CF7BTH"
59
+ },
60
+ {
61
+ "rel": "communications",
62
+ "href": "https://api.paychex.com/workers/00Z5V9BTIHRQF2CF7BTF/communications"
63
+ },
64
+ {
65
+ "rel": "supervisor",
66
+ "href": "https://api.paychex.com/workers/00H2A1IUJ4IPERJ589YE"
67
+ }
68
+ ]
69
+ }
70
+ ],
71
+ "links": [
72
+ {
73
+ "rel": "self",
74
+ "href": "https://api.paychex.com/companies/00Z5V9BTI8J2FCGESC05/workers?offset=5&limit=5"
75
+ },
76
+ {
77
+ "rel": "next",
78
+ "href": "https://api.paychex.com/companies/00Z5V9BTI8J2FCGESC05/workers?offset=10&limit=5"
79
+ },
80
+ {
81
+ "rel": "prev",
82
+ "href": "https://api.paychex.com/companies/00Z5V9BTI8J2FCGESC05/workers?offset=0&limit=5"
83
+ }
84
+ ]
85
+ }
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+ describe PaychexAPI::Client::Companies do
3
+
4
+ before do
5
+ @client = PaychexAPI::Client.new(prefix: "http://test.paychex.com", client_id: "client_id", client_secret: 'client_secret')
6
+ end
7
+
8
+ it 'should get a company' do
9
+ response = @client.get_company(1)
10
+ expect(response.first['companyId']).to(eq("99Z5V9BTI8J2FCGESC05"))
11
+ end
12
+
13
+ it 'should get a company by display id' do
14
+ response = @client.get_company_by_display_id(1)
15
+ expect(response.first['companyId']).to(eq("99Z5V9BTI8J2FCGESC05"))
16
+ end
17
+
18
+ it 'should get organizations' do
19
+ response = @client.get_organizations(1, 2)
20
+ expect(response.first['organizationId']).to(eq("970000055981384"))
21
+ end
22
+
23
+ end
@@ -0,0 +1,33 @@
1
+ require 'test_helper'
2
+ describe PaychexAPI::Client::Workers do
3
+
4
+ before do
5
+ @client = PaychexAPI::Client.new(prefix: "http://test.paychex.com", client_id: "client_id", client_secret: 'client_secret')
6
+ end
7
+
8
+ it 'should get all workers' do
9
+ response = @client.get_all_workers("1")
10
+ expect(response.first['workerId']).to(eq("00Z5V9BTIHRQF2CF7BTH"))
11
+ end
12
+
13
+ it 'should get all communications' do
14
+ response = @client.get_communications(1)
15
+ expect(response.first['communicationId']).to(eq("00Z5V9BTINBT97UMERCA"))
16
+ end
17
+
18
+ it 'should get a communication' do
19
+ response = @client.get_communication(1, 1)
20
+ expect(response.first['communicationId']).to(eq("00Z5V9BTINBT97UMERCA"))
21
+ end
22
+
23
+ it 'should get create a communication' do
24
+ response = @client.create_communication(1)
25
+ expect(response.first['communicationId']).to(eq("00Z5V9BTINBT97UMERCA"))
26
+ end
27
+
28
+ it 'should update a communication' do
29
+ response = @client.update_communication(1, 1, {something: 'something'})
30
+ expect(response.first['communicationId']).to(eq("00Z5V9BTINBT97UMERCA"))
31
+ end
32
+
33
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ describe PaychexAPI::Client do
4
+
5
+ it 'should pull the auth token' do
6
+ client = PaychexAPI::Client.new(prefix: "https://www.fake.com", client_id: "client_id", client_secret: 'client_secret')
7
+ client.get_all_workers("1")
8
+ expect(client.authorization['access_token']).to(eq('99f9c30a-8134-4a30-a789-7c7665add41e'))
9
+ end
10
+
11
+ it 'should skip pulling the auth token' do
12
+ client = PaychexAPI::Client.new(prefix: "https://www.fake.com", client_id: "client_id", client_secret: 'client_secret')
13
+ expect(client.authorization).to(eq(nil))
14
+ client.get_all_workers("1")
15
+ expect(client.authorization['access_token']).to(eq('99f9c30a-8134-4a30-a789-7c7665add41e'))
16
+ expect_any_instance_of(Faraday).not_to receive(:post)
17
+ client.get_all_workers("1")
18
+ end
19
+
20
+ it 'should set the auth header to bearer auth' do
21
+ client = PaychexAPI::Client.new(prefix: "https://www.fake.com", client_id: "client_id", client_secret: 'client_secret')
22
+ client.get_all_workers("1")
23
+ expect(client.connection.headers['Authorization']).to(eq("Bearer 99f9c30a-8134-4a30-a789-7c7665add41e"))
24
+ end
25
+
26
+ end
@@ -0,0 +1,61 @@
1
+ require 'sinatra/base'
2
+ require 'tilt'
3
+
4
+ class FakePaychex < Sinatra::Base
5
+
6
+ #auth
7
+ post %r{/auth/oauth/v2/token$} do
8
+ get_json_data 200, 'auth.json'
9
+ end
10
+
11
+ #workers
12
+ get %r{/companies/\d+/workers$} do
13
+ get_json_data 200, 'workers.json'
14
+ end
15
+
16
+ get %r{/workers/\d+/communications$} do
17
+ get_json_data 200, 'communications.json'
18
+ end
19
+
20
+ get %r{/workers/\d+/communications/\d+$} do
21
+ get_json_data 200, 'communications.json'
22
+ end
23
+
24
+ post %r{/workers/\d+/communications$} do
25
+ get_json_data 200, 'communications.json'
26
+ end
27
+
28
+ put %r{/workers/\d+/communications/\d+$} do
29
+ get_json_data 200, 'communications.json'
30
+ end
31
+
32
+ delete %r{/workers/\d+/communications/\d+$} do
33
+ get_json_data 200, 'communications.json'
34
+ end
35
+
36
+ #companies
37
+ get %r{/companies/\d+$} do
38
+ get_json_data 200, 'companies.json'
39
+ end
40
+
41
+ get %r{/companies$} do
42
+ get_json_data 200, 'companies.json'
43
+ end
44
+
45
+ get %r{/companies/\d/organizations+$} do
46
+ get_json_data 200, 'organizations.json'
47
+ end
48
+
49
+ private
50
+
51
+ def get_json_data(response_code, file_name)
52
+ content_type :json
53
+ status response_code
54
+ unless file_name.nil?
55
+ File.open(File.dirname(__FILE__) + '/../fixtures/' + file_name).read
56
+ else
57
+ {}
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,20 @@
1
+ require 'paychex_api'
2
+ require 'rspec'
3
+ require 'webmock/rspec'
4
+ require 'json'
5
+ require 'pry'
6
+ require 'byebug'
7
+
8
+ RSpec.configure do |config|
9
+ Dir["./spec/support/**/*.rb"].sort.each {|f| require f}
10
+
11
+ config.before(:each) do
12
+ WebMock.disable_net_connect!
13
+ WebMock.stub_request(:any, /.*/).to_rack(FakePaychex)
14
+ end
15
+ end
16
+
17
+
18
+ def fixture(*file)
19
+ File.new(File.join(File.expand_path("../fixtures", __FILE__), *file))
20
+ end
metadata ADDED
@@ -0,0 +1,240 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paychex_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jay Shaffer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.0.0
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.0'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.0.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.6'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.6'
61
+ - !ruby/object:Gem::Dependency
62
+ name: webmock
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 1.22.6
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 1.22.6
75
+ - !ruby/object:Gem::Dependency
76
+ name: pry
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: tilt
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 1.3.4
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: '1.3'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: 1.3.4
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '1.3'
109
+ - !ruby/object:Gem::Dependency
110
+ name: sinatra
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '1.0'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '1.0'
123
+ - !ruby/object:Gem::Dependency
124
+ name: byebug
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: 8.2.2
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: 8.2.2
137
+ - !ruby/object:Gem::Dependency
138
+ name: footrest
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: 0.5.1
144
+ type: :runtime
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: 0.5.1
151
+ - !ruby/object:Gem::Dependency
152
+ name: faraday
153
+ requirement: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - "~>"
156
+ - !ruby/object:Gem::Version
157
+ version: 0.9.0
158
+ type: :runtime
159
+ prerelease: false
160
+ version_requirements: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - "~>"
163
+ - !ruby/object:Gem::Version
164
+ version: 0.9.0
165
+ - !ruby/object:Gem::Dependency
166
+ name: faraday_middleware
167
+ requirement: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - "~>"
170
+ - !ruby/object:Gem::Version
171
+ version: 0.9.0
172
+ type: :runtime
173
+ prerelease: false
174
+ version_requirements: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - "~>"
177
+ - !ruby/object:Gem::Version
178
+ version: 0.9.0
179
+ description: Interface for interacting with the paychex enterprise API
180
+ email:
181
+ - jshaffer@instructure.com
182
+ executables: []
183
+ extensions: []
184
+ extra_rdoc_files: []
185
+ files:
186
+ - ".gitignore"
187
+ - Gemfile
188
+ - Gemfile.lock
189
+ - lib/paychex_api.rb
190
+ - lib/paychex_api/api_array.rb
191
+ - lib/paychex_api/client.rb
192
+ - lib/paychex_api/client/companies.rb
193
+ - lib/paychex_api/client/workers.rb
194
+ - lib/paychex_api/version.rb
195
+ - paychex_api.gemspec
196
+ - spec/fixtures/auth.json
197
+ - spec/fixtures/communications.json
198
+ - spec/fixtures/companies.json
199
+ - spec/fixtures/organizations.json
200
+ - spec/fixtures/workers.json
201
+ - spec/paychex_api/client/companies_spec.rb
202
+ - spec/paychex_api/client/workers_spec.rb
203
+ - spec/paychex_api/client_spec.rb
204
+ - spec/support/fake_paychex.rb
205
+ - spec/test_helper.rb
206
+ homepage: ''
207
+ licenses:
208
+ - MIT
209
+ metadata: {}
210
+ post_install_message:
211
+ rdoc_options: []
212
+ require_paths:
213
+ - lib
214
+ required_ruby_version: !ruby/object:Gem::Requirement
215
+ requirements:
216
+ - - ">="
217
+ - !ruby/object:Gem::Version
218
+ version: '0'
219
+ required_rubygems_version: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - ">="
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ requirements: []
225
+ rubyforge_project:
226
+ rubygems_version: 2.6.14
227
+ signing_key:
228
+ specification_version: 4
229
+ summary: Paychex API
230
+ test_files:
231
+ - spec/fixtures/auth.json
232
+ - spec/fixtures/communications.json
233
+ - spec/fixtures/companies.json
234
+ - spec/fixtures/organizations.json
235
+ - spec/fixtures/workers.json
236
+ - spec/paychex_api/client/companies_spec.rb
237
+ - spec/paychex_api/client/workers_spec.rb
238
+ - spec/paychex_api/client_spec.rb
239
+ - spec/support/fake_paychex.rb
240
+ - spec/test_helper.rb