ruby_http_client 3.4.3 → 3.5.3

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: cf298c885c0b0dca01df98cb03d9009ddb3b203fdb8a092a098358249e52a1fb
4
+ data.tar.gz: 42140a3b6dfd2fe8513ee82aa36c9e44f25ea6bcb8e8366d49e84e96fe39324a
5
5
  SHA512:
6
- metadata.gz: d1bad69c5dd5b3c5195e62977f75b47ee584b8f9d0a096580ad447d23abbf6e1cae11b1532301689ea8668efc6ab0531ce9380e10f0afb72d87764a10a26e7aa
7
- data.tar.gz: 3e396c3fa726e05f571b56af4c8209d081f4f1e0e553dfeeb8d397fdc7c242bb8a3d2d94135c68ad3a4637f1d23212547fa8d6c1da13eed1b2f483b5a8d6861d
6
+ metadata.gz: 501e371ce784a7ca64d3cd1459ccf6c84424fd581c17403a1e59ee1f9d9ad21660ae1e8b815cae11ddbae81e3ec96ea5c9a8d1f7cbe21af223875f9907b64141
7
+ data.tar.gz: ccd94079a82b5eb2e25974daf3ec6e8d768605ce174400e8f2fe33f8ba3696509d0c42bf9f7fb3e5fbfd4586a0c52082a33aa9f5e07b11c7b8db901921732743
@@ -0,0 +1,10 @@
1
+ contact_links:
2
+ - name: Twilio SendGrid Support
3
+ url: https://support.sendgrid.com
4
+ about: Get Support
5
+ - name: Stack Overflow
6
+ url: https://stackoverflow.com/questions/tagged/ruby-http-client+or+sendgrid+ruby
7
+ about: Ask questions on Stack Overflow
8
+ - name: Documentation
9
+ url: https://sendgrid.com/docs/for-developers/
10
+ about: View Reference Documentation
data/.rubocop.yml CHANGED
@@ -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
data/.travis.yml CHANGED
@@ -3,29 +3,34 @@ env:
3
3
  - CC_TEST_REPORTER_ID=$CC_TEST_REPORTER_ID
4
4
  language: ruby
5
5
  rvm:
6
- - ruby-head
6
+ - 2.7
7
7
  - 2.6
8
8
  - 2.5
9
9
  - 2.4
10
- - jruby
11
- before_install:
12
- - gem install minitest
13
- - gem install simplecov
10
+ - jruby-9.2
14
11
  before_script:
12
+ - make install
15
13
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
16
14
  > ./cc-test-reporter
17
15
  - chmod +x ./cc-test-reporter
18
16
  - "./cc-test-reporter before-build"
19
17
  script:
20
- - rake
18
+ - make test
21
19
  after_script:
22
20
  - "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
23
21
  deploy:
24
22
  provider: rubygems
25
- api_key:
26
- 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
23
+ api_key: "$RUBYGEMS_API_KEY"
24
+ gem: ruby_http_client
28
25
  on:
29
26
  tags: true
30
27
  rvm: '2.4'
31
28
  skip_cleanup: true
29
+ notifications:
30
+ slack:
31
+ if: branch = main
32
+ on_pull_requests: false
33
+ on_success: never
34
+ on_failure: change
35
+ rooms:
36
+ secure: OMWyUuj4Fu3n39qPhlNJlVoxhHYwS/xEC3sTtCztp1cc6eIfifletIwABRtGwoJw5ZyZ8tk3EZZjYu8iMVCyZzqAXK7e8OS1j8TW7gTs55j8BbZzgH00PMLa2/jQ/KJpF/0BqWsuexnApeJbuZVkIkOln6IzEFTUp8GKfoA3jXA4fxnfpE/hXQvLL/zw5a/qhv4Z1gl+aTN+LGW4M8dFvgTpEP993c7MCdXH+FcYhZKeDlQVtoEFc1NvcanjQmjZ6to99jAQM1VXBVqGrSowf7V525TNJy9MJ/txh1Y3scJI/eBtLIx+OTjGrL0AGvM+y7wq8U8WG8ssf83KogLTpvAOQXtWPZMO50q/n4D9a8eiIy5sZMAg+CafOovlyRqCS6tvYfmmSnOy+a9TyrQ1EGR7dT0dFpsYxEIkudcnxsWZ7sdboGrCdR92aotxp5+QLeDoOA3yeLiySqORUgG+JJ0xawftJnPnOC5qNzzLhQAf8bD31C1OnVqdE2DeKlzaCrTp4LBIVX5NNT707L62U6DZQCEOv1G/752n3NRUY9Trw+L+j8bq3vnPC2ER5hN9df0J3zvUfw/GXQd20OXRbv+nTU82uYNbpmevswyb/1H42NW/w82f3yOcic+lzF5XXLb8ZHbjn/sAt//7q7rDy2o20htzcK3we29LMIpf4pA=
data/CHANGELOG.md CHANGED
@@ -3,6 +3,47 @@ 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
+ [2022-01-12] Version 3.5.3
7
+ --------------------------
8
+ **Library - Chore**
9
+ - [PR #126](https://github.com/sendgrid/ruby-http-client/pull/126): update license year. Thanks to [@JenniferMah](https://github.com/JenniferMah)!
10
+
11
+
12
+ [2021-01-13] Version 3.5.2
13
+ --------------------------
14
+ **Library - Fix**
15
+ - [PR #124](https://github.com/sendgrid/ruby-http-client/pull/124): Mistake on setup http_options for Net::HTTP object when build http. Thanks to [@hoangtuanictvn](https://github.com/hoangtuanictvn)!
16
+
17
+
18
+ [2020-08-19] Version 3.5.1
19
+ --------------------------
20
+ **Library - Chore**
21
+ - [PR #120](https://github.com/sendgrid/ruby-http-client/pull/120): update GitHub branch references to use HEAD. Thanks to [@thinkingserious](https://github.com/thinkingserious)!
22
+
23
+
24
+ [2020-03-04] Version 3.5.0
25
+ --------------------------
26
+ **Library - Fix**
27
+ - [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)!
28
+ - [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)!
29
+ - [PR #115](https://github.com/sendgrid/ruby-http-client/pull/115): update incorrect gem name. Thanks to [@thinkingserious](https://github.com/thinkingserious)!
30
+
31
+ **Library - Chore**
32
+ - [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)!
33
+ - [PR #92](https://github.com/sendgrid/ruby-http-client/pull/92): Add CodeCov support to .travis.yml. Thanks to [@jamietanna](https://github.com/jamietanna)!
34
+
35
+ **Library - Feature**
36
+ - [PR #68](https://github.com/sendgrid/ruby-http-client/pull/68): add ratelimit support. Thanks to [@awj](https://github.com/awj)!
37
+
38
+ **Library - Test**
39
+ - [PR #98](https://github.com/sendgrid/ruby-http-client/pull/98): Fix rubocop.yml formatting warnings. Thanks to [@RolandBurrows](https://github.com/RolandBurrows)!
40
+
41
+ **Library - Docs**
42
+ - [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)!
43
+ - [PR #101](https://github.com/sendgrid/ruby-http-client/pull/101): Grammerly checks on *.md files. Thanks to [@prathamsharma92](https://github.com/prathamsharma92)!
44
+ - [PR #84](https://github.com/sendgrid/ruby-http-client/pull/84): Corrected *.md files using Grammarly. Thanks to [@pushkyn](https://github.com/pushkyn)!
45
+
46
+
6
47
  [2020-02-19] Version 3.4.3
7
48
  --------------------------
8
49
  **Library - Fix**
data/CONTRIBUTING.md CHANGED
@@ -1,7 +1,5 @@
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
- - [CLAs and CCLAs](#cla)
4
- - [Roadmap & Milestones](#roadmap)
5
3
  - [Feature Request](#feature-request)
6
4
  - [Submit a Bug Report](#submit-a-bug-report)
7
5
  - [Improvements to the Codebase](#improvements-to-the-codebase)
@@ -9,22 +7,7 @@ Hello! Thank you for choosing to help contribute to one of the SendGrid open sou
9
7
  - [Testing](#testing)
10
8
  - [Style Guidelines & Naming Conventions](#style-guidelines-and-naming-conventions)
11
9
  - [Creating a Pull Request](#creating-a-pull-request)
12
-
13
- <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
-
16
- <a name="cla"></a>
17
- ## CLAs and CCLAs
18
-
19
- 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
- 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
- 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
- When you create a Pull Request, after a few seconds, a comment will appear with a link to the CLA. Click the link and fill out the brief form and then click the "I agree" button and you are all set. You will not be asked to re-sign the CLA unless we make a change.
26
-
27
- There are a few ways to contribute, which we'll enumerate below:
10
+ - [Code Reviews](#code-reviews)
28
11
 
29
12
  <a name="feature-request"></a>
30
13
  ## Feature Request
@@ -46,12 +29,12 @@ A software bug is a demonstrable issue in the code base. In order for us to diag
46
29
  Before you decide to create a new issue, please try the following:
47
30
 
48
31
  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
32
+ 2. Update to the latest version of this code and check if the issue has already been fixed
50
33
  3. Copy and fill in the Bug Report Template we have provided below
51
34
 
52
35
  ### Please use our Bug Report Template
53
36
 
54
- In order to make the process easier, we've included a [sample bug report template](https://github.com/sendgrid/ruby-http-client/ISSUE_TEMPLATE.md) (borrowed from [Ghost](https://github.com/TryGhost/Ghost/)). The template uses [GitHub flavored markdown](https://help.github.com/articles/github-flavored-markdown/) for formatting.
37
+ In order to make the process easier, we've included a [sample bug report template](ISSUE_TEMPLATE.md).
55
38
 
56
39
  <a name="improvements-to-the-codebase"></a>
57
40
  ## Improvements to the Codebase
@@ -87,7 +70,7 @@ source ./sendgrid.env
87
70
 
88
71
  ##### Execute: #####
89
72
 
90
- See the [examples folder](https://github.com/sendgrid/ruby-http-client/tree/master/examples) to get started quickly.
73
+ See the [examples folder](examples) to get started quickly.
91
74
 
92
75
  To run the example (after updating the emails):
93
76
 
@@ -104,20 +87,20 @@ Working examples that demonstrate usage.
104
87
 
105
88
  **ruby_http_client.rb**
106
89
 
107
- An HTTP client with a fluent interface using method chaining and reflection. By returning self on [method_missing](https://github.com/sendgrid/ruby-http-client/blob/master/lib/ruby_http_client.rb#L209) and [_()](https://github.com/sendgrid/ruby-http-client/blob/master/lib/ruby_http_client.rb#L194), we can dynamically build the URL using method chaining and [method_missing](https://github.com/sendgrid/ruby-http-client/blob/master/lib/ruby_http_client.rb#L209) allows us to dynamically receive the method calls to achieve reflection.
90
+ An HTTP client with a fluent interface using method chaining and reflection. By returning self on [method_missing](lib/ruby_http_client.rb#L209) and [_()](lib/ruby_http_client.rb#L194), we can dynamically build the URL using method chaining and [method_missing](lib/ruby_http_client.rb#L209) allows us to dynamically receive the method calls to achieve reflection.
108
91
 
109
92
  This allows for the following mapping from a URL to a method chain:
110
93
 
111
- `/api_client/{api_key_id}/version` maps to `client.api_client._(api_key_id).version.<method>()` where <method> is a [HTTP verb](https://github.com/sendgrid/ruby-http-client/blob/master/lib/ruby_http_client.rb#L38).
94
+ `/api_client/{api_key_id}/version` maps to `client.api_client._(api_key_id).version.<method>()` where <method> is a [HTTP verb](lib/ruby_http_client.rb#L38).
112
95
 
113
96
  <a name="testing"></a>
114
97
  ## Testing
115
98
 
116
99
  All PRs require passing tests before the PR will be reviewed.
117
100
 
118
- All test files are in the [`test`](https://github.com/sendgrid/ruby-http-client/tree/master/test) directory.
101
+ All test files are in the [`test`](test) directory.
119
102
 
120
- For the purposes of contributing to this repo, please update the [`test_ruby_http_client.rb`](https://github.com/sendgrid/ruby-http-client/blob/master/test/test_ruby_http_client.rb) file with unit tests as you modify the code.
103
+ For the purposes of contributing to this repo, please update the [`test_ruby_http_client.rb`](test/test_ruby_http_client.rb) file with unit tests as you modify the code.
121
104
 
122
105
  To run the tests:
123
106
 
@@ -166,7 +149,7 @@ Please run your code through:
166
149
 
167
150
  4. Commit your changes in logical chunks. Please adhere to these [git commit
168
151
  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
152
+ or your code is unlikely to be merged into the main project. Use Git's
170
153
  [interactive rebase](https://help.github.com/articles/interactive-rebase)
171
154
  feature to tidy up your commits before making them public.
172
155
 
@@ -189,4 +172,7 @@ Please run your code through:
189
172
  7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/)
190
173
  with a clear title and description against the `development` branch. All tests must be passing before we will review the PR.
191
174
 
192
- If you have any additional questions, please feel free to [email](mailto:dx@sendgrid.com) us or create an issue in this repo.
175
+ <a name="code-reviews"></a>
176
+ ## Code Reviews
177
+
178
+ 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/FIRST_TIMERS.md ADDED
@@ -0,0 +1,79 @@
1
+ # How To Contribute to Twilio SendGrid Repositories via GitHub
2
+ Contributing to the Twilio SendGrid repositories is easy! All you need to do is find an open issue (see the bottom of this page for a list of repositories containing open issues), fix it and submit a pull request. Once you have submitted your pull request, the team can easily review it before it is merged into the repository.
3
+
4
+ To make a pull request, follow these steps:
5
+
6
+ 1. Log into GitHub. If you do not already have a GitHub account, you will have to create one in order to submit a change. Click the Sign up link in the upper right-hand corner to create an account. Enter your username, password, and email address. If you are an employee of Twilio SendGrid, please use your full name with your GitHub account and enter Twilio SendGrid as your company so we can easily identify you.
7
+
8
+ <img src="/static/img/github-sign-up.png" width="800">
9
+
10
+ 2. __[Fork](https://help.github.com/fork-a-repo/)__ the [ruby-http-client](https://github.com/sendgrid/ruby-http-client) repository:
11
+
12
+ <img src="/static/img/github-fork.png" width="800">
13
+
14
+ 3. __Clone__ your fork via the following commands:
15
+
16
+ ```bash
17
+ # Clone your fork of the repo into the current directory
18
+ git clone https://github.com/your_username/ruby-http-client
19
+ # Navigate to the newly cloned directory
20
+ cd ruby-http-client
21
+ # Assign the original repo to a remote called "upstream"
22
+ git remote add upstream https://github.com/sendgrid/ruby-http-client
23
+ ```
24
+
25
+ > Don't forget to replace *your_username* in the URL by your real GitHub username.
26
+
27
+ 4. __Create a new topic branch__ (off the main project development branch) to contain your feature, change, or fix:
28
+
29
+ ```bash
30
+ git checkout -b <topic-branch-name>
31
+ ```
32
+
33
+ 5. __Commit your changes__ in logical chunks.
34
+
35
+ Please adhere to these [git commit message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) or your code is unlikely be merged into the main project. Use Git's [interactive rebase](https://help.github.com/articles/interactive-rebase) feature to tidy up your commits before making them public. Probably you will also have to create tests (if needed) or create or update the example code that demonstrates the functionality of this change to the code.
36
+
37
+ 6. __Locally merge (or rebase)__ the upstream development branch into your topic branch:
38
+
39
+ ```bash
40
+ git pull [--rebase] upstream main
41
+ ```
42
+
43
+ 7. __Push__ your topic branch up to your fork:
44
+
45
+ ```bash
46
+ git push origin <topic-branch-name>
47
+ ```
48
+
49
+ 8. __[Open a Pull Request](https://help.github.com/articles/creating-a-pull-request/#changing-the-branch-range-and-destination-repository/)__ with a clear title and description against the `main` branch. All tests must be passing before we will review the PR.
50
+
51
+ ## Important notice
52
+
53
+ Before creating a pull request, make sure that you respect the repository's constraints regarding contributions. You can find them in the [CONTRIBUTING.md](CONTRIBUTING.md) file.
54
+
55
+ ## Repositories with Open, Easy, Help Wanted, Issue Filters
56
+
57
+ * [Python SDK](https://github.com/sendgrid/sendgrid-python/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
58
+ * [PHP SDK](https://github.com/sendgrid/sendgrid-php/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
59
+ * [C# SDK](https://github.com/sendgrid/sendgrid-csharp/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
60
+ * [Ruby SDK](https://github.com/sendgrid/sendgrid-ruby/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
61
+ * [Node.js SDK](https://github.com/sendgrid/sendgrid-nodejs/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
62
+ * [Java SDK](https://github.com/sendgrid/sendgrid-java/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
63
+ * [Go SDK](https://github.com/sendgrid/sendgrid-go/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
64
+ * [Python SMTPAPI Client](https://github.com/sendgrid/smtpapi-python/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
65
+ * [PHP SMTPAPI Client](https://github.com/sendgrid/smtpapi-php/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
66
+ * [C# SMTPAPI Client](https://github.com/sendgrid/smtpapi-csharp/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
67
+ * [Ruby SMTPAPI Client](https://github.com/sendgrid/smtpapi-ruby/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
68
+ * [Node.js SMTPAPI Client](https://github.com/sendgrid/smtpapi-nodejs/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
69
+ * [Java SMTPAPI Client](https://github.com/sendgrid/smtpapi-java/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
70
+ * [Go SMTPAPI Client](https://github.com/sendgrid/smtpapi-go/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
71
+ * [Python HTTP Client](https://github.com/sendgrid/python-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
72
+ * [PHP HTTP Client](https://github.com/sendgrid/php-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
73
+ * [C# HTTP Client](https://github.com/sendgrid/csharp-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
74
+ * [Java HTTP Client](https://github.com/sendgrid/java-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
75
+ * [Ruby HTTP Client](https://github.com/sendgrid/ruby-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
76
+ * [Go HTTP Client](https://github.com/sendgrid/rest/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
77
+ * [Open API Definition](https://github.com/sendgrid/sendgrid-oai/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
78
+ * [DX Automator](https://github.com/sendgrid/dx-automator/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
79
+ * [Documentation](https://github.com/sendgrid/docs/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
data/ISSUE_TEMPLATE.md CHANGED
@@ -1,5 +1,9 @@
1
1
  <!--
2
2
  If this is a feature request, make sure you search Issues for an existing request before creating a new one!
3
+
4
+ Please utilize the template below to help us resolve your issue.
5
+
6
+ Note that many issues can be resolved by updating to the latest version.
3
7
  -->
4
8
 
5
9
  ### Issue Summary
@@ -21,6 +25,6 @@ A summary of the issue and the environment in which it occurs. If suitable, incl
21
25
  ```
22
26
 
23
27
  ### Technical details:
24
- * ruby-http-client version:
28
+ * ruby-http-client version:
25
29
  * ruby version:
26
30
 
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (C) 2020, Twilio SendGrid, Inc. <help@twilio.com>
3
+ Copyright (C) 2022, Twilio SendGrid, Inc. <help@twilio.com>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/Makefile CHANGED
@@ -1,7 +1,7 @@
1
1
  .PHONY: install test
2
2
 
3
3
  install:
4
- gem install minitest
4
+ gem install bundler:1.14.6; bundle install
5
5
 
6
6
  test:
7
- rake
7
+ rake test
@@ -19,13 +19,13 @@ Closes #2
19
19
  A short description of what this PR does.
20
20
 
21
21
  ### Checklist
22
- - [ ] I acknowledge that all my contributions will be made under the project's license
22
+ - [x] I acknowledge that all my contributions will be made under the project's license
23
23
  - [ ] I have made a material change to the repo (functionality, testing, spelling, grammar)
24
- - [ ] I have read the [Contribution Guidelines](CONTRIBUTING.md) and my PR follows them
24
+ - [ ] I have read the [Contribution Guidelines](https://github.com/sendgrid/ruby-http-client/blob/main/CONTRIBUTING.md) and my PR follows them
25
25
  - [ ] I have titled the PR appropriately
26
- - [ ] I have updated my branch with the master branch
26
+ - [ ] I have updated my branch with the main branch
27
27
  - [ ] I have added tests that prove my fix is effective or that my feature works
28
- - [ ] I have added necessary documentation about the functionality in the appropriate .md file
28
+ - [ ] I have added the necessary documentation about the functionality in the appropriate .md file
29
29
  - [ ] I have added inline documentation to the code I modified
30
30
 
31
- If you have questions, please file a [support ticket](https://twilio.com/help/contact), or create a GitHub Issue in this repository.
31
+ If you have questions, please file a [support ticket](https://support.sendgrid.com), or create a GitHub Issue in this repository.
data/README.md CHANGED
@@ -1,9 +1,8 @@
1
- ![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)
1
+ ![SendGrid Logo](twilio_sendgrid_logo.png)
2
2
 
3
- [![BuildStatus](https://travis-ci.org/sendgrid/ruby-http-client.svg?branch=master)](https://travis-ci.org/sendgrid/ruby-http-client)
4
- [![Email Notifications Badge](https://dx.sendgrid.com/badge/ruby)](https://dx.sendgrid.com/newsletter/ruby)
5
- [![Gem Version](https://badge.fury.io/rb/sendgrid-ruby.svg)](https://badge.fury.io/rb/sendgrid-ruby)
6
- [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE.md)
3
+ [![BuildStatus](https://travis-ci.com/sendgrid/ruby-http-client.svg?branch=main)](https://travis-ci.com/sendgrid/ruby-http-client)
4
+ [![Gem Version](https://badge.fury.io/rb/ruby_http_client.svg)](https://badge.fury.io/rb/ruby_http_client)
5
+ [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
7
6
  [![Twitter Follow](https://img.shields.io/twitter/follow/sendgrid.svg?style=social&label=Follow)](https://twitter.com/sendgrid)
8
7
  [![GitHub contributors](https://img.shields.io/github/contributors/sendgrid/ruby-http-client.svg)](https://github.com/sendgrid/ruby-http-client/graphs/contributors)
9
8
 
@@ -12,15 +11,14 @@
12
11
  If you are looking for the SendGrid API client library, please see [this repo](https://github.com/sendgrid/sendgrid-ruby).
13
12
 
14
13
  # 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 :)
14
+ **The default branch name for this repository has been changed to `main` as of 07/27/2020.**
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](CHANGELOG.md).
18
17
 
19
18
  # Table of Contents
20
19
  - [Installation](#installation)
21
20
  - [Quick Start](#quick-start)
22
21
  - [Usage](#usage)
23
- - [Roadmap](#roadmap)
24
22
  - [How to Contribute](#contribute)
25
23
  - [About](#about)
26
24
  - [License](#license)
@@ -30,7 +28,7 @@ All updates to this library is documented in our [CHANGELOG](https://github.com/
30
28
 
31
29
  ## Prerequisites
32
30
 
33
- - Ruby version 2.2+
31
+ - Ruby version >= 2.4
34
32
 
35
33
  ## Setup Environment Variables
36
34
 
@@ -57,7 +55,7 @@ gem install ruby_http_client
57
55
 
58
56
  ```ruby
59
57
  require 'ruby_http_client'
60
- global_headers = {'Authorization' => 'Basic XXXXXXX' }
58
+ global_headers = {'Authorization' => 'Bearer XXXXXXX' }
61
59
  client = SendGrid::Client.new(host: 'base_url', request_headers: global_headers)
62
60
  client.your.api._(param).call.get
63
61
  puts response.status_code
@@ -69,7 +67,7 @@ puts response.headers
69
67
 
70
68
  ```ruby
71
69
  require 'ruby_http_client'
72
- global_headers = {'Authorization' => 'Basic XXXXXXX' }
70
+ global_headers = {'Authorization' => 'Bearer XXXXXXX' }
73
71
  client = SendGrid::Client.new(host: 'base_url', request_headers: global_headers)
74
72
  query_params = { 'hello' => 0, 'world' => 1 }
75
73
  request_headers = { 'X-Test' => 'test' }
@@ -85,31 +83,28 @@ puts response.headers
85
83
  <a name="usage"></a>
86
84
  # Usage
87
85
 
88
- - [Example Code](https://github.com/sendgrid/ruby-http-client/tree/master/examples)
89
-
90
- <a name="roadmap"></a>
91
- # Roadmap
92
-
93
- If you are interested in the future direction of this project, please take a look at our [milestones](https://github.com/sendgrid/ruby-http-client/milestones). We would love to hear your feedback.
86
+ - [Example Code](examples)
94
87
 
95
88
  <a name="contribute"></a>
96
89
  # How to Contribute
97
90
 
98
- We encourage contribution to our libraries, please see our [CONTRIBUTING](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md) guide for details.
91
+ We encourage contribution to our libraries, please see our [CONTRIBUTING](CONTRIBUTING.md) guide for details.
99
92
 
100
93
  Quick links:
101
94
 
102
- - [Feature Request](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md#feature-request)
103
- - [Bug Reports](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md#submit-a-bug-report)
104
- - [Sign the CLA to Create a Pull Request](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md)
105
- - [Improvements to the Codebase](https://github.com/sendgrid/ruby-http-client/blob/master/CONTRIBUTING.md#improvements-to-the-codebase)
95
+ - [Feature Request](CONTRIBUTING.md#feature-request)
96
+ - [Bug Reports](CONTRIBUTING.md#submit-a-bug-report)
97
+ - [Improvements to the Codebase](CONTRIBUTING.md#improvements-to-the-codebase)
98
+ - [Review Pull Requests](CONTRIBUTING.md#code-reviews)
106
99
 
107
100
  <a name="about"></a>
108
101
  # About
109
102
 
110
- ruby-http-client is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com).
103
+ ruby-http-client is maintained and funded by Twilio SendGrid, Inc. The names and logos for ruby-http-client are trademarks of Twilio SendGrid, Inc.
104
+
105
+ If you need help installing or using the library, please check the [Twilio SendGrid Support Help Center](https://support.sendgrid.com).
111
106
 
112
- ruby-http-client is maintained and funded by SendGrid, Inc. The names and logos for ruby-http-client are trademarks of SendGrid, Inc.
107
+ If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!
113
108
 
114
109
  # License
115
- [The MIT License (MIT)](LICENSE.md)
110
+ [The MIT License (MIT)](LICENSE)
data/TROUBLESHOOTING.md CHANGED
@@ -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
 
data/examples/example.rb CHANGED
@@ -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!
@@ -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
 
@@ -188,7 +227,9 @@ module SendGrid
188
227
  def build_http(host, port)
189
228
  params = [host, port]
190
229
  params += @proxy_options.values_at(:host, :port, :user, :pass) unless @proxy_options.empty?
191
- add_ssl(Net::HTTP.new(*params))
230
+ http = add_ssl(Net::HTTP.new(*params))
231
+ http = add_http_options(http) unless @http_options.empty?
232
+ http
192
233
  end
193
234
 
194
235
  # Allow for https calls
@@ -206,6 +247,20 @@ module SendGrid
206
247
  http
207
248
  end
208
249
 
250
+ # Add others http options to http object
251
+ #
252
+ # * *Args* :
253
+ # - +http+ -> HTTP::NET object
254
+ # * *Returns* :
255
+ # - HTTP::NET object
256
+ #
257
+ def add_http_options(http)
258
+ @http_options.each do |attribute, value|
259
+ http.send("#{attribute}=", value)
260
+ end
261
+ http
262
+ end
263
+
209
264
  # Add variable values to the url.
210
265
  # (e.g. /your/api/{variable_value}/call)
211
266
  # Another example: if you have a ruby reserved word, such as true,
@@ -227,7 +282,7 @@ module SendGrid
227
282
  # (e.g. client.name.name.get())
228
283
  #
229
284
  # * *Args* :
230
- # - The args are autmoatically passed in
285
+ # - The args are automatically passed in
231
286
  # * *Returns* :
232
287
  # - Client object or Response object
233
288
  #
@@ -245,6 +300,37 @@ module SendGrid
245
300
  # Add a segment to the URL
246
301
  _(name)
247
302
  end
303
+
304
+ private
305
+
306
+ def build_http_request(http_method)
307
+ uri = build_url(query_params: @query_params)
308
+ net_http = Kernel.const_get('Net::HTTP::' + http_method.to_s.capitalize)
309
+
310
+ @http = build_http(uri.host, uri.port)
311
+ @request = build_request_headers(net_http.new(uri.request_uri))
312
+ end
313
+
314
+ def update_content_type(http_method)
315
+ if @request_body && content_type_json?
316
+ # If body is a hash or array, encode it; else leave it alone
317
+ @request.body = if [Hash, Array].include?(@request_body.class)
318
+ @request_body.to_json
319
+ else
320
+ @request_body
321
+ end
322
+ @request['Content-Type'] = 'application/json'
323
+ elsif !@request_body && http_method.to_s == 'post'
324
+ @request['Content-Type'] = ''
325
+ else
326
+ @request.body = @request_body
327
+ end
328
+ end
329
+
330
+ def content_type_json?
331
+ !@request_headers.key?('Content-Type') ||
332
+ @request_headers['Content-Type'] == 'application/json'
333
+ end
248
334
  # rubocop:enable Style/MethodMissingSuper
249
335
  # rubocop:enable Style/MissingRespondToMissing
250
336
  end
@@ -3,9 +3,9 @@ $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.3'
7
7
  spec.authors = ['Elmer Thomas']
8
- spec.email = 'dx@sendgrid.com'
8
+ spec.email = 'help@twilio.com'
9
9
  spec.summary = 'A simple REST client'
10
10
  spec.description = 'Quickly and easily access any REST or REST-like API.'
11
11
  spec.homepage = 'http://github.com/sendgrid/ruby-http-client'
@@ -15,8 +15,9 @@ 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
- spec.add_development_dependency 'rubocop'
21
- spec.add_development_dependency 'simplecov'
21
+ spec.add_development_dependency 'rubocop', '~> 0.88.0'
22
+ spec.add_development_dependency 'simplecov', '~> 0.18.5'
22
23
  end
Binary file
Binary file
data/test/test_helper.rb CHANGED
@@ -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'
@@ -227,11 +253,47 @@ class TestClient < Minitest::Test
227
253
  assert_equal(http.verify_mode, OpenSSL::SSL::VERIFY_PEER)
228
254
  end
229
255
 
256
+ def test_add_http_options
257
+ uri = URI.parse('https://localhost:4010')
258
+ http = Net::HTTP.new(uri.host, uri.port)
259
+ http = @client_with_options.add_http_options(http)
260
+ assert_equal(http.open_timeout, 60)
261
+ assert_equal(http.read_timeout, 60)
262
+ end
263
+
230
264
  def test__
231
265
  url1 = @client._('test')
232
266
  assert_equal(['test'], url1.url_path)
233
267
  end
234
268
 
269
+ def test_ratelimit_core
270
+ expiry = Time.now.to_i + 1
271
+ rl = SendGrid::Response::Ratelimit.new(500, 100, expiry)
272
+ rl2 = SendGrid::Response::Ratelimit.new(500, 0, expiry)
273
+
274
+ refute rl.exceeded?
275
+ assert rl2.exceeded?
276
+
277
+ assert_equal(rl.used, 400)
278
+ assert_equal(rl2.used, 500)
279
+ end
280
+
281
+ def test_response_ratelimit_parsing
282
+ headers = {
283
+ 'X-RateLimit-Limit' => '500',
284
+ 'X-RateLimit-Remaining' => '300',
285
+ 'X-RateLimit-Reset' => Time.now.to_i.to_s
286
+ }
287
+
288
+ body = ''
289
+ code = 204
290
+ http_response = MockHttpResponse.new(code, body, headers)
291
+ response = SendGrid::Response.new(http_response)
292
+
293
+ refute_nil response.ratelimit
294
+ refute response.ratelimit.exceeded?
295
+ end
296
+
235
297
  def test_method_missing
236
298
  response = @client.get
237
299
  assert_equal(200, response.status_code)
@@ -319,7 +381,7 @@ class TestClient < Minitest::Test
319
381
  end
320
382
 
321
383
  def test_license_exists
322
- assert(File.file?('./LICENSE.md') || File.file?('./LICENSE.txt'))
384
+ assert(File.file?('./LICENSE'))
323
385
  end
324
386
 
325
387
  def test_pull_request_template_exists
@@ -339,7 +401,7 @@ class TestClient < Minitest::Test
339
401
  end
340
402
 
341
403
  def test_license_date_is_updated
342
- license_end_year = IO.read('LICENSE.md').match(/Copyright \(C\) (\d{4}), Twilio SendGrid/)[1].to_i
404
+ license_end_year = IO.read('LICENSE').match(/Copyright \(C\) (\d{4}), Twilio SendGrid/)[1].to_i
343
405
  current_year = Time.new.year
344
406
  assert_equal(current_year, license_end_year)
345
407
  end
Binary file
metadata CHANGED
@@ -1,17 +1,17 @@
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.3
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: 2022-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: minitest
14
+ name: codecov
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rubocop
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -52,37 +52,53 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.88.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.88.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: simplecov
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ">="
73
+ - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '0'
75
+ version: 0.18.5
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ">="
80
+ - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '0'
82
+ version: 0.18.5
69
83
  description: Quickly and easily access any REST or REST-like API.
70
- email: dx@sendgrid.com
84
+ email: help@twilio.com
71
85
  executables: []
72
86
  extensions: []
73
87
  extra_rdoc_files: []
74
88
  files:
75
89
  - ".codeclimate.yml"
76
90
  - ".env_sample"
91
+ - ".github/ISSUE_TEMPLATE/config.yml"
77
92
  - ".gitignore"
78
93
  - ".rubocop.yml"
79
94
  - ".travis.yml"
80
95
  - CHANGELOG.md
81
96
  - CODE_OF_CONDUCT.md
82
97
  - CONTRIBUTING.md
98
+ - FIRST_TIMERS.md
83
99
  - Gemfile
84
100
  - ISSUE_TEMPLATE.md
85
- - LICENSE.md
101
+ - LICENSE
86
102
  - Makefile
87
103
  - PULL_REQUEST_TEMPLATE.md
88
104
  - README.md
@@ -90,11 +106,13 @@ files:
90
106
  - TROUBLESHOOTING.md
91
107
  - USAGE.md
92
108
  - examples/example.rb
93
- - first-timers.md
94
109
  - lib/ruby_http_client.rb
95
110
  - ruby_http_client.gemspec
111
+ - static/img/github-fork.png
112
+ - static/img/github-sign-up.png
96
113
  - test/test_helper.rb
97
114
  - test/test_ruby_http_client.rb
115
+ - twilio_sendgrid_logo.png
98
116
  - use_cases/README.md
99
117
  homepage: http://github.com/sendgrid/ruby-http-client
100
118
  licenses:
@@ -115,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
133
  - !ruby/object:Gem::Version
116
134
  version: '0'
117
135
  requirements: []
118
- rubygems_version: 3.0.6
136
+ rubygems_version: 3.0.8
119
137
  signing_key:
120
138
  specification_version: 4
121
139
  summary: A simple REST client
data/first-timers.md DELETED
@@ -1,70 +0,0 @@
1
- # How To Contribute to ruby-http-client for first-timers
2
-
3
- We know that contributing to an open source project for the first time can be intimidating.
4
-
5
- This documentation serves to guide you on how to make your first contribution.
6
-
7
- Assuming you already have a [Github account](https://github.com/join), here are the steps to make your first contribution:
8
-
9
- ## Finding a task you can handle
10
-
11
- We label our issues according to their difficulty level. You can find easy ones [here](https://github.com/sendgrid/ruby-http-client/issues?q=is%3Aopen+is%3Aissue+label%3A%22difficulty%3A+easy%22) but feel free to explore other labels too.
12
-
13
- - [Medium labeled issues](https://github.com/sendgrid/ruby-http-client/issues?q=is%3Aopen+is%3Aissue+label%3A%22difficulty%3A+medium%22)
14
- - [Hard labeled issues](https://github.com/sendgrid/ruby-http-client/issues?q=is%3Aopen+is%3Aissue+label%3A%22difficulty%3A+hard%22)
15
-
16
-
17
- ## Creating a Pull Request<a name="creating-a-pull-request"></a>
18
-
19
- 1. [Fork](https://help.github.com/fork-a-repo/) the project, clone your fork,
20
- and configure the remotes:
21
-
22
- ```bash
23
- # Clone your fork of the repo into the current directory
24
- git clone https://github.com/sendgrid/ruby-http-client
25
- # Navigate to the newly cloned directory
26
- cd ruby-http-client
27
- # Assign the original repo to a remote called "upstream"
28
- git remote add upstream https://github.com/sendgrid/ruby-http-client
29
- ```
30
-
31
- 2. If you cloned a while ago, get the latest changes from upstream:
32
-
33
- ```bash
34
- git checkout <dev-branch>
35
- git pull upstream <dev-branch>
36
- ```
37
-
38
- 3. Create a new topic branch (off the main project development branch) to
39
- contain your feature, change, or fix:
40
-
41
- ```bash
42
- git checkout -b <topic-branch-name>
43
- ```
44
-
45
- 4. Commit your changes in logical chunks. Please adhere to these [git commit
46
- message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
47
- or your code is unlikely be merged into the main project. Use Git's
48
- [interactive rebase](https://help.github.com/articles/interactive-rebase)
49
- feature to tidy up your commits before making them public.
50
-
51
- 4a. Create tests.
52
-
53
- 4b. Create or update the example code that demonstrates the functionality of this change to the code.
54
-
55
- 5. Locally merge (or rebase) the upstream development branch into your topic branch:
56
-
57
- ```bash
58
- git pull [--rebase] upstream master
59
- ```
60
-
61
- 6. Push your topic branch up to your fork:
62
-
63
- ```bash
64
- git push origin <topic-branch-name>
65
- ```
66
-
67
- 7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/)
68
- with a clear title and description against the `master` branch. All tests must be passing before we will review the PR.
69
-
70
- If you have any additional questions, please feel free to [email](mailto:dx@sendgrid.com) us or create an issue in this repo.