paychex 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 536525ed2919179c29274b85dc3556a8820192a7356642d441afa3810b9d6779
4
+ data.tar.gz: b0360d844bc9bf7a6e7dc74d1b9a0dd487c1164159e863adbadb912c3996dd16
5
+ SHA512:
6
+ metadata.gz: c8041f078a3f9f7b1dec848a2e9848d5b5fadb9e071d8a534da2d4e30d1117e475b7ba6c50ca50665af3bc4b1be42dd8c56f1c6d5b07b1f1d618eb4a833c1161
7
+ data.tar.gz: 565beda31f91e267c9e7b4aa505499f97c49ae3835ceb6927abc9a39a4e7bfcdff115794c5448db8e55e68e882f5a90f1be38435dd2cc71469dfb7d0cac1ea8d
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,29 @@
1
+ # inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.6.6
5
+ DisplayCopNames: true
6
+ Exclude:
7
+ - 'db/schema.rb'
8
+ - 'bin/**/*'
9
+
10
+ Style/FrozenStringLiteralComment:
11
+ Enabled: false
12
+
13
+ Style/Documentation:
14
+ Enabled: false
15
+
16
+ Style/NumericLiterals:
17
+ Enabled: false
18
+
19
+ Layout/LineLength:
20
+ Enabled: false
21
+
22
+ Metrics/MethodLength:
23
+ Enabled: false
24
+
25
+ # Metrics/BlockLength:
26
+ # Enabled: false
27
+
28
+ Naming/VariableNumber:
29
+ EnforcedStyle: snake_case
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.6
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at mayankdedhia@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in paychex.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ paychex (0.1.0)
5
+ faraday
6
+ faraday_middleware
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ byebug (11.1.3)
14
+ coderay (1.1.3)
15
+ crack (0.4.4)
16
+ diff-lcs (1.4.4)
17
+ faraday (1.1.0)
18
+ multipart-post (>= 1.2, < 3)
19
+ ruby2_keywords
20
+ faraday_middleware (1.0.0)
21
+ faraday (~> 1.0)
22
+ hashdiff (1.0.1)
23
+ method_source (1.0.0)
24
+ multipart-post (2.1.1)
25
+ pry (0.13.1)
26
+ coderay (~> 1.1)
27
+ method_source (~> 1.0)
28
+ public_suffix (4.0.6)
29
+ rake (13.0.1)
30
+ rspec (3.9.0)
31
+ rspec-core (~> 3.9.0)
32
+ rspec-expectations (~> 3.9.0)
33
+ rspec-mocks (~> 3.9.0)
34
+ rspec-core (3.9.3)
35
+ rspec-support (~> 3.9.3)
36
+ rspec-expectations (3.9.3)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.9.0)
39
+ rspec-mocks (3.9.1)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.9.0)
42
+ rspec-support (3.9.4)
43
+ ruby2_keywords (0.0.2)
44
+ webmock (3.9.3)
45
+ addressable (>= 2.3.6)
46
+ crack (>= 0.3.2)
47
+ hashdiff (>= 0.4.0, < 2.0.0)
48
+
49
+ PLATFORMS
50
+ ruby
51
+
52
+ DEPENDENCIES
53
+ bundler (>= 1.17)
54
+ byebug
55
+ paychex!
56
+ pry
57
+ rake (>= 12.3.3)
58
+ rspec (>= 3.9.0)
59
+ webmock
60
+
61
+ BUNDLED WITH
62
+ 2.2.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Mayank Dedhia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # Paychex
2
+
3
+ Ruby toolkit for [Paychex APIs](https://developer.paychex.com/api-documentation-and-exploration/api-references).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'paychex'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install paychex
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ # Require the toolkit
25
+ require "paychex"
26
+
27
+ # Get an instance of Paychex::Client
28
+ client = Paychex.client()
29
+
30
+ # Before any other API call do call authorize
31
+ client.authorize({
32
+ grant_type: "client_credentials",
33
+ client_id: "c22",
34
+ client_secret: "8f6a4213",
35
+ })
36
+
37
+ # Fetch all the linked commpanies
38
+ client.linked_companies()
39
+
40
+ # Fetch profile for individual company
41
+ client.linked_company(company_id)
42
+
43
+ # Fetch all workers associated with a company
44
+ client.workers(company_id)
45
+
46
+ # Fetch workers with pagination support
47
+ client.workers(company_id, {
48
+ limit: 20, # indicates total number of workers to be given in a response
49
+ # Un-documented on Paychex but limit value is capped at 20
50
+ offset: 0, # zero based index to start showing workers
51
+ # if 5 is passed, the response will display from 6th worker
52
+ })
53
+
54
+ # Fetch a specific worker's profile
55
+ client.worker(worker_id)
56
+
57
+ # Fetch labor assignments for a company
58
+ client.labor_assignments(company_id)
59
+
60
+ # Fetch a specific labor assignment of a company
61
+ client.labor_assignment(company_id, labor_assignment_id)
62
+
63
+ # Fetch jobs for a company
64
+ client.jobs(company_id)
65
+
66
+ # Fetch a specific job of a company
67
+ client.job(company_id, job_id)
68
+
69
+ # Fetch locations for a company
70
+ client.locations(company_id)
71
+
72
+ # Fetch locations with asof option for a company
73
+ client.locations(company_id, {
74
+ asof: "2019-01-18T00:00:00Z" # This will give location/locations data for
75
+ # that particular date.
76
+ })
77
+
78
+ # Fetch a specific location of a company
79
+ client.location(company_id, location_id)
80
+ # Sepcific location method can also be sent the option of asof like in
81
+ # locations method.
82
+ ```
83
+
84
+ Fetching of workers supports more options along with paginations. For more
85
+ details refer to the [workers documentation](https://developer.paychex.com/api-documentation-and-exploration/api-references/workers).
86
+
87
+ ## Development
88
+
89
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
90
+
91
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
92
+
93
+ ## Future
94
+
95
+ - Pending collection APIs for workers
96
+ - Worker Job Titles
97
+
98
+ - All other APIs which do inserts or updates.
99
+
100
+ - Give all static dropdown options as collection or constants
101
+ - workerType
102
+ - employmentType
103
+ - exemptionType
104
+ - sex
105
+ - statusType
106
+ - statusReason - values are based on statusType
107
+ - legalIdType
108
+
109
+ - Fix usage of application/x-www-form-urlencoded content type for auth
110
+ - Make host and endpoint URLs support staging and production servers based on
111
+ environment configuration parameter
112
+ - Handle token expiry by refreshing
113
+ - Add support for auto-pagination and start using per_page configuration
114
+
115
+ ## Play Around
116
+
117
+ To experiment with that code, run `bin/console` for an interactive prompt.
118
+
119
+ ## Contributing
120
+
121
+ Any Ruby code should go in the `lib` directory.
122
+ Bug reports and pull requests are welcome on GitHub at https://github.com/helloworld1812/paychex. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/helloworld1812/paychex/blob/master/CODE_OF_CONDUCT.md).
123
+
124
+
125
+
126
+ ## License
127
+
128
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
129
+
130
+ ## Code of Conduct
131
+
132
+ Everyone interacting in the Paychex project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/helloworld1812/paychex/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |task|
5
+ # TODO: Check if following options work properly or not
6
+ task.rspec_opts = ["--color", "--format", "nested"]
7
+ task.verbose = false
8
+ end
9
+
10
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "paychex"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ require 'faraday'
2
+
3
+ module PaychexFaradayMiddleWare
4
+ class RaisePaychexHttpException < Faraday::Middleware
5
+ def initialize(app)
6
+ super(app)
7
+ end
8
+
9
+ def call(env)
10
+ @app.call(env).on_complete do |response|
11
+ case response.status.to_i
12
+ when 400
13
+ raise Paychex::BadRequest, response
14
+ when 401
15
+ raise Paychex::Unauthorized, response
16
+ when 403
17
+ raise Paychex::NoAccess, response
18
+ when 404
19
+ raise Paychex::NotFound, response
20
+ when 500
21
+ raise Paychex::InternalServerError, response
22
+ when 502
23
+ raise Paychex::BadGateway, response
24
+ when 503
25
+ raise Paychex::ServiceUnavailable, response
26
+ when 504
27
+ raise Paychex::GatewayTimeout, response
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,28 @@
1
+ require "paychex/connection"
2
+ require "paychex/request"
3
+ require "paychex/configuration"
4
+
5
+ module Paychex
6
+ class API
7
+ include Connection
8
+ include Request
9
+
10
+ attr_accessor *Paychex::Configuration::VALID_OPTIONS_KEYS
11
+
12
+ # Creates a new API
13
+ def initialize(options = {})
14
+ options = Paychex.options.merge(options)
15
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
16
+ send("#{key}=", options[key])
17
+ end
18
+ end
19
+
20
+ def config
21
+ conf = {}
22
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
23
+ conf[key] = send key
24
+ end
25
+ conf
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ module Paychex
2
+ class Client
3
+ module Auth
4
+ # Authorize a client and get back a access token with expiry.
5
+ def authorize(options = {})
6
+ response = auth('auth/oauth/v2/token', options)
7
+ if response.body.is_a?(Hash) && response.body['access_token']
8
+ self.access_token = response.body['access_token']
9
+ self.token_timeout = Time.new + response.body['expires_in']
10
+ response
11
+ else
12
+ # raise error when token is missing.
13
+ raise Paychex::BadRequest, response
14
+ end
15
+ end
16
+
17
+ # Indicates expiry of the auth token
18
+ def token_expired?
19
+ token_timeout < Time.new
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,77 @@
1
+ module Paychex
2
+ class Client
3
+ module Companies
4
+ # Get a list of all the linked companies
5
+ def linked_companies
6
+ get('companies')
7
+ end
8
+
9
+ # Get profile of a linked company
10
+ def linked_company(company_id)
11
+ get("companies/#{company_id}")
12
+ end
13
+
14
+ # Get company's linked status
15
+ def company_status(company_id)
16
+ begin
17
+ content = linked_company(company_id).body.fetch('content')
18
+ return 'linked' if content[0]&.fetch('companyId') == company_id
19
+ rescue Paychex::NoAccess => e
20
+ return 'not-linked'
21
+ rescue Paychex::NotFound => e
22
+ return 'invalid'
23
+ rescue StandardError => e
24
+ p 'Paychex Gem: Handle more errors'
25
+ p e
26
+ end
27
+ 'unsupported'
28
+ end
29
+
30
+ def details_by_display_id(display_id)
31
+ begin
32
+ content = linked_companies.body.fetch('content')
33
+ company = content.find { |company| company.fetch('displayId') == display_id }
34
+ return {
35
+ "company": company,
36
+ "message": company.nil? ? 'not-found' : 'found'
37
+ }
38
+ rescue Paychex::NoAccess => e
39
+ return {
40
+ "company": nil,
41
+ "message": 'unknown'
42
+ }
43
+ rescue StandardError => e
44
+ p 'Paychex Gem: Handle more errors'
45
+ p e
46
+ end
47
+ {
48
+ "company": nil,
49
+ "message": 'unsupported'
50
+ }
51
+ end
52
+
53
+ def details_by_display_ids(display_ids)
54
+ ret = {}
55
+ begin
56
+ content = linked_companies.body.fetch('content')
57
+ display_ids.each do |display_id|
58
+ company = content.find { |company| company.fetch('displayId') == display_id }
59
+ ret[display_id.to_s] = {
60
+ "company": company,
61
+ "message": company.nil? ? 'not-found' : 'found'
62
+ }
63
+ end
64
+ return ret
65
+ rescue Paychex::NoAccess => e
66
+ ret['message'] = 'unknown'
67
+ return ret
68
+ rescue StandardError => e
69
+ p 'Paychex Gem: Handle more errors'
70
+ p e
71
+ end
72
+ ret['message'] = 'unsupported'
73
+ ret
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,20 @@
1
+ module Paychex
2
+ class Client
3
+ module DirectDeposit
4
+ # Get the worker's all direct deposit details
5
+ def direct_deposits(worker_id)
6
+ get("workers/#{worker_id}/directdeposits")
7
+ end
8
+
9
+ # Get a worker's specific direct deposit details
10
+ def direct_deposit(worker_id, direct_deposit_id)
11
+ get("workers/#{worker_id}/directdeposits/#{direct_deposit_id}")
12
+ end
13
+
14
+ # Add a worker's direct deposit details
15
+ def add_direct_deposit(worker_id, options = {})
16
+ post("workers/#{worker_id}/directdeposits", options)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ module Paychex
2
+ class Client
3
+ module FederalTax
4
+ # Get a specific worker's federal tax
5
+ def federal_tax(worker_id)
6
+ get("workers/#{worker_id}/federaltax")
7
+ end
8
+
9
+ # Add a worker's federal tax
10
+ def add_federal_tax(worker_id, options = {})
11
+ post("workers/#{worker_id}/federaltax", options)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Paychex
2
+ class Client
3
+ module JobTitles
4
+ # Get a list of the job titles for a company
5
+ def job_titles(company_id)
6
+ get("companies/#{company_id}/jobtitles")
7
+ end
8
+
9
+ # Get a specific job title's details
10
+ def job_title(company_id, job_title_id)
11
+ get("companies/#{company_id}/jobtitles/#{job_title_id}")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Paychex
2
+ class Client
3
+ module Jobs
4
+ # Get a list of the jobs for a company
5
+ def jobs(company_id)
6
+ get("companies/#{company_id}/jobs")
7
+ end
8
+
9
+ # Get a specific job's details
10
+ def job(company_id, job_id)
11
+ get("companies/#{company_id}/jobs/#{job_id}")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Paychex
2
+ class Client
3
+ module LaborAssignments
4
+ # Get a list of the labor assignments for a company
5
+ def labor_assignments(company_id)
6
+ get("companies/#{company_id}/laborassignments")
7
+ end
8
+
9
+ # Get a specific labor assignment's details
10
+ def labor_assignment(company_id, labor_assignment_id)
11
+ get("companies/#{company_id}/laborassignments/#{labor_assignment_id}")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Paychex
2
+ class Client
3
+ module Locations
4
+ # Get a list of the locations for a company
5
+ def locations(company_id, options = {})
6
+ get("companies/#{company_id}/locations")
7
+ end
8
+
9
+ # Get a specific location's details
10
+ def location(company_id, location_id, options = {})
11
+ get("companies/#{company_id}/locations/#{location_id}")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Paychex
2
+ class Client
3
+ module Organizations
4
+ # Get a list of the organizations for a company
5
+ def organizations(company_id)
6
+ get("companies/#{company_id}/organizations")
7
+ end
8
+
9
+ # Get a specific organization's details
10
+ def organization(company_id, organization_id)
11
+ get("companies/#{company_id}/organizations/#{organization_id}")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ module Paychex
2
+ class Client
3
+ module PayRates
4
+ # Get a list of compensation rates for a worker
5
+ def pay_rates(worker_id)
6
+ get("workers/#{worker_id}/compensation/payrates")
7
+ end
8
+
9
+ # Get a worker's specific compensation rate
10
+ def pay_rate(worker_id, pay_rate_id)
11
+ get("workers/#{worker_id}/compensation/payrates/#{pay_rate_id}")
12
+ end
13
+
14
+ # Add a worker's pay rate
15
+ def add_pay_rate(worker_id, options = {})
16
+ post("workers/#{worker_id}/compensation/payrates", options)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,40 @@
1
+ module Paychex
2
+ class Client
3
+ module Workers
4
+ # Get a list of the workers of the company
5
+ def workers(company_id, options = {})
6
+ get("companies/#{company_id}/workers", options)
7
+ end
8
+
9
+ # Get a specific worker's profile
10
+ def worker(worker_id, options = {})
11
+ get("workers/#{worker_id}", options)
12
+ end
13
+
14
+ # Create a worker
15
+ def create_worker(company_id, options = {})
16
+ post("companies/#{company_id}/workers", options)
17
+ end
18
+
19
+ def remove_worker(worker_id, options = {})
20
+ delete("workers/#{worker_id}", options)
21
+ end
22
+
23
+ # Get company's linked status
24
+ def worker_status(company_id, worker_id)
25
+ begin
26
+ content = workers(company_id).body.fetch('content')
27
+ return 'valid' if content.one?{ |worker| worker.fetch('workerId') == worker_id }
28
+ rescue Paychex::NoAccess => e
29
+ return 'not-linked'
30
+ rescue Paychex::NotFound => e
31
+ return 'invalid'
32
+ rescue StandardError => e
33
+ p 'Paychex Gem: Handle more errors'
34
+ p e
35
+ end
36
+ 'unsupported'
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,35 @@
1
+ require 'paychex/api'
2
+
3
+ module Paychex
4
+ # Wrapper for the Paychex REST API
5
+ #
6
+ # @note All methods have been separated into modules for better management.
7
+ # @see https://developer.paychex.com/api-documentation-and-exploration/api-references
8
+ class Client < Paychex::API
9
+ require 'paychex/client/auth'
10
+ require 'paychex/client/companies'
11
+ require 'paychex/client/workers'
12
+ require 'paychex/client/jobs'
13
+ require 'paychex/client/job_titles'
14
+ require 'paychex/client/locations'
15
+ require 'paychex/client/labor_assignments'
16
+ require 'paychex/client/pay_rates'
17
+ require 'paychex/client/federal_tax'
18
+ require 'paychex/client/direct_deposit'
19
+ require 'paychex/client/organizations'
20
+
21
+ include Paychex::Client::Auth
22
+ include Paychex::Client::Companies
23
+ include Paychex::Client::Workers
24
+ include Paychex::Client::Jobs
25
+ include Paychex::Client::JobTitles
26
+ include Paychex::Client::Locations
27
+ include Paychex::Client::LaborAssignments
28
+ include Paychex::Client::PayRates
29
+ include Paychex::Client::FederalTax
30
+ include Paychex::Client::DirectDeposit
31
+ include Paychex::Client::Organizations
32
+
33
+ attr_accessor :token_timeout
34
+ end
35
+ end
@@ -0,0 +1,98 @@
1
+ require "paychex/version"
2
+
3
+ module Paychex
4
+ # Defines constants and methods related to configuration
5
+ module Configuration
6
+ # An array of valid keys in the options hash when configuring a {Paychex::API}
7
+ VALID_OPTIONS_KEYS = [
8
+ :access_token,
9
+ :host,
10
+ :endpoint,
11
+ :format,
12
+ :connection_options,
13
+ :proxy,
14
+ :environment,
15
+ :user_agent,
16
+ :per_page,
17
+ :timeout,
18
+ :open_timeout,
19
+ :token_timeout,
20
+ ].freeze
21
+
22
+ # By default, don't set an access_token
23
+ DEFAULT_ACCESS_TOKEN = nil
24
+
25
+ # By default, return 20 resources per page when there is an pagination.
26
+ DEFAULT_PER_PAGE = 20
27
+
28
+ # By default, don't set connection options.
29
+ DEFAULT_CONNECTION_OPTIONS = {}
30
+
31
+ # Default timeout time is 20 seconds
32
+ DEFAULT_TIMEOUT = 20
33
+
34
+ # By default, the open timeout is 20 seconds.
35
+ DEFAULT_OPEN_TIMEOUT = 20
36
+
37
+ DEFAULT_TOKEN_TIMEOUT = Time.new
38
+
39
+ # By default, use sandbox environment
40
+ DEFAULT_HOST = "https://sandbox.api.paychex.com".freeze
41
+
42
+ # The endpoint that will be used to connect if none is set
43
+ DEFAULT_ENDPOINT = "https://sandbox.api.paychex.com/".freeze
44
+
45
+ # The response format appended to the path and sent in the 'Accept' header if none is set
46
+ #
47
+ # @note JSON is the only available format at this time
48
+ DEFAULT_FORMAT = :json
49
+
50
+ # By default, don't use a proxy server
51
+ DEFAULT_PROXY = nil
52
+
53
+ # By default, environment will be sandbox
54
+ DEFAULT_ENVIRONMENT = "sandbox"
55
+
56
+ # The user agent that will be sent to the API endpoint if none is set
57
+ DEFAULT_USER_AGENT = "Paychex Ruby Gem #{Paychex::VERSION}".freeze
58
+
59
+ # An array of valid request/response formats
60
+ VALID_FORMATS = [:json].freeze
61
+
62
+ # @private
63
+ attr_accessor *VALID_OPTIONS_KEYS
64
+
65
+ # When this module is extended, set all configuration options to their default values
66
+ def self.extended(base)
67
+ base.reset
68
+ end
69
+
70
+ # Convenience method to allow configuration options to be set in a block
71
+ def configure
72
+ yield self
73
+ end
74
+
75
+ # Create a hash of options and their values
76
+ def options
77
+ VALID_OPTIONS_KEYS.inject({}) do |option, key|
78
+ option.merge!(key => send(key))
79
+ end
80
+ end
81
+
82
+ # Reset all configuration options to defaults
83
+ def reset
84
+ self.access_token = DEFAULT_ACCESS_TOKEN
85
+ self.host = DEFAULT_HOST
86
+ self.endpoint = DEFAULT_ENDPOINT
87
+ self.connection_options = DEFAULT_CONNECTION_OPTIONS
88
+ self.format = DEFAULT_FORMAT
89
+ self.proxy = DEFAULT_PROXY
90
+ self.environment = DEFAULT_ENVIRONMENT
91
+ self.user_agent = DEFAULT_USER_AGENT
92
+ self.per_page = DEFAULT_PER_PAGE
93
+ self.timeout = DEFAULT_TIMEOUT
94
+ self.open_timeout = DEFAULT_OPEN_TIMEOUT
95
+ self.token_timeout = DEFAULT_TOKEN_TIMEOUT
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,31 @@
1
+ require 'faraday_middleware'
2
+ require 'faraday/raise_paychex_http_exception'
3
+
4
+ module Paychex
5
+ module Connection
6
+ private
7
+
8
+ def connection
9
+ options = {
10
+ headers: {
11
+ 'Accept' => "application/#{format}; charset=utf-8",
12
+ 'User-Agent' => user_agent
13
+ },
14
+ proxy: proxy,
15
+ url: endpoint
16
+ }.merge(connection_options)
17
+
18
+ Faraday::Connection.new(options) do |conn|
19
+ conn.authorization :Bearer, access_token unless access_token.nil?
20
+ # https://github.com/lostisland/faraday/issues/417#issuecomment-223413386
21
+ conn.options[:timeout] = timeout
22
+ conn.options[:open_timeout] = open_timeout
23
+ conn.request :json
24
+
25
+ conn.use ::PaychexFaradayMiddleWare::RaisePaychexHttpException
26
+ conn.response :json, content_type: /\bjson$/
27
+ conn.adapter Faraday.default_adapter
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,61 @@
1
+ module Paychex
2
+ # Custom error class for rescuing from all paychex errors
3
+ class Error < StandardError
4
+ attr_reader :http_method, :url, :errors, :response, :raw_errors
5
+
6
+ def initialize(response)
7
+ super
8
+ @response = response.dup
9
+ @http_method = response.method.to_s
10
+ @url = response.url
11
+ @raw_errors = response.body.fetch('errors') if response.body.is_a?(Hash) && !response.body.empty? && !response.body.fetch('errors', nil).nil?
12
+ end
13
+
14
+ def message
15
+ <<-HEREDOC
16
+ URL: #{@response.url}
17
+ method: #{@response.method}
18
+ response status: #{@response.status}
19
+ response body: #{@response.response.body}
20
+ HEREDOC
21
+ end
22
+
23
+ def error_sentence
24
+ return if @raw_errors.nil?
25
+
26
+ array = []
27
+ @raw_errors.each do |v|
28
+ array += "#{v['code']}: #{v['description']}, #{v['resolution']}"
29
+ end
30
+
31
+ array.join(' ')
32
+ end
33
+ end
34
+
35
+ # Raised when api.paychex.com returns the HTTP status code 400
36
+ class BadRequest < Error; end
37
+
38
+ # Raised when api.paychex.com returns the HTTP status code 401
39
+ class Unauthorized < Error; end
40
+
41
+ # Raised when api.paychex.com returns the HTTP status code 403
42
+ class NoAccess < Error; end
43
+
44
+ # Raised when api.paychex.com returns the HTTP status code 404
45
+ class NotFound < Error; end
46
+
47
+ # Raised when api.paychex.com returns the HTTP status code 500
48
+ class InternalServerError < Error; end
49
+
50
+ # Raised when api.paychex.com returns the HTTP status code 502
51
+ class BadGateway < Error; end
52
+
53
+ # Raised when api.paychex.com returns the HTTP status code 503
54
+ class ServiceUnavailable < Error; end
55
+
56
+ # Raised when api.paychex.com returns the HTTP status code 504
57
+ class GatewayTimeout < Error; end
58
+
59
+ # Raised when client fails to provide required parameters.
60
+ class MissingRequiredArgument < Error; end
61
+ end
@@ -0,0 +1,54 @@
1
+ require 'uri'
2
+ require 'base64'
3
+
4
+ module Paychex
5
+ # Defines HTTP request methods
6
+ module Request
7
+ # HTTP GET request
8
+ def get(path, options = {})
9
+ request(:get, path, options)
10
+ end
11
+
12
+ # HTTP POST request
13
+ def post(path, options = {})
14
+ request(:post, path, options)
15
+ end
16
+
17
+ # HTTP PUT request
18
+ def put(path, options = {})
19
+ request(:put, path, options)
20
+ end
21
+
22
+ # HTTP DELETE request
23
+ def delete(path, options = {})
24
+ request(:delete, path, options)
25
+ end
26
+
27
+ def auth(path, options = {})
28
+ options['Content-Type'] = 'application/x-www-form-urlencoded'
29
+ request(:post, path, options)
30
+ end
31
+
32
+ private
33
+
34
+ def request(method, path, options)
35
+ encoded_path = Addressable::URI.escape(path)
36
+ connection.send(method) do |request|
37
+ case method
38
+ when :get, :delete
39
+ request.url(encoded_path, options)
40
+ # TODO: Need to test for more post and put requests
41
+ when :post, :put
42
+ request.path = encoded_path
43
+ content_type = options.delete('Content-Type')
44
+ if content_type == 'application/x-www-form-urlencoded'
45
+ request.headers['Content-Type'] = content_type
46
+ request.body = URI.encode_www_form(options)
47
+ else
48
+ request.body = options
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module Paychex
2
+ VERSION = '0.1.1'
3
+ end
data/lib/paychex.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'paychex/configuration'
2
+ require 'paychex/error'
3
+ require 'paychex/api'
4
+ require 'paychex/client'
5
+
6
+ module Paychex
7
+ extend Configuration
8
+
9
+ # Alias for Paychex::Client.new
10
+ #
11
+ # @return [Paychex::Client]
12
+ def self.client(options = {})
13
+ ::Paychex::Client.new(options)
14
+ end
15
+
16
+ # Delegate to Paychex::Client
17
+ def self.method_missing(method, *args, &block)
18
+ return super unless client.respond_to?(method)
19
+
20
+ client.send(method, *args, &block)
21
+ end
22
+
23
+ # Delegate to Paychex::Client
24
+ def self.respond_to?(method, include_all = false)
25
+ client.respond_to?(method, include_all) || super
26
+ end
27
+ end
data/paychex.gemspec ADDED
@@ -0,0 +1,43 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'paychex/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'paychex'
7
+ spec.version = Paychex::VERSION
8
+ spec.authors = ['Mayank Dedhia']
9
+ spec.email = ['mayankdedhia@gmail.com']
10
+
11
+ spec.summary = 'Ruby wrapper for paychex.com APIs.'
12
+ spec.description = "A Ruby wrapper for paychex.com REST APIs which will make \
13
+ it easy to interact with Paychex."
14
+ spec.homepage = 'https://github.com/helloworld1812/paychex-ruby-gem'
15
+ spec.license = 'MIT'
16
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
17
+
18
+ # Currently no push is allowed
19
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ spec.metadata['source_code_uri'] = 'https://github.com/helloworld1812/paychex-ruby-gem'
23
+ spec.metadata['changelog_uri'] = 'https://github.com/helloworld1812/paychex-ruby-gem/CHANGELOG.md'
24
+
25
+ # Specify which files should be added to the gem when it is released.
26
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
28
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
+ end
30
+ spec.bindir = 'exe'
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ['lib']
33
+
34
+ spec.add_development_dependency 'bundler', '>= 1.17'
35
+ spec.add_development_dependency 'byebug'
36
+ spec.add_development_dependency 'pry'
37
+ spec.add_development_dependency 'rake', '>= 12.3.3'
38
+ spec.add_development_dependency 'rspec', '>= 3.9.0'
39
+ spec.add_development_dependency 'webmock'
40
+ spec.add_runtime_dependency 'faraday'
41
+ spec.add_runtime_dependency 'faraday_middleware'
42
+ spec.add_runtime_dependency 'addressable'
43
+ end
metadata ADDED
@@ -0,0 +1,206 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paychex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Mayank Dedhia
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-06-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 12.3.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 12.3.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.9.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.9.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: faraday_middleware
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: addressable
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: A Ruby wrapper for paychex.com REST APIs which will make it easy
140
+ to interact with Paychex.
141
+ email:
142
+ - mayankdedhia@gmail.com
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".rubocop.yml"
150
+ - ".travis.yml"
151
+ - CODE_OF_CONDUCT.md
152
+ - Gemfile
153
+ - Gemfile.lock
154
+ - LICENSE.txt
155
+ - README.md
156
+ - Rakefile
157
+ - bin/console
158
+ - bin/setup
159
+ - lib/faraday/raise_paychex_http_exception.rb
160
+ - lib/paychex.rb
161
+ - lib/paychex/api.rb
162
+ - lib/paychex/client.rb
163
+ - lib/paychex/client/auth.rb
164
+ - lib/paychex/client/companies.rb
165
+ - lib/paychex/client/direct_deposit.rb
166
+ - lib/paychex/client/federal_tax.rb
167
+ - lib/paychex/client/job_titles.rb
168
+ - lib/paychex/client/jobs.rb
169
+ - lib/paychex/client/labor_assignments.rb
170
+ - lib/paychex/client/locations.rb
171
+ - lib/paychex/client/organizations.rb
172
+ - lib/paychex/client/pay_rates.rb
173
+ - lib/paychex/client/workers.rb
174
+ - lib/paychex/configuration.rb
175
+ - lib/paychex/connection.rb
176
+ - lib/paychex/error.rb
177
+ - lib/paychex/request.rb
178
+ - lib/paychex/version.rb
179
+ - paychex.gemspec
180
+ homepage: https://github.com/helloworld1812/paychex-ruby-gem
181
+ licenses:
182
+ - MIT
183
+ metadata:
184
+ homepage_uri: https://github.com/helloworld1812/paychex-ruby-gem
185
+ source_code_uri: https://github.com/helloworld1812/paychex-ruby-gem
186
+ changelog_uri: https://github.com/helloworld1812/paychex-ruby-gem/CHANGELOG.md
187
+ post_install_message:
188
+ rdoc_options: []
189
+ require_paths:
190
+ - lib
191
+ required_ruby_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: 2.3.0
196
+ required_rubygems_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
201
+ requirements: []
202
+ rubygems_version: 3.1.6
203
+ signing_key:
204
+ specification_version: 4
205
+ summary: Ruby wrapper for paychex.com APIs.
206
+ test_files: []