rest-client-wrapper 4.0.0 → 5.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b402585e6034813c0b9d3fa1af05e943ca106f7cdcae0b0f6e205e822250304
4
- data.tar.gz: 64390499b6848d1dab15c57a723b9b02bded8eedf2b5f3650e8f3f8ed789f3f2
3
+ metadata.gz: 9fb801363ad2583dd1774f9c662fea54d6fe3b42747296e959e51a712f5f0795
4
+ data.tar.gz: 1ff4d4aed156a6a99467997d20f1713a72d4976e9082fba2fda3e8589b2ee6d0
5
5
  SHA512:
6
- metadata.gz: 8769b420a7bfe481450e0665a3f4899564dff302769bf050f7d512564b828479529a5a3859dd8fb581d714e8b4452601e102a0d28226771bc57ece9f16b4cc88
7
- data.tar.gz: 46a6573d732840fe66240d6773db7f07ecd274d70b3a7b794b44d1bb31eca85fe514a050726571afe47538b8b4a16b260013c872b20283eb52c515df47829d6f
6
+ metadata.gz: 2804b60c91e9d6df61cda9471eae4b3af1f3297d0dd21b47e957077b0873df55784d207ac595acc9e56b819ba05910dd11100e43604d78a0bb53773cdde56caa
7
+ data.tar.gz: db9077dfaf78eed8d79cca584949a4ceb0ca4a13fa4a02ab5068bdc098d7b84a15488b1b86e05f34b2c5e1ed1c0a1f4b3d97cd3972dcd492837215ba4e178a17
data/README.md CHANGED
@@ -31,7 +31,7 @@ A `rest_client` must be created to make requests (if the rest_client requires au
31
31
  require "rest_client_wrapper"
32
32
 
33
33
  # Create a rest_client
34
- rest_client = RestClientWrapper::RestClient.new({ host: "https://www.host.com" })
34
+ rest_client = RestClientWrapper::RestClient.new(host: "https://www.host.com")
35
35
  ```
36
36
 
37
37
  ## Basic Usage: `make_request`
@@ -40,7 +40,7 @@ The `rest_client` can make HTTP requests using `make_request`:
40
40
 
41
41
  ```ruby
42
42
  # Make a request
43
- response = rest_client.make_request({ http_method: :get, uri: "https://www.host.com" })
43
+ response = rest_client.make_request(http_method: :get, uri: "https://www.host.com")
44
44
  ```
45
45
  <a name="get_started"></a>
46
46
  ## Basic Usage: `execute`
@@ -51,23 +51,23 @@ _Segment parameters_ can be added to an existing `request`:
51
51
 
52
52
  ```ruby
53
53
  # Create an HTTP request with a segmented uri
54
- request = Request.new({ http_method: :get, uri: "/%<segment_1>s/%<segment_2>s" })
54
+ request = Request.new(http_method: :get, uri: "/%<segment_1>s/%<segment_2>s")
55
55
 
56
56
  # Add the segment parameter(s) to the request ('%<segment_x>s' in the uri will be replaced with the matching segment param when the request is executed)
57
57
  request.segment_params = { segment_1: "user_id_0001", segment_2: "course_id_0001" }
58
58
 
59
59
  # Execute a request
60
- response = rest_client.execute({ request: request })
60
+ response = rest_client.execute(request: request)
61
61
  ```
62
62
 
63
63
  _Segment parameters_ can be created with the `request`:
64
64
 
65
65
  ```ruby
66
66
  # Segment parameters can be created with the request
67
- request = Request.new({ http_method: :post, uri: "/%<segment_1>s", segment_params: { segment_1: "user_id_0001" }, payload: { first_name: "name" }, headers: { content_type: "application/json" } })
67
+ request = Request.new(http_method: :post, uri: "/%<segment_1>s", segment_params: { segment_1: "user_id_0001" }, payload: { first_name: "name" }, headers: { content_type: "application/json" })
68
68
 
69
69
  # Execute a request
70
- response = rest_client.execute({ request: request })
70
+ response = rest_client.execute(request: request)
71
71
  ```
72
72
  <a name="authentication"></a>
73
73
  ## Authentication
@@ -78,10 +78,10 @@ The `rest_client` can make authenticated HTTP requests using an `authenticator`.
78
78
 
79
79
  ```ruby
80
80
  # Add a Basic authenticator to the rest_client
81
- rest_client.authenticator = Authenticator::Basic.new({ username: "username", password: "password" })
81
+ rest_client.authenticator = Authenticator::Basic.new(username: "username", password: "password")
82
82
 
83
83
  # Make a request
84
- response = rest_client.make_request({ http_method: :get, uri: "https://www.host.com/api/v1/resource" })
84
+ response = rest_client.make_request(http_method: :get, uri: "https://www.host.com/api/v1/resource")
85
85
  ```
86
86
 
87
87
  ### Custom
@@ -93,39 +93,39 @@ response = rest_client.make_request({ http_method: :get, uri: "https://www.host.
93
93
  ```ruby
94
94
  # Add a Custom authenticator using query_param
95
95
  # The custom auth parameter will be added as a query parameter
96
- rest_client.authenticator = Authenticator::Custom.new({ type: :query_param, auth_param: { custom_auth_param: "auth_value" } })
96
+ rest_client.authenticator = Authenticator::Custom.new(type: :query_param, auth_param: { custom_auth_param: "auth_value" })
97
97
 
98
98
  # Make a request
99
- response = rest_client.make_request({ http_method: :get, uri: "https://www.host.com/api/v1/resource" })
99
+ response = rest_client.make_request(http_method: :get, uri: "https://www.host.com/api/v1/resource")
100
100
  ```
101
101
 
102
102
  ```ruby
103
103
  # Add a Custom authenticator using header
104
104
  # The custom auth parameter will be added to the request header
105
- rest_client.authenticator = Authenticator::Custom.new({ type: :header, auth_param: { custom_auth_param: "auth_value" } })
105
+ rest_client.authenticator = Authenticator::Custom.new(type: :header, auth_param: { custom_auth_param: "auth_value" })
106
106
 
107
107
  # Make a request
108
- response = rest_client.make_request({ http_method: :get, uri: "https://www.host.com/api/v1/resource" })
108
+ response = rest_client.make_request(http_method: :get, uri: "https://www.host.com/api/v1/resource")
109
109
  ```
110
110
 
111
111
  ### OAuth
112
112
 
113
113
  ```ruby
114
114
  # Add an OAuth authenticator to the rest_client
115
- rest_client.authenticator = Authenticator::Oauth.new({ site: "https://www.host.com", token_url_path: "token_url_path", client_id: "client_id", client_secret: "secret" })
115
+ rest_client.authenticator = Authenticator::Oauth.new(site: "https://www.host.com", token_url_path: "token_url_path", client_id: "client_id", client_secret: "secret")
116
116
 
117
117
  # Make a request
118
- response = rest_client.make_request({ http_method: :get, uri: "/api/v1/user" })
118
+ response = rest_client.make_request(http_method: :get, uri: "/api/v1/user")
119
119
  ```
120
120
 
121
121
  ### Token
122
122
 
123
123
  ```ruby
124
124
  # Add a Token authenticator to the rest_client
125
- rest_client.authenticator = Authenticator::Token.new({ access_token: "access_token" })
125
+ rest_client.authenticator = Authenticator::Token.new(access_token: "access_token")
126
126
 
127
127
  # Make a request
128
- response = rest_client.make_request({ http_method: :get, uri: "/api/v1/user" })
128
+ response = rest_client.make_request(http_method: :get, uri: "/api/v1/user")
129
129
  ```
130
130
 
131
131
  ## Pagination
@@ -139,7 +139,7 @@ The `rest_client` can make paginated HTTP requests using a `paginator`.
139
139
  rest_client.paginator = Paginator::HeaderLink.new
140
140
 
141
141
  # Make a request for paginated data
142
- rest_client.make_request_for_pages({ http_method: :get, uri: "/api/v1/user" })
142
+ rest_client.make_request_for_pages(http_method: :get, uri: "/api/v1/user")
143
143
  ```
144
144
 
145
145
  ### Echo360
@@ -148,7 +148,7 @@ rest_client.make_request_for_pages({ http_method: :get, uri: "/api/v1/user" })
148
148
  # Add an Echo paginator to the rest_client
149
149
  rest_client.paginator = Paginator::Echo.new
150
150
 
151
- rest_client.make_request_for_pages({ http_method: :get, uri: "/api/v1/user" })
151
+ rest_client.make_request_for_pages(http_method: :get, uri: "/api/v1/user")
152
152
  ```
153
153
 
154
154
  ---
@@ -184,7 +184,7 @@ config = {
184
184
  }
185
185
  }
186
186
 
187
- rest_client = RestClientWrapper::RestClient.new({ host: "host" })
187
+ rest_client = RestClientWrapper::RestClient.new(host: "host")
188
188
  ```
189
189
 
190
190
  If the caller wishes for additional HTTP codes to be handled, they can be specified in the `config`:
@@ -197,7 +197,7 @@ config = {
197
197
  }
198
198
  }
199
199
 
200
- rest_client = RestClientWrapper::RestClient.new({ host: "host", config: config })
200
+ rest_client = RestClientWrapper::RestClient.new(host: "host", config: config)
201
201
  ```
202
202
 
203
203
  ## make_request
@@ -389,8 +389,8 @@ _Response_ objects have the following methods:
389
389
 
390
390
  ```ruby
391
391
  begin
392
- request = Request.new({http_method: :get, uri: "https://www.host.com/public/api/v1/resource" })
393
- response = rest_client.execute({ request: request })
392
+ request = Request.new(http_method: :get, uri: "https://www.host.com/public/api/v1/resource")
393
+ response = rest_client.execute(request: request)
394
394
  rescue RestClientError => e
395
395
  e.response
396
396
  end
@@ -408,14 +408,14 @@ end
408
408
  host_url = "https://www.host.com"
409
409
  username = "api_user_name"
410
410
  password = "password"
411
- client = Client.new({ host: host_url })
412
- client.authenticator = Authenticator::Basic.new({ username: username, password: password })
413
- client.paginator = Paginator::HeaderLink.new({ per_page: 10 })
411
+ client = Client.new(host: host_url)
412
+ client.authenticator = Authenticator::Basic.new(username: username, password: password)
413
+ client.paginator = Paginator::HeaderLink.new(per_page: 10)
414
414
 
415
- response = client.make_request({ http_method: :get, uri: "/api/v1/resource" })
415
+ response = client.make_request(http_method: :get, uri: "/api/v1/resource")
416
416
 
417
417
  # paginated request
418
- data = client.make_request_for_pages({ http_method: :get, uri: "/api/v1/resource", data: true })
418
+ data = client.make_request_for_pages(http_method: :get, uri: "/api/v1/resource", data: true)
419
419
 
420
420
  ```
421
421
 
@@ -424,28 +424,28 @@ data = client.make_request_for_pages({ http_method: :get, uri: "/api/v1/resource
424
424
  ```ruby
425
425
  canvas_host = "https://host.instructure.com"
426
426
  canvas_access_token = "access_token"
427
- canvas_client = Client.new({ host: canvas_host })
428
- canvas_client.authenticator = Authenticator::Token.new({ access_token: canvas_access_token })
429
- canvas_client.paginator = Paginator::HeaderLink.new({ per_page: 10 })
427
+ canvas_client = Client.new(host: canvas_host)
428
+ canvas_client.authenticator = Authenticator::Token.new(access_token: canvas_access_token)
429
+ canvas_client.paginator = Paginator::HeaderLink.new(per_page: 10)
430
430
 
431
- canvas_response = canvas_client.make_request({ http_method: :get, uri: "/api/v1/accounts/1/terms" })
431
+ canvas_response = canvas_client.make_request(http_method: :get, uri: "/api/v1/accounts/1/terms")
432
432
 
433
433
  # paginated request
434
- canvas_data = canvas_client.make_request_for_pages({ http_method: :get, uri: "/api/v1/accounts/1/terms", data: true })
434
+ canvas_data = canvas_client.make_request_for_pages(http_method: :get, uri: "/api/v1/accounts/1/terms", data: true)
435
435
  ```
436
436
 
437
437
  ### Echo
438
438
 
439
439
  ```ruby
440
- echo_host = "https://echo360.org.au"
440
+ echo_host = "https://echo360.net.au"
441
441
  echo_client_id = "client_id"
442
442
  echo_client_secret = "client_secret"
443
- echo_client = Client.new({ host: echo_host })
444
- echo_client.authenticator = Authenticator::Oauth.new({ site: echo_host, token_url_path: "/oauth2/access_token", client_id: echo_client_id, client_secret: echo_client_secret })
445
- echo_client.paginator = Paginator::Echo.new({ limit: 10 })
443
+ echo_client = Client.new(host: echo_host)
444
+ echo_client.authenticator = Authenticator::Oauth.new(site: echo_host, token_url_path: "/oauth2/access_token", client_id: echo_client_id, client_secret: echo_client_secret)
445
+ echo_client.paginator = Paginator::Echo.new(limit: 10)
446
446
 
447
- echo_response = echo_client.make_request({ http_method: :get, uri: "/public/api/v1/terms" })
448
- echo_data = echo_client.make_request_for_pages({ http_method: :get, uri: "/public/api/v1/terms", data: true })
447
+ echo_response = echo_client.make_request(http_method: :get, uri: "/public/api/v1/terms")
448
+ echo_data = echo_client.make_request_for_pages(http_method: :get, uri: "/public/api/v1/terms", data: true)
449
449
  ```
450
450
 
451
451
  ## Create a request object
@@ -453,32 +453,32 @@ echo_data = echo_client.make_request_for_pages({ http_method: :get, uri: "/publi
453
453
  Create a `rest_client`.
454
454
 
455
455
  ```ruby
456
- rest_client = RestClientWrapper::RestClient.new({ host: "https://www.host.com" })
456
+ rest_client = RestClientWrapper::RestClient.new(host: "https://www.host.com")
457
457
  ```
458
458
 
459
459
  ## Request with a segmented absolute URI
460
460
 
461
461
  ```ruby
462
- request = Request.new({http_method: :get, uri: "https://www.host.com/public/api/v1/users/%<user_id>s" })
462
+ request = Request.new(http_method: :get, uri: "https://www.host.com/public/api/v1/users/%<user_id>s")
463
463
  request.segment_params = { user_id: "user_id" }
464
- response = rest_client.execute({ request: request })
464
+ response = rest_client.execute(request: request)
465
465
  ```
466
466
 
467
467
  ## Request with a segmented resource path
468
468
 
469
469
  ```ruby
470
- rest_client = RestClientWrapper::RestClient.new({ host: "https://www.host.com" })
471
- request = Request.new({ http_method: :get, uri: "/public/api/v1/users/%<user_id>s" })
470
+ rest_client = RestClientWrapper::RestClient.new(host: "https://www.host.com")
471
+ request = Request.new(http_method: :get, uri: "/public/api/v1/users/%<user_id>s")
472
472
  request.segment_params = { user_id: "user_id" }
473
- response = rest_client.execute({ request: request })
473
+ response = rest_client.execute(request: request)
474
474
  ```
475
475
 
476
476
  ## Query Parameters
477
477
 
478
478
  ```ruby
479
- rest_client = RestClientWrapper::RestClient.new({ host: "https://www.host.com" })
480
- request = Request.new({ http_method: :put, uri: "/api/v1/resource/" })
479
+ rest_client = RestClientWrapper::RestClient.new(host: "https://www.host.com")
480
+ request = Request.new(http_method: :put, uri: "/api/v1/resource/")
481
481
  request.payload = { user_id: "user_id" }
482
482
  request.query_params = { id: "value" }
483
- response = rest_client.execute({ request: request })
483
+ response = rest_client.execute(request: request)
484
484
  ```
@@ -50,14 +50,14 @@ module RestClientWrapper
50
50
  end
51
51
 
52
52
  def generate_auth
53
- Authenticator::Oauth.authenticate({ client_id: @client_id }) if @@api_client&.[](@client_id)&.[](:access_token).nil?
53
+ Authenticator::Oauth.authenticate(client_id: @client_id) if @@api_client&.[](@client_id)&.[](:access_token).nil?
54
54
  access_token = @@api_client&.[](@client_id)&.[](:access_token)
55
55
  raise StandardError "Unable to authenticate #{ @client_id }" if @@api_client&.[](@client_id)&.[](:access_token).nil?
56
56
 
57
57
  return { Authorization: "Bearer #{ access_token }" }
58
58
  end
59
59
 
60
- def self.authenticate(client_id:, access_token: nil)
60
+ def self.authenticate(client_id:, access_token: nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
61
61
  # Ensure that other threads aren't checking and updating the token at the same time
62
62
  @@api_client[client_id][:lock].synchronize do
63
63
  # Return access_token from @@api_client when the current_token is different to what's in @@api_client as it's already been refreshed
@@ -65,12 +65,12 @@ module RestClientWrapper
65
65
 
66
66
  payload = {
67
67
  grant_type: GrantType::CLIENT_CREDENTIALS,
68
- client_id: client_id,
68
+ client_id:,
69
69
  client_secret: @@api_client&.[](client_id)&.[](:settings)&.[](:client_secret)
70
70
  }
71
71
  url = "#{ @@api_client&.[](client_id)&.[](:settings)&.[](:site) }#{ @@api_client&.[](client_id)&.[](:settings)&.[](:token_url_path) }"
72
72
 
73
- response = ::RestClient::Request.execute({ method: :post, url: url, payload: payload })
73
+ response = ::RestClient::Request.execute(method: :post, url:, payload:)
74
74
 
75
75
  if Http.ok?(response.code)
76
76
  content_type = MIME::Types[response&.headers&.[](:content_type)].first
@@ -33,7 +33,7 @@ module RestClientWrapper
33
33
 
34
34
  # success
35
35
  def self.success?(code)
36
- return SUCCESS_STATUS_CODES[code].nil? ? false : true
36
+ return !SUCCESS_STATUS_CODES[code].nil?
37
37
  end
38
38
 
39
39
  # 200
@@ -33,7 +33,7 @@ module RestClientWrapper
33
33
 
34
34
  def initialize(limit: Paginate::DEFAULT_PAGINATION_PAGE_SIZE)
35
35
  @rest_client = nil
36
- @config = { limit: limit }
36
+ @config = { limit: }
37
37
  end
38
38
 
39
39
  def paginate(http_method:, uri:, segment_params: {}, query_params: {}, headers: {}, data: false)
@@ -42,14 +42,14 @@ module RestClientWrapper
42
42
  query_params.reverse_merge!(@config)
43
43
  responses = []
44
44
  loop do
45
- response = @rest_client.make_request({ http_method: http_method, uri: uri, segment_params: segment_params, query_params: query_params, headers: headers })
46
- block_given? ? yield(response) : (responses << response)
45
+ response = @rest_client.make_request(http_method:, uri:, segment_params:, query_params:, headers:)
46
+ (block_given?) ? yield(response) : (responses << response)
47
47
  links = _pagination_links(response)
48
48
  break unless links.key?(:offset)
49
49
 
50
50
  query_params[:offset] = links[:offset]
51
51
  end
52
- return data ? responses.map(&:body).pluck(:data).flatten : responses
52
+ return (data) ? responses.map(&:body).pluck(:data).flatten : responses
53
53
  end
54
54
 
55
55
  private
@@ -33,7 +33,7 @@ module RestClientWrapper
33
33
 
34
34
  def initialize(limit: Paginate::DEFAULT_PAGINATION_PAGE_SIZE)
35
35
  @rest_client = nil
36
- @config = { limit: limit }
36
+ @config = { limit: }
37
37
  end
38
38
 
39
39
  def paginate(http_method:, uri:, segment_params: {}, query_params: {}, headers: {}, data: false)
@@ -42,20 +42,20 @@ module RestClientWrapper
42
42
  query_params.reverse_merge!(@config)
43
43
  responses = []
44
44
  loop do
45
- response = @rest_client.make_request({ http_method: http_method, uri: uri, segment_params: segment_params, query_params: query_params, headers: headers })
46
- block_given? ? yield(response) : (responses << response)
45
+ response = @rest_client.make_request(http_method:, uri:, segment_params:, query_params:, headers:)
46
+ (block_given?) ? yield(response) : (responses << response)
47
47
  links = _pagination_links(response)
48
48
  break unless links.key?(:offset)
49
49
 
50
50
  query_params[:offset] = links[:offset]
51
51
  end
52
- return data ? responses.map(&:body).pluck(:data).flatten : responses
52
+ return (data) ? responses.map(&:body).pluck(:data).flatten : responses
53
53
  end
54
54
 
55
55
  private
56
56
 
57
57
  def _pagination_links(response)
58
- next_l = response&.body.instance_of?(Hash) ? response&.body&.[](:next) || "" : ""
58
+ next_l = (response&.body.instance_of?(Hash)) ? response&.body&.[](:next) || "" : ""
59
59
  next_h = Rack::Utils.parse_query(URI.parse(next_l)&.query)
60
60
  return next_h.symbolize_keys!
61
61
  end
@@ -33,7 +33,7 @@ module RestClientWrapper
33
33
 
34
34
  def initialize(per_page: Paginate::DEFAULT_PAGINATION_PAGE_SIZE)
35
35
  @rest_client = nil
36
- @config = { page: nil, per_page: per_page }
36
+ @config = { page: nil, per_page: }
37
37
  end
38
38
 
39
39
  def paginate(http_method:, uri:, segment_params: {}, query_params: {}, headers: {}, data: false)
@@ -43,18 +43,18 @@ module RestClientWrapper
43
43
  responses = []
44
44
  loop.with_index(1) do |_, page|
45
45
  query_params[:page] = page
46
- response = @rest_client.make_request({ http_method: http_method, uri: uri, segment_params: segment_params, query_params: query_params, headers: headers })
47
- block_given? ? yield(response) : (responses << response)
46
+ response = @rest_client.make_request(http_method:, uri:, segment_params:, query_params:, headers:)
47
+ (block_given?) ? yield(response) : (responses << response)
48
48
  links = _pagination_links(response)
49
49
  break unless links.key?(:next)
50
50
  end
51
- return data ? responses.map(&:body).flatten : responses
51
+ return (data) ? responses.map(&:body).flatten : responses
52
52
  end
53
53
 
54
54
  private
55
55
 
56
- def _pagination_links(response)
57
- re_uri = "\<(.*?)\>".freeze
56
+ def _pagination_links(response) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
57
+ re_uri = "<(.*?)>".freeze
58
58
  re_rel = "current|next|first|last".freeze
59
59
  links_a = response&.headers&.[](:link)&.split(",") || []
60
60
  links_h = {}
@@ -33,7 +33,7 @@ module RestClientWrapper
33
33
 
34
34
  def initialize(per_page: Paginate::DEFAULT_PAGINATION_PAGE_SIZE)
35
35
  @rest_client = nil
36
- @config = { page: nil, per_page: per_page }
36
+ @config = { page: nil, per_page: }
37
37
  end
38
38
 
39
39
  def paginate(http_method:, uri:, segment_params: {}, query_params: {}, headers: {}, data: false)
@@ -43,18 +43,18 @@ module RestClientWrapper
43
43
  responses = []
44
44
  loop.with_index(1) do |_, page|
45
45
  query_params[:page] = page
46
- response = @rest_client.make_request({ http_method: http_method, uri: uri, segment_params: segment_params, query_params: query_params, headers: headers })
47
- block_given? ? yield(response) : (responses << response)
46
+ response = @rest_client.make_request(http_method:, uri:, segment_params:, query_params:, headers:)
47
+ (block_given?) ? yield(response) : (responses << response)
48
48
  links = _pagination_links(response)
49
49
  break unless links.key?(:next)
50
50
  end
51
- return data ? responses.map(&:body).flatten : responses
51
+ return (data) ? responses.map(&:body).flatten : responses
52
52
  end
53
53
 
54
54
  private
55
55
 
56
- def _pagination_links(response)
57
- re_uri = "\<(.*?)\>".freeze
56
+ def _pagination_links(response) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
57
+ re_uri = "<(.*?)>".freeze
58
58
  re_rel = "current|next|first|last".freeze
59
59
  links_a = response&.headers&.[](:link)&.split(",") || []
60
60
  links_h = {}
@@ -30,11 +30,11 @@ module RestClientWrapper
30
30
 
31
31
  def initialize(**params)
32
32
  @uri = params[:uri]
33
- self.headers = params[:headers].nil? ? {} : params[:headers]
33
+ self.headers = (params[:headers].nil?) ? {} : params[:headers]
34
34
  self.http_method = params[:http_method]
35
- self.segment_params = params[:segment_params].nil? ? {} : params[:segment_params]
36
- self.payload = params[:payload].nil? ? {} : params[:payload]
37
- self.query_params = params[:query_params].nil? ? {} : params[:query_params]
35
+ self.segment_params = (params[:segment_params].nil?) ? {} : params[:segment_params]
36
+ self.payload = (params[:payload].nil?) ? {} : params[:payload]
37
+ self.query_params = (params[:query_params].nil?) ? {} : params[:query_params]
38
38
  end
39
39
 
40
40
  def http_method=(http_method)
@@ -67,7 +67,7 @@ module RestClientWrapper
67
67
  def headers=(headers)
68
68
  raise TypeError, "Request headers parameters is not a hash" unless headers.is_a?(Hash)
69
69
 
70
- @headers.nil? ? @headers = headers : @headers.merge!(headers)
70
+ (@headers.nil?) ? @headers = headers : @headers.merge!(headers)
71
71
  end
72
72
 
73
73
  end
@@ -62,13 +62,13 @@ module RestClientWrapper
62
62
  url = _build_uri(request)
63
63
 
64
64
  loop do
65
- access_token = @authenticator.is_a?(Authenticator::Oauth) ? @authenticator.access_token : nil
65
+ access_token = (@authenticator.is_a?(Authenticator::Oauth)) ? @authenticator.access_token : nil
66
66
  response_code = nil
67
67
 
68
68
  begin
69
- payload = Request::HTTP_METHOD_FOR_JSON.include?(request.http_method) && request.headers[:content_type] == :json ? request.payload.to_json : request.payload
69
+ payload = (Request::HTTP_METHOD_FOR_JSON.include?(request.http_method) && request.headers[:content_type] == :json) ? request.payload.to_json : request.payload
70
70
  request.headers[:params] = request.query_params
71
- response = ::RestClient::Request.execute({ method: request.http_method, url: url, payload: payload, headers: request.headers })
71
+ response = ::RestClient::Request.execute(method: request.http_method, url:, payload:, headers: request.headers)
72
72
  response_code = response&.code
73
73
  rescue StandardError => e
74
74
  response_code = e.response&.code
@@ -85,20 +85,20 @@ module RestClientWrapper
85
85
  end
86
86
 
87
87
  def execute_paginated_request(request:, data: true)
88
- return self.make_request_for_pages({ http_method: request.http_method, uri: request.uri, segment_params: request.segment_params, query_params: request.query_params, headers: request.headers, data: data }) # rubocop:disable Metrics/LineLength
88
+ return self.make_request_for_pages({ http_method: request.http_method, uri: request.uri, segment_params: request.segment_params, query_params: request.query_params, headers: request.headers, data: }) # rubocop:disable Metrics/LineLength
89
89
  end
90
90
 
91
91
  def make_request(http_method:, uri:, payload: {}, segment_params: {}, query_params: {}, headers: {})
92
- request = Request.new({ http_method: http_method, uri: uri, payload: payload, segment_params: segment_params, query_params: query_params })
92
+ request = Request.new(http_method:, uri:, payload:, segment_params:, query_params:)
93
93
  request.headers = headers
94
- return self.execute({ request: request })
94
+ return self.execute(request:)
95
95
  end
96
96
 
97
97
  def make_request_for_pages(http_method:, uri:, segment_params: {}, query_params: {}, headers: {}, data: false)
98
98
  raise RestClientError.new("Paginator not set, unable to make API call", nil, nil) unless @paginator
99
99
 
100
100
  @paginator.rest_client ||= self
101
- return @paginator.paginate({ http_method: http_method, uri: uri, segment_params: segment_params, query_params: query_params, headers: headers, data: data })
101
+ return @paginator.paginate(http_method:, uri:, segment_params:, query_params:, headers:, data:)
102
102
  end
103
103
 
104
104
  private
@@ -106,7 +106,7 @@ module RestClientWrapper
106
106
  def _set_auth(request)
107
107
  return if @authenticator.nil?
108
108
 
109
- auth = @authenticator.respond_to?(:generate_auth) ? @authenticator.generate_auth : {}
109
+ auth = (@authenticator.respond_to?(:generate_auth)) ? @authenticator.generate_auth : {}
110
110
  if @authenticator.is_a?(Authenticator::Custom)
111
111
  case @authenticator.type
112
112
  when :query_param
@@ -124,7 +124,7 @@ module RestClientWrapper
124
124
  parsed_uri = URI.parse(uri)
125
125
  raise ArgumentError, "URL host does not match config host of instance, unable to make API call" if parsed_uri.absolute? && @host.casecmp("#{ parsed_uri.scheme }://#{ parsed_uri.host }").nonzero?
126
126
 
127
- return parsed_uri.absolute? ? uri : "#{ @host }#{ uri }"
127
+ return (parsed_uri.absolute?) ? uri : "#{ @host }#{ uri }"
128
128
  end
129
129
 
130
130
  def _validate_request(request)
@@ -172,7 +172,7 @@ module RestClientWrapper
172
172
 
173
173
  def _wait_and_retry(response_code, access_token)
174
174
  sleep(@retry_configs[response_code][:wait].to_f)
175
- Authenticator::Oauth.authenticate({ client_id: @authenticator&.client_id, access_token: access_token }) if Http.unauthorized?(response_code) && @authenticator.is_a?(Authenticator::Oauth)
175
+ Authenticator::Oauth.authenticate(client_id: @authenticator&.client_id, access_token:) if Http.unauthorized?(response_code) && @authenticator.is_a?(Authenticator::Oauth)
176
176
  @retry_configs[response_code][:retry] += 1
177
177
  end
178
178
 
@@ -18,6 +18,6 @@
18
18
 
19
19
  module RestClientWrapper
20
20
 
21
- VERSION = "4.0.0".freeze
21
+ VERSION = "5.0.0".freeze
22
22
 
23
23
  end
@@ -30,22 +30,17 @@ Gem::Specification.new do |s|
30
30
  s.summary = "Rest client wrapper"
31
31
  s.description = "Generic REST client wrapper"
32
32
  s.license = "GPL 3.0"
33
- s.required_ruby_version = ">= 2.6.0"
33
+ s.required_ruby_version = ">= 3.2.2"
34
34
 
35
- s.add_runtime_dependency "json", ">= 1.8.3"
36
- s.add_runtime_dependency "oauth2", ">= 1.2"
37
- s.add_runtime_dependency "rack", ">= 2.0.5"
38
- s.add_runtime_dependency "rest-client", ">= 2.0.2"
39
- s.add_runtime_dependency "typhoeus", "~> 1.0", ">= 1.0.1"
40
-
41
- s.add_development_dependency "colorize", "~> 0.7", ">= 0.7.0"
42
- s.add_development_dependency "geminabox", "~> 0.13.0"
43
- s.add_development_dependency "rspec", "~> 3.4", ">= 3.4.0"
35
+ s.add_runtime_dependency "json", "~> 2.6.3"
36
+ s.add_runtime_dependency "oauth2", "~> 2.0.9"
37
+ s.add_runtime_dependency "rest-client", "~> 2.1.0"
38
+ s.add_runtime_dependency "typhoeus", "~> 1.4"
44
39
 
45
40
  s.metadata["allowed_push_host"] = "https://rubygems.org"
46
41
 
47
42
  s.files = Dir.glob("lib/**/*.{rake,rb}") + ["#{ s.name }.gemspec", "README.md"]
48
- s.test_files = `find spec/*`.split("\n")
49
43
  s.executables = []
50
44
  s.require_paths = ["lib"]
45
+ s.metadata["rubygems_mfa_required"] = "true"
51
46
  end