ruby_http_client 3.4.3 → 3.5.0

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: 8e31d36787f9a9884ba0058c32dd4afcc9819c85449f9219fbfd06875a234ae5
4
- data.tar.gz: 8d050bdebb3367d89ae53ebb83d1a2f0f7f2e639a9dec3d27cd71b819848c3d7
3
+ metadata.gz: 508dd343a5994fe2f5b5efa8c088213348488ca0524c99fe327cb7cd244dc5df
4
+ data.tar.gz: a239ad23f4dc8f87dc65b738d8e05cc91a3904b0a04452eec6091005a215c893
5
5
  SHA512:
6
- metadata.gz: d1bad69c5dd5b3c5195e62977f75b47ee584b8f9d0a096580ad447d23abbf6e1cae11b1532301689ea8668efc6ab0531ce9380e10f0afb72d87764a10a26e7aa
7
- data.tar.gz: 3e396c3fa726e05f571b56af4c8209d081f4f1e0e553dfeeb8d397fdc7c242bb8a3d2d94135c68ad3a4637f1d23212547fa8d6c1da13eed1b2f483b5a8d6861d
6
+ metadata.gz: 39e4db29d108b36ff22d9bdef44efaff457de7e6bee92921f3aa2eebcb25003e8dfca46c35ef005168e97859e578a409fc64669f9f6f82099d71eac2e7b605d5
7
+ data.tar.gz: 5b74ee2d1306c0c47e282542391ba63ffe694360d53e10d93f5a64e1510f79bc392348c12ea61e55e0a4b1084e034a2a4352093820bf98ead47c206bc9eeae7d
@@ -13,35 +13,35 @@ Documentation:
13
13
  Enabled: false
14
14
  Encoding:
15
15
  Enabled: false
16
+ Layout/EmptyLinesAroundBlockBody:
17
+ Enabled: true
18
+ Layout/ExtraSpacing:
19
+ Enabled: true
20
+ AllowForAlignment: false
21
+ ForceEqualSignAlignment: false
22
+ Layout/SpaceBeforeFirstArg:
23
+ Enabled: true
16
24
  LineLength:
17
25
  Enabled: false
18
26
  MethodLength:
19
27
  Enabled: false
20
28
  Metrics/AbcSize:
21
29
  Enabled: false
30
+ Metrics/BlockLength:
31
+ Enabled: false
22
32
  Metrics/ModuleLength:
23
33
  Enabled: false
34
+ Naming/FileName:
35
+ Enabled: true
24
36
  PerceivedComplexity:
25
37
  Enabled: false
26
- Layout/SpaceBeforeFirstArg:
27
- Enabled: true
28
38
  Style/ClassAndModuleChildren:
29
39
  Enabled: false
30
- Layout/EmptyLinesAroundBlockBody:
31
- Enabled: true
32
- Naming/FileName:
33
- Enabled: true
34
40
  Style/RescueModifier:
35
41
  Enabled: true
36
42
  Style/StringLiterals:
37
43
  Enabled: true
38
- Metrics/BlockLength:
39
- Enabled: false
40
44
  Style/NumericLiterals:
41
45
  Enabled: false
42
- Layout/ExtraSpacing:
43
- Enabled: true
44
- AllowForAlignment: false
45
- ForceEqualSignAlignment: false
46
46
  Style/FrozenStringLiteralComment:
47
47
  Enabled: false
@@ -1,30 +1,32 @@
1
1
  env:
2
2
  global:
3
- - CC_TEST_REPORTER_ID=$CC_TEST_REPORTER_ID
3
+ - CC_TEST_REPORTER_ID=$CC_TEST_REPORTER_ID
4
4
  language: ruby
5
5
  rvm:
6
- - ruby-head
7
- - 2.6
8
- - 2.5
9
- - 2.4
10
- - jruby
6
+ - ruby-head
7
+ - 2.7
8
+ - 2.6
9
+ - 2.5
10
+ - 2.4
11
+ - jruby
11
12
  before_install:
12
13
  - gem install minitest
13
14
  - gem install simplecov
15
+ - gem install codecov
14
16
  before_script:
15
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
16
- > ./cc-test-reporter
17
- - chmod +x ./cc-test-reporter
18
- - "./cc-test-reporter before-build"
17
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
18
+ > ./cc-test-reporter
19
+ - chmod +x ./cc-test-reporter
20
+ - "./cc-test-reporter before-build"
19
21
  script:
20
- - rake
22
+ - rake
21
23
  after_script:
22
- - "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
24
+ - "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
23
25
  deploy:
24
26
  provider: rubygems
25
27
  api_key:
26
28
  secure: ubaCqrwnHN4TzLhFyM7/2WPicNya2FSeKbZiG9zqGGTklTNi3T/pP1BUDdVQGNSOsvBl/s20P6M+aKL6KTH9t4JpS4laFgI3iwBWyg4Q4fcchDMOrtMaChR7FvIfvOOFcCQYvvMB/U+Mr9GSnKkVHmcu2JQgZM/kBSst3FymAQeRa8+64IKg2s/DjPejT4aTvyuqJ75xN+pkCbv36KHic1jrKZgpSdWZ7UaOZfBJ7xdReCXYXignKFJs1240O1yfIyikFrgTs75Ch7/OmI792CaFIKIvODg97wYlCnu0FYCOxNfZw2JVwp+oYqXRkI5l2ljXWFvjPxdckGSP7rM4lL9GxSgVqgqBd1orXyab2Ad+POlbx97wEmoYLbIF4BHGoe7nXV7BXquQDWIm2o5vx5RxenTnWMOZNLbRBVUAdRbxrxW8iQhTRs+jjeJu3Cj9alWd7UPB/t2v8/c9MpOCNdH+QyAJW6dvZrKTyy75CofGAYbzezp2DA91IXAELiFQaPhCXXzkOTVHCh9+mBYG7b0t1iXQoN+MMcyQ3q89coZDxI1l77keNPbj8GcQQ35fRxRhmgsID+mQfuYXgkx8aTs5MYwJWy+sxyOrEBMAyehDhdk0JZjJdYhgsh+zIqfpy9meZIxNxNQ7+s1EGoFW4RggKark2t9Y8NML7hX+xIc=
27
- gem: sendgrid-ruby
29
+ gem: ruby_http_client
28
30
  on:
29
31
  tags: true
30
32
  rvm: '2.4'
@@ -3,6 +3,29 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ [2020-03-04] Version 3.5.0
7
+ --------------------------
8
+ **Library - Fix**
9
+ - [PR #118](https://github.com/sendgrid/ruby-http-client/pull/118): JSON-encode array request bodies. Thanks to [@childish-sambino](https://github.com/childish-sambino)!
10
+ - [PR #67](https://github.com/sendgrid/ruby-http-client/pull/67): Split up the build_request function to logical component functions to reduce method complexity. Thanks to [@sony-mathew](https://github.com/sony-mathew)!
11
+ - [PR #115](https://github.com/sendgrid/ruby-http-client/pull/115): update incorrect gem name. Thanks to [@thinkingserious](https://github.com/thinkingserious)!
12
+
13
+ **Library - Chore**
14
+ - [PR #116](https://github.com/sendgrid/ruby-http-client/pull/116): add Ruby 2.7 to Travis. Thanks to [@childish-sambino](https://github.com/childish-sambino)!
15
+ - [PR #92](https://github.com/sendgrid/ruby-http-client/pull/92): Add CodeCov support to .travis.yml. Thanks to [@jamietanna](https://github.com/jamietanna)!
16
+
17
+ **Library - Feature**
18
+ - [PR #68](https://github.com/sendgrid/ruby-http-client/pull/68): add ratelimit support. Thanks to [@awj](https://github.com/awj)!
19
+
20
+ **Library - Test**
21
+ - [PR #98](https://github.com/sendgrid/ruby-http-client/pull/98): Fix rubocop.yml formatting warnings. Thanks to [@RolandBurrows](https://github.com/RolandBurrows)!
22
+
23
+ **Library - Docs**
24
+ - [PR #100](https://github.com/sendgrid/ruby-http-client/pull/100): adding code review section under contributing.md. Thanks to [@prathamsharma92](https://github.com/prathamsharma92)!
25
+ - [PR #101](https://github.com/sendgrid/ruby-http-client/pull/101): Grammerly checks on *.md files. Thanks to [@prathamsharma92](https://github.com/prathamsharma92)!
26
+ - [PR #84](https://github.com/sendgrid/ruby-http-client/pull/84): Corrected *.md files using Grammarly. Thanks to [@pushkyn](https://github.com/pushkyn)!
27
+
28
+
6
29
  [2020-02-19] Version 3.4.3
7
30
  --------------------------
8
31
  **Library - Fix**
@@ -1,4 +1,4 @@
1
- Hello! Thank you for choosing to help contribute to one of the SendGrid open source libraries. There are many ways you can contribute and help is always welcome. We simply ask that you follow the following contribution policies.
1
+ Hello! Thank you for choosing to help contribute to one of the SendGrid open source libraries. There are many ways you can contribute and help is always welcome. We simply ask that you follow the following contribution policies.
2
2
 
3
3
  - [CLAs and CCLAs](#cla)
4
4
  - [Roadmap & Milestones](#roadmap)
@@ -9,16 +9,17 @@ Hello! Thank you for choosing to help contribute to one of the SendGrid open sou
9
9
  - [Testing](#testing)
10
10
  - [Style Guidelines & Naming Conventions](#style-guidelines-and-naming-conventions)
11
11
  - [Creating a Pull Request](#creating-a-pull-request)
12
+ - [Code Reviews](#code-reviews)
12
13
 
13
14
  <a name="roadmap"></a>
14
- We use [Milestones](https://github.com/sendgrid/ruby-http-client/milestones) to help define current roadmaps, please feel free to grab an issue from the current milestone. Please indicate that you have begun work on it to avoid collisions. Once a PR is made, community review, comments, suggestions and additional PRs are welcomed and encouraged.
15
+ We use [Milestones](https://github.com/sendgrid/ruby-http-client/milestones) to help define current roadmaps, please feel free to grab an issue from the current milestone. Please indicate that you have begun work on it to avoid collisions. Once a PR is made, community review, comments, suggestions, and additional PRs are welcomed and encouraged.
15
16
 
16
17
  <a name="cla"></a>
17
18
  ## CLAs and CCLAs
18
19
 
19
20
  Before you get started, SendGrid requires that a SendGrid Contributor License Agreement (CLA) be filled out by every contributor to a SendGrid open source project.
20
21
 
21
- Our goal with the CLA is to clarify the rights of our contributors and reduce other risks arising from inappropriate contributions. The CLA also clarifies the rights SendGrid holds in each contribution and helps to avoid misunderstandings over what rights each contributor is required to grant to SendGrid when making a contribution. In this way the CLA encourages broad participation by our open source community and helps us build strong open source projects, free from any individual contributor withholding or revoking rights to any contribution.
22
+ Our goal with the CLA is to clarify the rights of our contributors and reduce other risks arising from inappropriate contributions. The CLA also clarifies the rights SendGrid holds in each contribution and helps to avoid misunderstandings over what rights each contributor is required to grant to SendGrid when making a contribution. In this way, the CLA encourages broad participation by our open source community and helps us build strong open source projects, free from any individual contributor withholding or revoking rights to any contribution.
22
23
 
23
24
  SendGrid does not merge a pull request made against a SendGrid open source project until that pull request is associated with a signed CLA. Copies of the CLA are available [here](https://gist.github.com/SendGridDX/98b42c0a5d500058357b80278fde3be8#file-sendgrid_cla).
24
25
 
@@ -46,7 +47,7 @@ A software bug is a demonstrable issue in the code base. In order for us to diag
46
47
  Before you decide to create a new issue, please try the following:
47
48
 
48
49
  1. Check the Github issues tab if the identified issue has already been reported, if so, please add a +1 to the existing post.
49
- 2. Update to the latest version of this code and check if issue has already been fixed
50
+ 2. Update to the latest version of this code and check if the issue has already been fixed
50
51
  3. Copy and fill in the Bug Report Template we have provided below
51
52
 
52
53
  ### Please use our Bug Report Template
@@ -166,7 +167,7 @@ Please run your code through:
166
167
 
167
168
  4. Commit your changes in logical chunks. Please adhere to these [git commit
168
169
  message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
169
- or your code is unlikely be merged into the main project. Use Git's
170
+ or your code is unlikely to be merged into the main project. Use Git's
170
171
  [interactive rebase](https://help.github.com/articles/interactive-rebase)
171
172
  feature to tidy up your commits before making them public.
172
173
 
@@ -190,3 +191,8 @@ Please run your code through:
190
191
  with a clear title and description against the `development` branch. All tests must be passing before we will review the PR.
191
192
 
192
193
  If you have any additional questions, please feel free to [email](mailto:dx@sendgrid.com) us or create an issue in this repo.
194
+
195
+ <a name="code-reviews"></a>
196
+ ## Code Reviews
197
+
198
+ If you can, please look at open PRs and review them. Give feedback and help us merge these PRs much faster! If you don't know how, Github has some great <a href="https://help.github.com/articles/about-pull-request-reviews/">information on how to review a Pull Request.</a>
data/README.md CHANGED
@@ -12,9 +12,8 @@
12
12
  If you are looking for the SendGrid API client library, please see [this repo](https://github.com/sendgrid/sendgrid-ruby).
13
13
 
14
14
  # Announcements
15
- **NEW:** If you're a software engineer who is passionate about #DeveloperExperience and/or #OpenSource, [this is an incredible opportunity to join our #DX team](https://sendgrid.com/careers/role/1421152/?gh_jid=1421152) as a Developer Experience Engineer and work with [@thinkingserious](https://github.com/thinkingserious) and [@aroach](https://github.com/aroach)! Tell your friends :)
16
15
 
17
- All updates to this library is documented in our [CHANGELOG](https://github.com/sendgrid/ruby-http-client/blob/master/CHANGELOG.md).
16
+ All updates to this library are documented in our [CHANGELOG](https://github.com/sendgrid/ruby-http-client/blob/master/CHANGELOG.md).
18
17
 
19
18
  # Table of Contents
20
19
  - [Installation](#installation)
@@ -30,7 +29,7 @@ All updates to this library is documented in our [CHANGELOG](https://github.com/
30
29
 
31
30
  ## Prerequisites
32
31
 
33
- - Ruby version 2.2+
32
+ - Ruby version >= 2.4
34
33
 
35
34
  ## Setup Environment Variables
36
35
 
@@ -103,6 +102,7 @@ Quick links:
103
102
  - [Bug Reports](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md#submit-a-bug-report)
104
103
  - [Sign the CLA to Create a Pull Request](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md)
105
104
  - [Improvements to the Codebase](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md#improvements-to-the-codebase)
105
+ - [Review Pull Requests](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md#code-reviews)
106
106
 
107
107
  <a name="about"></a>
108
108
  # About
@@ -8,7 +8,7 @@ If you can't find a solution below, please open an [issue](https://github.com/se
8
8
  <a name="request-body"></a>
9
9
  ## Viewing the Request Body
10
10
 
11
- When debugging or testing, it may be useful to exampine the raw request body to compare against the [documented format](https://sendgrid.com/docs/API_Reference/api_v3.html).
11
+ When debugging or testing, it may be useful to examine the raw request body to compare against the [documented format](https://sendgrid.com/docs/API_Reference/api_v3.html).
12
12
 
13
13
  You can do this right before you call: `response = client.version('v3').api_keys.post(request_body: request_body)` like so:
14
14
 
@@ -88,3 +88,12 @@ puts response.headers
88
88
  response = client.api_keys._(api_key_id).delete
89
89
  puts response.status_code
90
90
  puts response.headers
91
+
92
+ # Rate limit information
93
+ response = client.version('v3').api_keys._(api_key_id).get
94
+ puts response.ratelimit.limit
95
+ puts response.ratelimit.remaining
96
+ puts response.ratelimit.reset
97
+ puts response.ratelimit.exceeded?
98
+ # Sleep the current thread until the reset has happened
99
+ response.ratelimit.wait!
@@ -35,7 +35,7 @@ We label our issues according to their difficulty level. You can find easy ones
35
35
  git pull upstream <dev-branch>
36
36
  ```
37
37
 
38
- 3. Create a new topic branch (off the main project development branch) to
38
+ 3. Create a new topic branch (off of the main project development branch) to
39
39
  contain your feature, change, or fix:
40
40
 
41
41
  ```bash
@@ -6,10 +6,54 @@ module SendGrid
6
6
 
7
7
  # Holds the response from an API call.
8
8
  class Response
9
+ # Provide useful functionality around API rate limiting.
10
+ class Ratelimit
11
+ attr_reader :limit, :remaining, :reset
12
+
13
+ # * *Args* :
14
+ # - +limit+ -> The total number of requests allowed within a rate limit window
15
+ # - +remaining+ -> The number of requests that have been processed within this current rate limit window
16
+ # - +reset+ -> The time (in seconds since Unix Epoch) when the rate limit will reset
17
+ def initialize(limit, remaining, reset)
18
+ @limit = limit.to_i
19
+ @remaining = remaining.to_i
20
+ @reset = Time.at reset.to_i
21
+ end
22
+
23
+ def exceeded?
24
+ remaining <= 0
25
+ end
26
+
27
+ # * *Returns* :
28
+ # - The number of requests that have been used out of this
29
+ # rate limit window
30
+ def used
31
+ limit - remaining
32
+ end
33
+
34
+ # Sleep until the reset time arrives. If given a block, it will
35
+ # be called after sleeping is finished.
36
+ #
37
+ # * *Returns* :
38
+ # - The amount of time (in seconds) that the rate limit slept
39
+ # for.
40
+ def wait!
41
+ now = Time.now.utc.to_i
42
+ duration = (reset.to_i - now) + 1
43
+
44
+ sleep duration if duration >= 0
45
+
46
+ yield if block_given?
47
+
48
+ duration
49
+ end
50
+ end
51
+
9
52
  # * *Args* :
10
53
  # - +response+ -> A NET::HTTP response object
11
54
  #
12
55
  attr_reader :status_code, :body, :headers
56
+
13
57
  def initialize(response)
14
58
  @status_code = response.code
15
59
  @body = response.body
@@ -21,6 +65,20 @@ module SendGrid
21
65
  def parsed_body
22
66
  @parsed_body ||= JSON.parse(@body, symbolize_names: true)
23
67
  end
68
+
69
+ def ratelimit
70
+ return @ratelimit unless @ratelimit.nil?
71
+
72
+ limit = headers['X-RateLimit-Limit']
73
+ remaining = headers['X-RateLimit-Remaining']
74
+ reset = headers['X-RateLimit-Reset']
75
+
76
+ # Guard against possibility that one (or probably, all) of the
77
+ # needed headers were not returned.
78
+ @ratelimit = Ratelimit.new(limit, remaining, reset) if limit && remaining && reset
79
+
80
+ @ratelimit
81
+ end
24
82
  end
25
83
 
26
84
  # A simple REST client.
@@ -141,29 +199,10 @@ module SendGrid
141
199
  #
142
200
  def build_request(name, args)
143
201
  build_args(args) if args
144
- uri = build_url(query_params: @query_params)
145
- @http = build_http(uri.host, uri.port)
146
- net_http = Kernel.const_get('Net::HTTP::' + name.to_s.capitalize)
147
- @request = build_request_headers(net_http.new(uri.request_uri))
148
- if @request_body &&
149
- (!@request_headers.key?('Content-Type') ||
150
- @request_headers['Content-Type'] == 'application/json')
151
-
152
- # If body is a hash, encode it; else leave it alone
153
- @request.body = if @request_body.class == Hash
154
- @request_body.to_json
155
- else
156
- @request_body
157
- end
158
- @request['Content-Type'] = 'application/json'
159
- elsif !@request_body && (name.to_s == 'post')
160
- @request['Content-Type'] = ''
161
- else
162
- @request.body = @request_body
163
- end
164
- @http_options.each do |attribute, value|
165
- @http.send("#{attribute}=", value)
166
- end
202
+ # build the request & http object
203
+ build_http_request(name)
204
+ # set the content type & request body
205
+ update_content_type(name)
167
206
  make_request(@http, @request)
168
207
  end
169
208
 
@@ -227,7 +266,7 @@ module SendGrid
227
266
  # (e.g. client.name.name.get())
228
267
  #
229
268
  # * *Args* :
230
- # - The args are autmoatically passed in
269
+ # - The args are automatically passed in
231
270
  # * *Returns* :
232
271
  # - Client object or Response object
233
272
  #
@@ -245,6 +284,37 @@ module SendGrid
245
284
  # Add a segment to the URL
246
285
  _(name)
247
286
  end
287
+
288
+ private
289
+
290
+ def build_http_request(http_method)
291
+ uri = build_url(query_params: @query_params)
292
+ net_http = Kernel.const_get('Net::HTTP::' + http_method.to_s.capitalize)
293
+
294
+ @http = build_http(uri.host, uri.port)
295
+ @request = build_request_headers(net_http.new(uri.request_uri))
296
+ end
297
+
298
+ def update_content_type(http_method)
299
+ if @request_body && content_type_json?
300
+ # If body is a hash or array, encode it; else leave it alone
301
+ @request.body = if [Hash, Array].include?(@request_body.class)
302
+ @request_body.to_json
303
+ else
304
+ @request_body
305
+ end
306
+ @request['Content-Type'] = 'application/json'
307
+ elsif !@request_body && http_method.to_s == 'post'
308
+ @request['Content-Type'] = ''
309
+ else
310
+ @request.body = @request_body
311
+ end
312
+ end
313
+
314
+ def content_type_json?
315
+ !@request_headers.key?('Content-Type') ||
316
+ @request_headers['Content-Type'] == 'application/json'
317
+ end
248
318
  # rubocop:enable Style/MethodMissingSuper
249
319
  # rubocop:enable Style/MissingRespondToMissing
250
320
  end
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = 'ruby_http_client'
6
- spec.version = '3.4.3'
6
+ spec.version = '3.5.0'
7
7
  spec.authors = ['Elmer Thomas']
8
8
  spec.email = 'dx@sendgrid.com'
9
9
  spec.summary = 'A simple REST client'
@@ -15,6 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.test_files = spec.files.grep(/^(test|spec|features)/)
16
16
  spec.require_paths = ['lib']
17
17
 
18
+ spec.add_development_dependency 'codecov'
18
19
  spec.add_development_dependency 'minitest'
19
20
  spec.add_development_dependency 'rake'
20
21
  spec.add_development_dependency 'rubocop'
@@ -1,4 +1,7 @@
1
1
  if ENV['CI'] == 'true'
2
2
  require 'simplecov'
3
3
  SimpleCov.start
4
+
5
+ require 'codecov'
6
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
4
7
  end
@@ -12,6 +12,18 @@ class MockResponse
12
12
  end
13
13
  end
14
14
 
15
+ class MockHttpResponse
16
+ attr_reader :code, :body, :headers
17
+
18
+ def initialize(code, body, headers)
19
+ @code = code
20
+ @body = body
21
+ @headers = headers
22
+ end
23
+
24
+ alias to_hash headers
25
+ end
26
+
15
27
  class MockResponseWithRequestBody < MockResponse
16
28
  attr_reader :request_body
17
29
 
@@ -177,7 +189,7 @@ class TestClient < Minitest::Test
177
189
  assert_equal('hogebody', client.request.body)
178
190
  end
179
191
 
180
- def test_json_body_encode
192
+ def test_json_body_encode_hash
181
193
  headers = {
182
194
  'Content-Type' => 'application/json'
183
195
  }
@@ -191,6 +203,20 @@ class TestClient < Minitest::Test
191
203
  assert_equal('{"this_is":"json"}', response.request_body)
192
204
  end
193
205
 
206
+ def test_json_body_encode_array
207
+ headers = {
208
+ 'Content-Type' => 'application/json'
209
+ }
210
+ client = MockRequestWithRequestBody.new(
211
+ host: 'https://localhost',
212
+ request_headers: headers
213
+ )
214
+ name = 'post'
215
+ args = [{ 'request_body' => [{ 'this_is' => 'json' }] }]
216
+ response = client.build_request(name, args)
217
+ assert_equal('[{"this_is":"json"}]', response.request_body)
218
+ end
219
+
194
220
  def test_json_body_do_not_reencode
195
221
  headers = {
196
222
  'Content-Type' => 'application/json'
@@ -232,6 +258,34 @@ class TestClient < Minitest::Test
232
258
  assert_equal(['test'], url1.url_path)
233
259
  end
234
260
 
261
+ def test_ratelimit_core
262
+ expiry = Time.now.to_i + 1
263
+ rl = SendGrid::Response::Ratelimit.new(500, 100, expiry)
264
+ rl2 = SendGrid::Response::Ratelimit.new(500, 0, expiry)
265
+
266
+ refute rl.exceeded?
267
+ assert rl2.exceeded?
268
+
269
+ assert_equal(rl.used, 400)
270
+ assert_equal(rl2.used, 500)
271
+ end
272
+
273
+ def test_response_ratelimit_parsing
274
+ headers = {
275
+ 'X-RateLimit-Limit' => '500',
276
+ 'X-RateLimit-Remaining' => '300',
277
+ 'X-RateLimit-Reset' => Time.now.to_i.to_s
278
+ }
279
+
280
+ body = ''
281
+ code = 204
282
+ http_response = MockHttpResponse.new(code, body, headers)
283
+ response = SendGrid::Response.new(http_response)
284
+
285
+ refute_nil response.ratelimit
286
+ refute response.ratelimit.exceeded?
287
+ end
288
+
235
289
  def test_method_missing
236
290
  response = @client.get
237
291
  assert_equal(200, response.status_code)
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_http_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.3
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elmer Thomas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-20 00:00:00.000000000 Z
11
+ date: 2020-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: codecov
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'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: minitest
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -115,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
129
  - !ruby/object:Gem::Version
116
130
  version: '0'
117
131
  requirements: []
118
- rubygems_version: 3.0.6
132
+ rubygems_version: 3.0.3
119
133
  signing_key:
120
134
  specification_version: 4
121
135
  summary: A simple REST client