paychex 0.3.3 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b108a5bafb14b19e27ff229025979dfacc3cbfda66fc85d090bafe0938cfd9ac
4
- data.tar.gz: 10a0d2572db4ad5aa98af00ca09823773cc2cde782e71ce929dc2b07f650b388
3
+ metadata.gz: 45e870f2d315996be069c400602a4ccf366a9994cd266618114f6dffc54c9004
4
+ data.tar.gz: 92f46dee54c5fa14fb1b1b1ff10b7ac4615f57e2cae2eee3ee7dcde9090c7e60
5
5
  SHA512:
6
- metadata.gz: 5012a0ccd1850760585823bca158af65e653c88fac133edb5f2c077cf5a797284f7c4cc25a8874ba9e80257e84ad0d12a458f3e827d2b9803fdba7f7918f9301
7
- data.tar.gz: 2cc60fd55900567803106581ea33a8a20f881d4f1a58d2cdeb0e062740fb9d7318bc91fc107c281100dc002b80958babd0e051c42b09c526616ab0c82a59daad
6
+ metadata.gz: a052c5f5d6ee6811fad22bf8391b302f274fb9fe2d794e21033e3180f8094a7528e79a8230e953b61c1aef239d028adf294ce85a3d13a4c58324664d2efe745f
7
+ data.tar.gz: 1bf76e48e2e5ed81b69fd055f01f84d5a042f11d9fd93ef7e8dcfe0b124c46458edaac46502e83c503d669e9ce05973d2466e0a9342447167344c7c5eae08a4a
data/Gemfile.lock CHANGED
@@ -1,65 +1,65 @@
1
- PATH
2
- remote: .
3
- specs:
4
- paychex (0.3.3)
5
- addressable
6
- faraday
7
- faraday_middleware
8
- rexml
9
-
10
- GEM
11
- remote: https://rubygems.org/
12
- specs:
13
- addressable (2.7.0)
14
- public_suffix (>= 2.0.2, < 5.0)
15
- byebug (11.1.3)
16
- coderay (1.1.3)
17
- crack (0.4.4)
18
- diff-lcs (1.4.4)
19
- faraday (1.1.0)
20
- multipart-post (>= 1.2, < 3)
21
- ruby2_keywords
22
- faraday_middleware (1.0.0)
23
- faraday (~> 1.0)
24
- hashdiff (1.0.1)
25
- method_source (1.0.0)
26
- multipart-post (2.1.1)
27
- pry (0.13.1)
28
- coderay (~> 1.1)
29
- method_source (~> 1.0)
30
- public_suffix (4.0.6)
31
- rake (13.0.1)
32
- rexml (3.2.5)
33
- rspec (3.9.0)
34
- rspec-core (~> 3.9.0)
35
- rspec-expectations (~> 3.9.0)
36
- rspec-mocks (~> 3.9.0)
37
- rspec-core (3.9.3)
38
- rspec-support (~> 3.9.3)
39
- rspec-expectations (3.9.3)
40
- diff-lcs (>= 1.2.0, < 2.0)
41
- rspec-support (~> 3.9.0)
42
- rspec-mocks (3.9.1)
43
- diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.9.0)
45
- rspec-support (3.9.4)
46
- ruby2_keywords (0.0.4)
47
- webmock (3.9.3)
48
- addressable (>= 2.3.6)
49
- crack (>= 0.3.2)
50
- hashdiff (>= 0.4.0, < 2.0.0)
51
-
52
- PLATFORMS
53
- ruby
54
-
55
- DEPENDENCIES
56
- bundler (>= 1.17)
57
- byebug
58
- paychex!
59
- pry
60
- rake (>= 12.3.3)
61
- rspec (>= 3.9.0)
62
- webmock
63
-
64
- BUNDLED WITH
65
- 2.4.4
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ paychex (0.3.5)
5
+ addressable
6
+ faraday
7
+ faraday_middleware
8
+ rexml
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ addressable (2.7.0)
14
+ public_suffix (>= 2.0.2, < 5.0)
15
+ byebug (11.1.3)
16
+ coderay (1.1.3)
17
+ crack (0.4.4)
18
+ diff-lcs (1.4.4)
19
+ faraday (1.1.0)
20
+ multipart-post (>= 1.2, < 3)
21
+ ruby2_keywords
22
+ faraday_middleware (1.0.0)
23
+ faraday (~> 1.0)
24
+ hashdiff (1.0.1)
25
+ method_source (1.0.0)
26
+ multipart-post (2.1.1)
27
+ pry (0.13.1)
28
+ coderay (~> 1.1)
29
+ method_source (~> 1.0)
30
+ public_suffix (4.0.6)
31
+ rake (13.0.1)
32
+ rexml (3.2.5)
33
+ rspec (3.9.0)
34
+ rspec-core (~> 3.9.0)
35
+ rspec-expectations (~> 3.9.0)
36
+ rspec-mocks (~> 3.9.0)
37
+ rspec-core (3.9.3)
38
+ rspec-support (~> 3.9.3)
39
+ rspec-expectations (3.9.3)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.9.0)
42
+ rspec-mocks (3.9.1)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.9.0)
45
+ rspec-support (3.9.4)
46
+ ruby2_keywords (0.0.4)
47
+ webmock (3.9.3)
48
+ addressable (>= 2.3.6)
49
+ crack (>= 0.3.2)
50
+ hashdiff (>= 0.4.0, < 2.0.0)
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ bundler (>= 1.17)
57
+ byebug
58
+ paychex!
59
+ pry
60
+ rake (>= 12.3.3)
61
+ rspec (>= 3.9.0)
62
+ webmock
63
+
64
+ BUNDLED WITH
65
+ 2.4.4
@@ -2,9 +2,42 @@ module Paychex
2
2
  class Client
3
3
  module Companies
4
4
  # Get a list of all the linked companies
5
- # This will be unavailable once we have 200+ linked companies
6
5
  def linked_companies
7
- get('companies')
6
+ limit = per_page
7
+ opts = { limit: limit, offset: 0 }
8
+ response_content = []
9
+ current_page = 1
10
+
11
+ response = companies(opts)
12
+
13
+ begin
14
+ while response && response.body
15
+ begin
16
+ companies_count = response.body.fetch('metadata').fetch('pagination').fetch('total')
17
+
18
+ no_of_pages = (companies_count.to_f / limit).ceil
19
+ rescue KeyError => e
20
+ # Consider no_of_pages = 1 unless pagination - total node is missing
21
+ no_of_pages = 1
22
+ end
23
+
24
+ companies_content = response.body.fetch('content').to_a
25
+ companies_content = companies_content.select { |c| c['hasPermission'] } if companies_content
26
+ response_content += companies_content
27
+
28
+ current_page += 1
29
+ if current_page <= no_of_pages
30
+ opts = { limit: limit, offset: (current_page - 1) * limit }
31
+ response = companies(opts)
32
+ else
33
+ break
34
+ end
35
+ end
36
+ rescue StandardError => e
37
+ return response_content
38
+ end
39
+
40
+ response_content
8
41
  end
9
42
 
10
43
  # Get profile of a linked company
@@ -85,5 +118,15 @@ module Paychex
85
118
  ret
86
119
  end
87
120
  end
121
+
122
+ private
123
+
124
+ def companies(options)
125
+ begin
126
+ get('companies', options)
127
+ rescue => e
128
+ nil
129
+ end
130
+ end
88
131
  end
89
132
  end
@@ -1,98 +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 60 seconds
32
- DEFAULT_TIMEOUT = 60
33
-
34
- # By default, the open timeout is 60 seconds.
35
- DEFAULT_OPEN_TIMEOUT = 60
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
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 = 100
27
+
28
+ # By default, don't set connection options.
29
+ DEFAULT_CONNECTION_OPTIONS = {}
30
+
31
+ # Default timeout time is 60 seconds
32
+ DEFAULT_TIMEOUT = 60
33
+
34
+ # By default, the open timeout is 60 seconds.
35
+ DEFAULT_OPEN_TIMEOUT = 60
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
@@ -1,32 +1,32 @@
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}",
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
- conn.request :instrumentation, name: 'request.paychex'
25
-
26
- conn.use ::PaychexFaradayMiddleWare::RaisePaychexHttpException
27
- conn.response :json, content_type: /\bjson$/
28
- conn.adapter Faraday.default_adapter
29
- end
30
- end
31
- end
32
- end
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}",
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
+ conn.request :instrumentation, name: 'request.paychex'
25
+
26
+ conn.use ::PaychexFaradayMiddleWare::RaisePaychexHttpException
27
+ conn.response :json, content_type: /\bjson$/
28
+ conn.adapter Faraday.default_adapter
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
- module Paychex
2
- VERSION = '0.3.3'
3
- end
1
+ module Paychex
2
+ VERSION = '0.3.5'
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paychex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mayank Dedhia
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-08 00:00:00.000000000 Z
11
+ date: 2024-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -199,7 +199,7 @@ metadata:
199
199
  homepage_uri: https://github.com/helloworld1812/paychex-ruby-gem
200
200
  source_code_uri: https://github.com/helloworld1812/paychex-ruby-gem
201
201
  changelog_uri: https://github.com/helloworld1812/paychex-ruby-gem/CHANGELOG.md
202
- post_install_message:
202
+ post_install_message:
203
203
  rdoc_options: []
204
204
  require_paths:
205
205
  - lib
@@ -214,8 +214,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  - !ruby/object:Gem::Version
215
215
  version: '0'
216
216
  requirements: []
217
- rubygems_version: 3.4.4
218
- signing_key:
217
+ rubygems_version: 3.0.3.1
218
+ signing_key:
219
219
  specification_version: 4
220
220
  summary: Ruby wrapper for paychex.com APIs.
221
221
  test_files: []