dnsimple 3.0.0.pre.beta1 → 3.0.0.pre.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile +0 -1
- data/README.md +8 -1
- data/lib/dnsimple/client.rb +19 -3
- data/lib/dnsimple/client/oauth.rb +2 -0
- data/lib/dnsimple/version.rb +1 -1
- data/spec/dnsimple/client/oauth_spec.rb +13 -0
- data/spec/dnsimple/client_spec.rb +16 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7128cb8f75d602974383ef364f17f679420772b2
|
4
|
+
data.tar.gz: a2fa6d2b0434351994f911d2b72bf385b885a8f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 774ea827afd9b4f40ba487dbf04c8c5a1c32bb3850abd94bae3652e4d75867c124000384d26505186e5963f0873b74a5b117342b8530eeea491e8808b95b3360
|
7
|
+
data.tar.gz: e4debc8a6e08f919d7839d007e58845a58a0f68e0b64d5ecb77623030a585a830f1e2665f7f49f061ee20f89117634df8b501e40bbe6c8e7df913884d44047c6
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,12 @@ This project uses [Semantic Versioning 2.0.0](http://semver.org/).
|
|
5
5
|
|
6
6
|
#### 3.0
|
7
7
|
|
8
|
+
##### beta2
|
9
|
+
|
10
|
+
- FIXED: `state` and `redirect_uri` are not properly passed in the request to exchang the code for an access token (GH-89, GH-90).
|
11
|
+
|
12
|
+
- FIXED: Request body is not properly serialized to JSON, and the "Content-Type" header was omissed (GH-91).
|
13
|
+
|
8
14
|
##### beta1
|
9
15
|
|
10
16
|
- CHANGED: Minimum Ruby version >= 2
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -18,10 +18,17 @@ This library is currently in beta version, the methods and the implementation sh
|
|
18
18
|
|
19
19
|
## Installation
|
20
20
|
|
21
|
+
During the initial beta period, releases of this gem are flagged as [prerelease](http://guides.rubygems.org/patterns/#prerelease-gems). You will need to append `--pre` in order to install the beta client.
|
22
|
+
|
21
23
|
```
|
22
|
-
$ gem install dnsimple
|
24
|
+
$ gem install dnsimple --pre
|
23
25
|
```
|
24
26
|
|
27
|
+
Also note that Bundler ignores pre-releases by default. To use a pre-release gem, make sure to explicitly add the release version.
|
28
|
+
|
29
|
+
```
|
30
|
+
gem 'dnsimple', '~> 3.0', '>= 3.0.0.pre.beta1'
|
31
|
+
```
|
25
32
|
|
26
33
|
## Usage
|
27
34
|
|
data/lib/dnsimple/client.rb
CHANGED
@@ -156,9 +156,14 @@ module Dnsimple
|
|
156
156
|
# @param [Hash] options The query and header params for the request
|
157
157
|
# @return [HTTParty::Response]
|
158
158
|
def request(method, path, data = nil, options = {})
|
159
|
-
|
159
|
+
request_options = Extra.deep_merge!(base_options, options)
|
160
160
|
|
161
|
-
|
161
|
+
if data
|
162
|
+
request_options[:headers]["Content-Type"] = content_type(request_options[:headers])
|
163
|
+
request_options[:body] = content_data(request_options[:headers], data)
|
164
|
+
end
|
165
|
+
|
166
|
+
HTTParty.send(method, base_url + path, request_options)
|
162
167
|
end
|
163
168
|
|
164
169
|
|
@@ -167,7 +172,10 @@ module Dnsimple
|
|
167
172
|
def base_options
|
168
173
|
options = {
|
169
174
|
format: :json,
|
170
|
-
headers: {
|
175
|
+
headers: {
|
176
|
+
'Accept' => 'application/json',
|
177
|
+
'User-Agent' => user_agent
|
178
|
+
},
|
171
179
|
}
|
172
180
|
|
173
181
|
if proxy
|
@@ -188,5 +196,13 @@ module Dnsimple
|
|
188
196
|
options
|
189
197
|
end
|
190
198
|
|
199
|
+
def content_type(headers)
|
200
|
+
headers["Content-Type"] || "application/json"
|
201
|
+
end
|
202
|
+
|
203
|
+
def content_data(headers, data)
|
204
|
+
headers["Content-Type"] == "application/json" ? JSON.dump(data) : data
|
205
|
+
end
|
206
|
+
|
191
207
|
end
|
192
208
|
end
|
@@ -13,6 +13,8 @@ module Dnsimple
|
|
13
13
|
# @return [String] The url to redirect the user to authorize.
|
14
14
|
def exchange_authorization_for_token(code, client_id, client_secret, options = {})
|
15
15
|
attributes = { code: code, client_id: client_id, client_secret: client_secret, grant_type: "authorization_code" }
|
16
|
+
attributes[:state] = options.delete(:state) if options.has_key?(:state)
|
17
|
+
attributes[:redirect_uri] = options.delete(:redirect_uri) if options.has_key?(:redirect_uri)
|
16
18
|
response = client.post(Client.versioned("/oauth/access_token"), attributes, options)
|
17
19
|
Struct::OauthToken.new(response)
|
18
20
|
end
|
data/lib/dnsimple/version.rb
CHANGED
@@ -31,6 +31,19 @@ describe Dnsimple::Client, ".oauth" do
|
|
31
31
|
expect(result.token_type).to eq("Bearer")
|
32
32
|
expect(result.account_id).to eq(1)
|
33
33
|
end
|
34
|
+
|
35
|
+
context "when state and redirect_uri are provided" do
|
36
|
+
let(:state) { "super-state" }
|
37
|
+
let(:redirect_uri) { "super-redirect-uri" }
|
38
|
+
|
39
|
+
it "builds the correct request" do
|
40
|
+
subject.exchange_authorization_for_token(code, client_id, client_secret, state:state, redirect_uri: redirect_uri)
|
41
|
+
|
42
|
+
expect(WebMock).to have_requested(:post, "https://api.dnsimple.test/v2/oauth/access_token")
|
43
|
+
.with(body: { client_id: client_id, client_secret: client_secret, code: code, state: state, redirect_uri: redirect_uri, grant_type: "authorization_code" })
|
44
|
+
.with(headers: { 'Accept' => 'application/json' })
|
45
|
+
end
|
46
|
+
end
|
34
47
|
end
|
35
48
|
|
36
49
|
describe "#authorize_url" do
|
@@ -137,19 +137,32 @@ describe Dnsimple::Client do
|
|
137
137
|
subject.request(:get, 'foo')
|
138
138
|
end
|
139
139
|
|
140
|
-
it "properly extracts options
|
140
|
+
it "properly extracts processes options and encodes data" do
|
141
141
|
expect(HTTParty).to receive(:put).
|
142
142
|
with("#{subject.base_url}foo",
|
143
143
|
format: :json,
|
144
|
-
body: { something: "else" },
|
144
|
+
body: JSON.dump({ something: "else" }),
|
145
145
|
query: { foo: "bar" },
|
146
146
|
basic_auth: { username: "user", password: "pass" },
|
147
|
-
headers: { 'Accept' => 'application/json', 'User-Agent' => "dnsimple-ruby/#{Dnsimple::VERSION}", "Custom" => "Header" }
|
147
|
+
headers: { 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'User-Agent' => "dnsimple-ruby/#{Dnsimple::VERSION}", "Custom" => "Header" }
|
148
148
|
).
|
149
149
|
and_return(double('response', code: 200))
|
150
150
|
|
151
151
|
subject.request(:put, 'foo', { something: "else" }, { query: { foo: "bar" }, headers: { "Custom" => "Header" } })
|
152
152
|
end
|
153
|
+
|
154
|
+
it "handles non application/json content types" do
|
155
|
+
expect(HTTParty).to receive(:post).
|
156
|
+
with("#{subject.base_url}foo",
|
157
|
+
format: :json,
|
158
|
+
body: { something: "else" },
|
159
|
+
basic_auth: { username: "user", password: "pass" },
|
160
|
+
headers: { 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => "dnsimple-ruby/#{Dnsimple::VERSION}" }
|
161
|
+
).
|
162
|
+
and_return(double('response', code: 200))
|
163
|
+
|
164
|
+
subject.request(:post, 'foo', { something: "else" }, headers: { "Content-Type" => "application/x-www-form-urlencoded" })
|
165
|
+
end
|
153
166
|
end
|
154
167
|
|
155
168
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dnsimple
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.pre.
|
4
|
+
version: 3.0.0.pre.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Eden
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-03-
|
12
|
+
date: 2016-03-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|