ruby_http_client 3.3.0 → 3.4.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
- SHA1:
3
- metadata.gz: f96204e110fa9585143ab6df25e1f452ac13a264
4
- data.tar.gz: e61b148893688c666f487682a93693b08e32a276
2
+ SHA256:
3
+ metadata.gz: a76e3392d677cadaf41d419bdec64bafc4ddda722b1c805171cec97ff27767da
4
+ data.tar.gz: 101c510d5c659e4108073466b6c963b54405fb770ccecd4f398c0b3328c9fd56
5
5
  SHA512:
6
- metadata.gz: fd090f25ab9ef5fc013feeb1e78d955d749c78de5a78b062e3672b8d9fbdb5fecd0a2be6ce9740b99513d8155099ee1911fde3125ce398da9e9652cbbc51eeee
7
- data.tar.gz: 17e37ac97e6b926f85e2ad97acdd72a6afb0f1ef533c114f0b74be513452da60ffa1fcaf5a571c443e0b757adec692e04438f9d79153b0f69cefe26857020293
6
+ metadata.gz: be8d8d553070cde4f609c23a8b24392c92260dc01146391f60e0cb095d620f4b8d7ca013283d8384150b0729ce61902972e9072c82ae9e67fcbaaddd57594406
7
+ data.tar.gz: e29ca74e02e911742d5d3af6e4ee537d78033e71ee4764762c8f092c76955bff5f377fa8b77070bf3c2bd73ee26578cbd04db0bdb1dd807567122bc17b5c0198
@@ -0,0 +1 @@
1
+ export SENDGRID_API_KEY=''
@@ -12,7 +12,7 @@ Closes #2
12
12
  ### Checklist
13
13
  - [ ] I have made a material change to the repo (functionality, testing, spelling, grammar)
14
14
  - [ ] I have read the [Contribution Guide] and my PR follows them.
15
- - [ ] I updated my branch with the master branch.
15
+ - [ ] I updated my branch with the development branch.
16
16
  - [ ] I have added tests that prove my fix is effective or that my feature works
17
17
  - [ ] I have added necessary documentation about the functionality in the appropriate .md file
18
18
  - [ ] I have added in line documentation to the code I modified
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  bin
2
+ vendor/*
2
3
  *.gem
3
4
  *.rbc
4
5
  /.config
@@ -0,0 +1,47 @@
1
+ AllCops:
2
+ Exclude:
3
+ - bin/**/*
4
+ - script/**/*
5
+ - vendor/**/*
6
+ - cookbooks/**/*
7
+
8
+ ClassLength:
9
+ Enabled: false
10
+ CyclomaticComplexity:
11
+ Enabled: false
12
+ Documentation:
13
+ Enabled: false
14
+ Encoding:
15
+ Enabled: false
16
+ LineLength:
17
+ Enabled: false
18
+ MethodLength:
19
+ Enabled: false
20
+ Metrics/AbcSize:
21
+ Enabled: false
22
+ Metrics/ModuleLength:
23
+ Enabled: false
24
+ PerceivedComplexity:
25
+ Enabled: false
26
+ Style/SpaceBeforeFirstArg:
27
+ Enabled: true
28
+ Style/ClassAndModuleChildren:
29
+ Enabled: false
30
+ Style/EmptyLinesAroundBlockBody:
31
+ Enabled: true
32
+ Style/FileName:
33
+ Enabled: true
34
+ Style/RescueModifier:
35
+ Enabled: true
36
+ Style/StringLiterals:
37
+ Enabled: true
38
+ Metrics/BlockLength:
39
+ Enabled: false
40
+ Style/NumericLiterals:
41
+ Enabled: false
42
+ Style/ExtraSpacing:
43
+ Enabled: true
44
+ AllowForAlignment: false
45
+ ForceEqualSignAlignment: false
46
+ Style/FrozenStringLiteralComment:
47
+ Enabled: false
@@ -1,17 +1,46 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=$CC_TEST_REPORTER_ID
4
+
1
5
  language: ruby
2
6
  rvm:
3
- - 2.2
7
+ - ruby-head
8
+ - 2.6
9
+ - 2.5
10
+ - 2.4
11
+ - jruby
12
+
4
13
  before_install:
5
14
  - gem install minitest
15
+ - gem install simplecov
16
+
6
17
  notifications:
7
18
  hipchat:
8
19
  rooms:
9
20
  secure: S0K355wxCRxwK2cOmbcVOaQitRtIEIq0OEEW7JZp8XtooupGwpmJSm22gqeo7GR6eidqlV8Tp6SUffpLE6SvS0hed3LDbJw7oWoXA7XvRp7gh/AKvLZ0e2uz/a1WPSYy0gNS3TJ72PcyoMS6rPCKR0FyDu8mQ2sW8CpZG07NDCmJPgO+dKfnpeuEmElZoh0AZxE6u1RjvUdSzxnmCVjve621ghtMaKInd0fnNPOM6tm9L0HKSbaLI/buphYhQ/DLpO+dLvt7W2yN+9BwaGqPv7X04Sn0UVAu9+EjSouLLBVNRIsdUfgRGeooStm8/Iw0c1brY4goyYJxGs0TiPkfPeWJcNmQ68YSZLDhUGoMZWCZwGq0Lm/oThJX8K777r3qt0Td4iAXNG+bVN+1KZtZRra6B/qBKBcpTTs1p4WRfIUY9D6udwyWZMcGEOFecsyt/MRlkjdmu+zSvZsadvhvQCL+m+aUmTtlUbswXu46g5NxQrHS9UKzzPkk/3mUrO1r4HLhhuuNtn3LRMbx9WVMdidMiFaAxG99VFC0Gon//FMvpTShNrRRuNSW7EJ0V8gwpx69SticfxC88pfka/MEeY9KoZc3MJdILbpgLK5oPuFMih2F/emJP1muWnk8mjaEHqHPqnSuKRr4oqO1xbh+r2ggKW58akCe08a4TihD4rg=
10
21
  template:
11
- - '<a href="https://travis-ci.org/%{repository}/builds/%{build_id}">%{repository}
12
- Build %{build_number}</a> on branch <i>%{branch}</i> by %{author}: <strong>%{message}</strong>
13
- <a href="https://github.com/sendgrid/%{repository}/commits/%{commit}">View on GitHub</a>'
22
+ - '<a href="https://travis-ci.org/%{repository}/builds/%{build_id}">%{repository}
23
+ Build %{build_number}</a> on branch <i>%{branch}</i> by %{author}: <strong>%{message}</strong>
24
+ <a href="https://github.com/sendgrid/%{repository}/commits/%{commit}">View on GitHub</a>'
14
25
  format: html
15
26
  notify: false
27
+
28
+ before_script:
29
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
30
+ - chmod +x ./cc-test-reporter
31
+ - ./cc-test-reporter before-build
32
+
16
33
  script:
17
- - rake
34
+ - rake
35
+
36
+ after_script:
37
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
38
+
39
+ deploy:
40
+ provider: rubygems
41
+ api_key:
42
+ secure: CWlfN170i/fHPrIufHHLWQ0utjuhxf4ELSxKeypIuO2CNTqNMzocDAa2vxMt4XfO6d2wFPV/LC+IHR7i+sp7PKvjRoa4BLUUxjfBNDboc0gGESeUYlAxwsJo0tOVCNmpxgjQKqtPLz/19A/v/xpxLv2Im/9Idqa5ATd06sMDdM8=
43
+ gem: ruby-http-client
44
+ on:
45
+ tags: true
46
+ rvm: '2.4'
@@ -3,7 +3,42 @@ 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
- ## [3.3.0] - 2017-10-30
6
+ [2020-01-09] Version 3.4.0
7
+ --------------------------
8
+ **Library - Fix**
9
+ - [PR #108](https://github.com/sendgrid/ruby-http-client/pull/108): Avoid mutating @url_path to avoid unexpected side effects. Thanks to [@tachyons](https://github.com/tachyons)!
10
+ - [PR #49](https://github.com/sendgrid/ruby-http-client/pull/49): change year for the license file. Thanks to [@luiscobits](https://github.com/luiscobits)!
11
+ - [PR #48](https://github.com/sendgrid/ruby-http-client/pull/48): update LICENSE - fix year. Thanks to [@pushkyn](https://github.com/pushkyn)!
12
+
13
+ **Library - Docs**
14
+ - [PR #105](https://github.com/sendgrid/ruby-http-client/pull/105): Add our Developer Experience Engineer career opportunity to the READM…. Thanks to [@mptap](https://github.com/mptap)!
15
+ - [PR #61](https://github.com/sendgrid/ruby-http-client/pull/61): update CONTRIBUTING.md. Thanks to [@thepriefy](https://github.com/thepriefy)!
16
+ - [PR #86](https://github.com/sendgrid/ruby-http-client/pull/86): Add first time contributor documentation. Thanks to [@eyewritecode](https://github.com/eyewritecode)!
17
+ - [PR #91](https://github.com/sendgrid/ruby-http-client/pull/91): update contribution to branch off development. Thanks to [@vikasnautiyal](https://github.com/vikasnautiyal)!
18
+ - [PR #72](https://github.com/sendgrid/ruby-http-client/pull/72): Add USAGE.md. Thanks to [@ProZsolt](https://github.com/ProZsolt)!
19
+ - [PR #73](https://github.com/sendgrid/ruby-http-client/pull/73): Create a Use Cases Directory. Thanks to [@ProZsolt](https://github.com/ProZsolt)!
20
+ - [PR #41](https://github.com/sendgrid/ruby-http-client/pull/41): Create PULL_REQUEST_TEMPLATE.md. Thanks to [@flaredragon](https://github.com/flaredragon)!
21
+
22
+ **Library - Chore**
23
+ - [PR #80](https://github.com/sendgrid/ruby-http-client/pull/80): Missing Dev Dependencies + rubocop #79. Thanks to [@kplimack](https://github.com/kplimack)!
24
+ - [PR #66](https://github.com/sendgrid/ruby-http-client/pull/66): delete PULL_REQUEST_TEMPLATE.md. Thanks to [@thepriefy](https://github.com/thepriefy)!
25
+ - [PR #76](https://github.com/sendgrid/ruby-http-client/pull/76): Add Gemfile. Thanks to [@kplimack](https://github.com/kplimack)!
26
+ - [PR #58](https://github.com/sendgrid/ruby-http-client/pull/58): [Closes #55] Add code coverage reporting to CC. Thanks to [@lauratpa](https://github.com/lauratpa)!
27
+ - [PR #57](https://github.com/sendgrid/ruby-http-client/pull/57): [Closes #56] Fix some rubocop issues. Thanks to [@lauratpa](https://github.com/lauratpa)!
28
+ - [PR #50](https://github.com/sendgrid/ruby-http-client/pull/50): Added unittest to check for specific repo files. Thanks to [@mptap](https://github.com/mptap)!
29
+ - [PR #51](https://github.com/sendgrid/ruby-http-client/pull/51): Add License end year test. Thanks to [@diegous](https://github.com/diegous)!
30
+ - [PR #39](https://github.com/sendgrid/ruby-http-client/pull/39): Add a .env_sample file. Thanks to [@thepriefy](https://github.com/thepriefy)!
31
+ - [PR #112](https://github.com/sendgrid/ruby-http-client/pull/112): Auto-deploy upon successful tagged commit. Thanks to [@thinkingserious](https://github.com/thinkingserious)!
32
+ - [PR #111](https://github.com/sendgrid/ruby-http-client/pull/111): Update CHANGELOG heading format for automation. Thanks to [@thinkingserious](https://github.com/thinkingserious)!
33
+ - [PR #110](https://github.com/sendgrid/ruby-http-client/pull/110): Add Makefile for Librarian automation. Thanks to [@thinkingserious](https://github.com/thinkingserious)!
34
+
35
+ **Library - Feature**
36
+ - [PR #75](https://github.com/sendgrid/ruby-http-client/pull/75): Add ability to set proxy. Thanks to [@eitoball](https://github.com/eitoball)!
37
+ - [PR #20](https://github.com/sendgrid/ruby-http-client/pull/20): Add option to set http attributes when creating an instance of Client. Thanks to [@jrectenwald](https://github.com/jrectenwald)!
38
+
39
+
40
+ [2017-10-30] Version 3.3.0
41
+ --------------------------
7
42
  ## Added
8
43
  - #11 fix: Allow for multiple values for a parameter
9
44
  - Thanks to [xiaoboa](https://github.com/xiaoboa) for the pull request!
@@ -73,11 +73,7 @@ git clone https://github.com/sendgrid/ruby-http-client.git
73
73
  cd ruby-http-client
74
74
  ```
75
75
 
76
- ##### Execute: #####
77
-
78
- See the [examples folder](https://github.com/sendgrid/ruby-http-client/tree/master/examples) to get started quickly.
79
-
80
- To try the SendGrid example:
76
+ ### Environment Variables
81
77
 
82
78
  First, get your free SendGrid account [here](https://sendgrid.com/free?source=ruby-http-client).
83
79
 
@@ -89,6 +85,10 @@ echo "sendgrid.env" >> .gitignore
89
85
  source ./sendgrid.env
90
86
  ```
91
87
 
88
+ ##### Execute: #####
89
+
90
+ See the [examples folder](https://github.com/sendgrid/ruby-http-client/tree/master/examples) to get started quickly.
91
+
92
92
  To run the example (after updating the emails):
93
93
 
94
94
  ```bash
@@ -130,8 +130,6 @@ rake
130
130
 
131
131
  Generally, we follow the style guidelines as suggested by the official language. However, we ask that you conform to the styles that already exist in the library. If you wish to deviate, please explain your reasoning.
132
132
 
133
- Generally, we follow the style guidelines as suggested by the official language. However, we ask that you conform to the styles that already exist in the library. If you wish to deviate, please explain your reasoning.
134
-
135
133
  - [Community Driven Style Guide](https://github.com/bbatsov/ruby-style-guide)
136
134
 
137
135
  Please run your code through:
@@ -159,7 +157,7 @@ Please run your code through:
159
157
  git pull upstream <dev-branch>
160
158
  ```
161
159
 
162
- 3. Create a new topic branch (off the main project development branch) to
160
+ 3. Create a new topic branch off the `development` branch to
163
161
  contain your feature, change, or fix:
164
162
 
165
163
  ```bash
@@ -179,7 +177,7 @@ Please run your code through:
179
177
  5. Locally merge (or rebase) the upstream development branch into your topic branch:
180
178
 
181
179
  ```bash
182
- git pull [--rebase] upstream master
180
+ git pull [--rebase] upstream development
183
181
  ```
184
182
 
185
183
  6. Push your topic branch up to your fork:
@@ -189,6 +187,6 @@ Please run your code through:
189
187
  ```
190
188
 
191
189
  7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/)
192
- with a clear title and description against the `master` branch. All tests must be passing before we will review the PR.
190
+ with a clear title and description against the `development` branch. All tests must be passing before we will review the PR.
193
191
 
194
192
  If you have any additional questions, please feel free to [email](mailto:dx@sendgrid.com) us or create an issue in this repo.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016-2017 SendGrid, Inc.
3
+ Copyright (c) 2016-2020 Twilio SendGrid, Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,7 @@
1
+ .PHONY: install test
2
+
3
+ install:
4
+ gem install minitest
5
+
6
+ test:
7
+ rake
data/README.md CHANGED
@@ -12,6 +12,7 @@
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 :)
15
16
 
16
17
  All updates to this library is documented in our [CHANGELOG](https://github.com/sendgrid/ruby-http-client/blob/master/CHANGELOG.md).
17
18
 
@@ -31,6 +32,18 @@ All updates to this library is documented in our [CHANGELOG](https://github.com/
31
32
 
32
33
  - Ruby version 2.2+
33
34
 
35
+ ## Setup Environment Variables
36
+
37
+ ### Environment Variable
38
+
39
+ Update the development environment with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys), for example:
40
+
41
+ ```bash
42
+ echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
43
+ echo "sendgrid.env" >> .gitignore
44
+ source ./sendgrid.env
45
+ ```
46
+
34
47
  ## Install Package
35
48
 
36
49
  ```bash
data/Rakefile CHANGED
@@ -4,5 +4,28 @@ Rake::TestTask.new do |t|
4
4
  t.libs << 'test'
5
5
  end
6
6
 
7
- desc "Run tests"
8
- task :default => :test
7
+ desc 'run rubocop'
8
+ task :rubocop do
9
+ sh 'rubocop -c .rubocop.yml --display-only-fail-level-offenses -D'
10
+ end
11
+
12
+ desc 'run rubocop w/autocorrect'
13
+ task :rubocorrect do
14
+ sh 'rubocop -c .rubocop.yml -a'
15
+ end
16
+
17
+ desc 'run minitest'
18
+ task :minitest do
19
+ Rake::Task[:test].invoke
20
+ end
21
+
22
+ desc 'Run tests'
23
+ task default: 'test:quick'
24
+
25
+ namespace :test do
26
+ desc 'Run all the quick tests'
27
+ task :quick do
28
+ Rake::Task['rubocop'].invoke
29
+ Rake::Task['minitest'].invoke
30
+ end
31
+ end
@@ -0,0 +1,108 @@
1
+ # Usage
2
+
3
+ Usage examples for SendGrid ruby-http-client
4
+
5
+ ## Initialization
6
+
7
+ ```ruby
8
+ require_relative '../lib/ruby_http_client'
9
+
10
+ # This uses the SendGrid API as an example
11
+ headers = JSON.parse('
12
+ {
13
+ "Authorization": "Bearer ' + ENV['SENDGRID_API_KEY'] + '"
14
+ }
15
+ ')
16
+ host = 'https://api.sendgrid.com'
17
+ client = SendGrid::Client.new(host: host, request_headers: headers)
18
+ ```
19
+
20
+ ## Table of Contents
21
+
22
+ - [GET](#get)
23
+ - [DELETE](#delete)
24
+ - [POST](#post)
25
+ - [PUT](#put)
26
+ - [PATCH](#patch)
27
+
28
+ ## GET
29
+
30
+ #### GET Collection
31
+
32
+ ```ruby
33
+ query_params = { 'limit' => 100, 'offset' => 0 }
34
+ response = client.version('v3').api_keys.get(query_params: query_params)
35
+ puts response.status_code
36
+ puts response.body
37
+ puts response.headers
38
+ ```
39
+
40
+ #### GET Single
41
+
42
+ ```ruby
43
+ response = client.version('v3').api_keys._(api_key_id).get
44
+ puts response.status_code
45
+ puts response.body
46
+ puts response.headers
47
+ ```
48
+
49
+ ## DELETE
50
+
51
+ ```ruby
52
+ response = client.api_keys._(api_key_id).delete
53
+ puts response.status_code
54
+ puts response.headers
55
+ ```
56
+
57
+ ## POST
58
+
59
+ ```ruby
60
+ request_body = JSON.parse('
61
+ {
62
+ "name": "My API Key Ruby Test",
63
+ "scopes": [
64
+ "mail.send",
65
+ "alerts.create",
66
+ "alerts.read"
67
+ ]
68
+ }
69
+ ')
70
+ response = client.version('v3').api_keys.post(request_body: request_body)
71
+ puts response.status_code
72
+ puts response.body
73
+ puts response.headers
74
+ api_key_id = JSON.parse(response.body)['api_key_id']
75
+ ```
76
+
77
+ ## PUT
78
+
79
+ ```ruby
80
+ request_body = JSON.parse('
81
+ {
82
+ "name": "A New Hope",
83
+ "scopes": [
84
+ "user.profile.read",
85
+ "user.profile.update"
86
+ ]
87
+ }
88
+ ')
89
+
90
+ response = client.api_keys._(api_key_id).put(request_body: request_body)
91
+ puts response.status_code
92
+ puts response.body
93
+ puts response.headers
94
+ ```
95
+
96
+ ## PATCH
97
+
98
+ ```ruby
99
+ request_body = JSON.parse('
100
+ {
101
+ "name": "A New Hope"
102
+ }
103
+ ')
104
+ response = client.api_keys._(api_key_id).patch(request_body: request_body)
105
+ puts response.status_code
106
+ puts response.body
107
+ puts response.headers
108
+ ```
@@ -6,9 +6,28 @@ headers = JSON.parse('
6
6
  "Authorization": "Bearer ' + ENV['SENDGRID_API_KEY'] + '"
7
7
  }
8
8
  ')
9
- host = 'https://api.sendgrid.com'
9
+ host = 'https://api.sendgrid.com'
10
10
  client = SendGrid::Client.new(host: host, request_headers: headers)
11
11
 
12
+ # You can pass in an http_options hash to set values for NET::HTTP attributes
13
+ # https://ruby-doc.org/stdlib-2.4.1/libdoc/net/http/rdoc/Net/HTTP.html
14
+ # client = SendGrid::Client.new(host: host,
15
+ # request_headers: headers,
16
+ # http_options: {open_timeout: 15, read_timeout: 30})
17
+
18
+ # If you want to make request via proxy, you can set your proxy server in two ways.
19
+ #
20
+ # (1) Pass proxy_options hash
21
+ #
22
+ # client = SendGrid::Client.new(host: host,
23
+ # request_headers: headers,
24
+ # proxy_options: { host: '127.0.0.1', port: 8080 })
25
+ #
26
+ # (2) Set 'http_proxy' environment variable
27
+ #
28
+ # ENV['http_proxy'] = 'user:pass@127.0.0.1:8080'
29
+ # client = SendGrid::Client.new(host: host, request_headers: headers)
30
+
12
31
  # GET Collection
13
32
  query_params = { 'limit' => 100, 'offset' => 0 }
14
33
  response = client.version('v3').api_keys.get(query_params: query_params)
@@ -0,0 +1,70 @@
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.
@@ -35,15 +35,19 @@ module SendGrid
35
35
  # Or just pass the version as part of the URL
36
36
  # (e.g. client._("/v3"))
37
37
  # - +url_path+ -> A list of the url path segments
38
+ # - +proxy_options+ -> A hash of proxy settings.
39
+ # (e.g. { host: '127.0.0.1', port: 8080 })
38
40
  #
39
- def initialize(host: nil, request_headers: nil, version: nil, url_path: nil)
41
+ def initialize(host: nil, request_headers: nil, version: nil, url_path: nil, http_options: {}, proxy_options: {}) # rubocop:disable Metrics/ParameterLists
40
42
  @host = host
41
43
  @request_headers = request_headers || {}
42
44
  @version = version
43
45
  @url_path = url_path || []
44
- @methods = %w(delete get patch post put)
46
+ @methods = %w[delete get patch post put]
45
47
  @query_params = nil
46
48
  @request_body = nil
49
+ @http_options = http_options
50
+ @proxy_options = proxy_options
47
51
  end
48
52
 
49
53
  # Update the headers for the request
@@ -138,20 +142,23 @@ module SendGrid
138
142
  def build_request(name, args)
139
143
  build_args(args) if args
140
144
  uri = build_url(query_params: @query_params)
141
- @http = add_ssl(Net::HTTP.new(uri.host, uri.port))
145
+ @http = build_http(uri.host, uri.port)
142
146
  net_http = Kernel.const_get('Net::HTTP::' + name.to_s.capitalize)
143
147
  @request = build_request_headers(net_http.new(uri.request_uri))
144
- if (@request_body &&
145
- (!@request_headers.has_key?('Content-Type') ||
146
- @request_headers['Content-Type'] == 'application/json')
147
- )
148
+ if @request_body &&
149
+ (!@request_headers.key?('Content-Type') ||
150
+ @request_headers['Content-Type'] == 'application/json')
151
+
148
152
  @request.body = @request_body.to_json
149
153
  @request['Content-Type'] = 'application/json'
150
- elsif !@request_body and (name.to_s == "post")
154
+ elsif !@request_body && (name.to_s == 'post')
151
155
  @request['Content-Type'] = ''
152
156
  else
153
157
  @request.body = @request_body
154
158
  end
159
+ @http_options.each do |attribute, value|
160
+ @http.send("#{attribute}=", value)
161
+ end
155
162
  make_request(@http, @request)
156
163
  end
157
164
 
@@ -169,6 +176,16 @@ module SendGrid
169
176
  Response.new(response)
170
177
  end
171
178
 
179
+ # Build HTTP request object
180
+ #
181
+ # * *Returns* :
182
+ # - Request object
183
+ def build_http(host, port)
184
+ params = [host, port]
185
+ params += @proxy_options.values_at(:host, :port, :user, :pass) unless @proxy_options.empty?
186
+ add_ssl(Net::HTTP.new(*params))
187
+ end
188
+
172
189
  # Allow for https calls
173
190
  #
174
191
  # * *Args* :
@@ -195,10 +212,10 @@ module SendGrid
195
212
  # - Client object
196
213
  #
197
214
  def _(name = nil)
198
- url_path = name ? @url_path.push(name) : @url_path
199
- @url_path = []
215
+ url_path = name ? @url_path + [name] : @url_path
200
216
  Client.new(host: @host, request_headers: @request_headers,
201
- version: @version, url_path: url_path)
217
+ version: @version, url_path: url_path,
218
+ http_options: @http_options)
202
219
  end
203
220
 
204
221
  # Dynamically add segments to the url, then call a method.
@@ -209,6 +226,8 @@ module SendGrid
209
226
  # * *Returns* :
210
227
  # - Client object or Response object
211
228
  #
229
+ # rubocop:disable Style/MethodMissingSuper
230
+ # rubocop:disable Style/MissingRespondToMissing
212
231
  def method_missing(name, *args, &_block)
213
232
  # Capture the version
214
233
  if name.to_s == 'version'
@@ -217,8 +236,11 @@ module SendGrid
217
236
  end
218
237
  # We have reached the end of the method chain, make the API call
219
238
  return build_request(name, args) if @methods.include?(name.to_s)
239
+
220
240
  # Add a segment to the URL
221
241
  _(name)
222
242
  end
243
+ # rubocop:enable Style/MethodMissingSuper
244
+ # rubocop:enable Style/MissingRespondToMissing
223
245
  end
224
246
  end
@@ -1,20 +1,22 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
 
5
4
  Gem::Specification.new do |spec|
6
- spec.name = 'ruby_http_client'
7
- spec.version = '3.3.0'
8
- spec.authors = ['Elmer Thomas']
9
- spec.email = 'dx@sendgrid.com'
10
- spec.summary = 'A simple REST client'
5
+ spec.name = 'ruby_http_client'
6
+ spec.version = '3.4.0'
7
+ spec.authors = ['Elmer Thomas']
8
+ spec.email = 'dx@sendgrid.com'
9
+ spec.summary = 'A simple REST client'
11
10
  spec.description = 'Quickly and easily access any REST or REST-like API.'
12
- spec.homepage = 'http://github.com/sendgrid/ruby-http-client'
13
- spec.license = 'MIT'
14
- spec.files = `git ls-files -z`.split("\x0")
15
- spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
16
- spec.test_files = spec.files.grep(/^(test|spec|features)/)
11
+ spec.homepage = 'http://github.com/sendgrid/ruby-http-client'
12
+ spec.license = 'MIT'
13
+ spec.files = `git ls-files -z`.split("\x0")
14
+ spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(/^(test|spec|features)/)
17
16
  spec.require_paths = ['lib']
18
17
 
19
- spec.add_development_dependency 'rake', '~> 0'
18
+ spec.add_development_dependency 'minitest'
19
+ spec.add_development_dependency 'rake'
20
+ spec.add_development_dependency 'rubocop'
21
+ spec.add_development_dependency 'simplecov'
20
22
  end
@@ -0,0 +1,4 @@
1
+ if ENV['CI'] == 'true'
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+ end
@@ -1,3 +1,4 @@
1
+ require './test/test_helper'
1
2
  require 'ruby_http_client'
2
3
  require 'minitest/autorun'
3
4
 
@@ -31,9 +32,14 @@ class TestClient < Minitest::Test
31
32
  ')
32
33
  @host = 'http://localhost:4010'
33
34
  @version = 'v3'
35
+ @http_options = { open_timeout: 60, read_timeout: 60 }
34
36
  @client = MockRequest.new(host: @host,
35
37
  request_headers: @headers,
36
38
  version: @version)
39
+ @client_with_options = MockRequest.new(host: @host,
40
+ request_headers: @headers,
41
+ version: @version,
42
+ http_options: @http_options)
37
43
  end
38
44
 
39
45
  def test_init
@@ -61,7 +67,7 @@ class TestClient < Minitest::Test
61
67
 
62
68
  def test_build_query_params
63
69
  url = ''
64
- query_params = { 'limit' => 100, 'offset' => 0, 'categories' => ['category1', 'category2'] }
70
+ query_params = { 'limit' => 100, 'offset' => 0, 'categories' => %w[category1 category2] }
65
71
  url = @client.build_query_params(url, query_params)
66
72
  assert_equal('?limit=100&offset=0&categories=category1&categories=category2', url)
67
73
  end
@@ -91,8 +97,8 @@ class TestClient < Minitest::Test
91
97
  args = nil
92
98
  response = @client.build_request(name, args)
93
99
  assert_equal(200, response.status_code)
94
- assert_equal({'message' => 'success'}, response.body)
95
- assert_equal({'headers' => 'test'}, response.headers)
100
+ assert_equal({ 'message' => 'success' }, response.body)
101
+ assert_equal({ 'headers' => 'test' }, response.headers)
96
102
  end
97
103
 
98
104
  def test_build_request_post_empty_content_type
@@ -103,7 +109,7 @@ class TestClient < Minitest::Test
103
109
  request_headers: headers,
104
110
  version: 'v3'
105
111
  )
106
- args = [{'request_body' => {"hogekey" => "hogevalue"}}]
112
+ args = [{ 'request_body' => { 'hogekey' => 'hogevalue' } }]
107
113
  client.build_request('post', args)
108
114
  assert_equal('application/json', client.request['Content-Type'])
109
115
  assert_equal('{"hogekey":"hogevalue"}', client.request.body)
@@ -143,10 +149,10 @@ class TestClient < Minitest::Test
143
149
  }
144
150
  client = MockRequest.new(
145
151
  host: 'https://localhost',
146
- request_headers: headers,
152
+ request_headers: headers
147
153
  )
148
154
  name = 'post'
149
- args = [{'request_body' => 'hogebody'}]
155
+ args = [{ 'request_body' => 'hogebody' }]
150
156
  client.build_request(name, args)
151
157
  assert_equal('multipart/form-data; boundary=xYzZY', client.request['Content-Type'])
152
158
  assert_equal('hogebody', client.request.body)
@@ -168,7 +174,112 @@ class TestClient < Minitest::Test
168
174
  def test_method_missing
169
175
  response = @client.get
170
176
  assert_equal(200, response.status_code)
171
- assert_equal({'message' => 'success'}, response.body)
172
- assert_equal({'headers' => 'test'}, response.headers)
177
+ assert_equal({ 'message' => 'success' }, response.body)
178
+ assert_equal({ 'headers' => 'test' }, response.headers)
179
+ end
180
+
181
+ def test_http_options
182
+ url1 = @client_with_options._('test')
183
+ assert_equal(@host, @client_with_options.host)
184
+ assert_equal(@headers, @client_with_options.request_headers)
185
+ assert_equal(['test'], url1.url_path)
186
+ end
187
+
188
+ def test_proxy_options
189
+ proxy_options = {
190
+ host: '127.0.0.1', port: 8080, user: 'anonymous', pass: 'secret'
191
+ }
192
+ client = MockRequest.new(
193
+ host: 'https://api.sendgrid.com',
194
+ request_headers: { 'Authorization' => 'Bearer xxx' },
195
+ proxy_options: proxy_options
196
+ ).version('v3').api_keys
197
+
198
+ assert(client.proxy_address, '127.0.0.1')
199
+ assert(client.proxy_pass, 'secret')
200
+ assert(client.proxy_port, 8080)
201
+ assert(client.proxy_user, 'anonymous')
202
+ end
203
+
204
+ def test_proxy_from_http_proxy_environment_variable
205
+ ENV['http_proxy'] = 'anonymous:secret@127.0.0.1:8080'
206
+
207
+ client = MockRequest.new(
208
+ host: 'https://api.sendgrid.com',
209
+ request_headers: { 'Authorization' => 'Bearer xxx' }
210
+ ).version('v3').api_keys
211
+
212
+ assert(client.proxy_address, '127.0.0.1')
213
+ assert(client.proxy_pass, 'secret')
214
+ assert(client.proxy_port, 8080)
215
+ assert(client.proxy_user, 'anonymous')
216
+ ensure
217
+ ENV.delete('http_proxy')
218
+ end
219
+
220
+ # def test_docker_exists
221
+ # assert(File.file?('./Dockerfile') || File.file?('./docker/Dockerfile'))
222
+ # end
223
+
224
+ # def test_docker_compose_exists
225
+ # assert(File.file?('./docker-compose.yml') || File.file?('./docker/docker-compose.yml'))
226
+ # end
227
+
228
+ def test_env_sample_exists
229
+ assert(File.file?('./.env_sample'))
230
+ end
231
+
232
+ def test_gitignore_exists
233
+ assert(File.file?('./.gitignore'))
234
+ end
235
+
236
+ def test_travis_exists
237
+ assert(File.file?('./.travis.yml'))
238
+ end
239
+
240
+ def test_codeclimate_exists
241
+ assert(File.file?('./.codeclimate.yml'))
242
+ end
243
+
244
+ def test_changelog_exists
245
+ assert(File.file?('./CHANGELOG.md'))
246
+ end
247
+
248
+ def test_code_of_conduct_exists
249
+ assert(File.file?('./CODE_OF_CONDUCT.md'))
250
+ end
251
+
252
+ def test_contributing_exists
253
+ assert(File.file?('./CONTRIBUTING.md'))
254
+ end
255
+
256
+ def test_issue_template_exists
257
+ assert(File.file?('./.github/ISSUE_TEMPLATE'))
258
+ end
259
+
260
+ def test_license_exists
261
+ assert(File.file?('./LICENSE.md') || File.file?('./LICENSE.txt'))
262
+ end
263
+
264
+ def test_pull_request_template_exists
265
+ assert(File.file?('./.github/PULL_REQUEST_TEMPLATE'))
266
+ end
267
+
268
+ def test_readme_exists
269
+ assert(File.file?('./README.md'))
270
+ end
271
+
272
+ def test_troubleshooting_exists
273
+ assert(File.file?('./TROUBLESHOOTING.md'))
274
+ end
275
+
276
+ def test_use_cases_exists
277
+ assert(File.file?('use_cases/README.md'))
278
+ end
279
+
280
+ def test_license_date_is_updated
281
+ license_end_year = IO.read('LICENSE.txt').match(/Copyright \(c\) 2016-(\d{4}) Twilio SendGrid/)[1].to_i
282
+ current_year = Time.new.year
283
+ assert_equal(current_year, license_end_year)
173
284
  end
174
285
  end
@@ -0,0 +1,3 @@
1
+ This directory provides examples for specific use cases. Please [open an issue](https://github.com/sendgrid/ruby-http-client/issues) or make a pull request for any use cases you would like us to document here. Thank you!
2
+
3
+ # Table of Contents
metadata CHANGED
@@ -1,27 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_http_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.4.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: 2017-10-30 00:00:00.000000000 Z
11
+ date: 2020-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
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: rake
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - "~>"
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
18
60
  - !ruby/object:Gem::Version
19
61
  version: '0'
20
62
  type: :development
21
63
  prerelease: false
22
64
  version_requirements: !ruby/object:Gem::Requirement
23
65
  requirements:
24
- - - "~>"
66
+ - - ">="
25
67
  - !ruby/object:Gem::Version
26
68
  version: '0'
27
69
  description: Quickly and easily access any REST or REST-like API.
@@ -31,21 +73,29 @@ extensions: []
31
73
  extra_rdoc_files: []
32
74
  files:
33
75
  - ".codeclimate.yml"
76
+ - ".env_sample"
34
77
  - ".github/ISSUE_TEMPLATE"
35
78
  - ".github/PULL_REQUEST_TEMPLATE"
36
79
  - ".gitignore"
80
+ - ".rubocop.yml"
37
81
  - ".travis.yml"
38
82
  - CHANGELOG.md
39
83
  - CODE_OF_CONDUCT.md
40
84
  - CONTRIBUTING.md
85
+ - Gemfile
41
86
  - LICENSE.txt
87
+ - Makefile
42
88
  - README.md
43
89
  - Rakefile
44
90
  - TROUBLESHOOTING.md
91
+ - USAGE.md
45
92
  - examples/example.rb
93
+ - first-timers.md
46
94
  - lib/ruby_http_client.rb
47
95
  - ruby_http_client.gemspec
96
+ - test/test_helper.rb
48
97
  - test/test_ruby_http_client.rb
98
+ - use_cases/README.md
49
99
  homepage: http://github.com/sendgrid/ruby-http-client
50
100
  licenses:
51
101
  - MIT
@@ -65,10 +115,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
115
  - !ruby/object:Gem::Version
66
116
  version: '0'
67
117
  requirements: []
68
- rubyforge_project:
69
- rubygems_version: 2.6.10
118
+ rubygems_version: 3.0.6
70
119
  signing_key:
71
120
  specification_version: 4
72
121
  summary: A simple REST client
73
122
  test_files:
123
+ - test/test_helper.rb
74
124
  - test/test_ruby_http_client.rb