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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6571b9393456ff941623f5001f393bfd819493f3
4
- data.tar.gz: bf1878874ee2fa403519e51bcf28e7c1a36afbd9
3
+ metadata.gz: 7128cb8f75d602974383ef364f17f679420772b2
4
+ data.tar.gz: a2fa6d2b0434351994f911d2b72bf385b885a8f9
5
5
  SHA512:
6
- metadata.gz: 2fb5142d55bbc3408be6b2626c67a7c2c41caeb4239ace0a1b3624e870857bfb987e0073e3cea7180eec3fb935c819441d9ff1f6eee3de6c9c38b5de2f184763
7
- data.tar.gz: e681b2fc92d3c1c4d6c51bf9407c28c89b3129e73180009ab6a1e2aabf2ebf7579b70af34c638e8e627dd1979724de3313bdd58057e42b68de1361e19878f433
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
@@ -4,4 +4,3 @@ gemspec
4
4
 
5
5
  gem 'rake', '< 11'
6
6
  gem 'coveralls', require: false
7
- gem 'rspec-core', '>= 3.4.4'
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
 
@@ -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
- options[:body] = data if data
159
+ request_options = Extra.deep_merge!(base_options, options)
160
160
 
161
- HTTParty.send(method, base_url + path, Extra.deep_merge!(base_options, options))
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: { 'Accept' => 'application/json', 'User-Agent' => user_agent },
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
@@ -1,3 +1,3 @@
1
1
  module Dnsimple
2
- VERSION = "3.0.0-beta1"
2
+ VERSION = "3.0.0-beta2"
3
3
  end
@@ -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 from data" do
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.beta1
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-09 00:00:00.000000000 Z
12
+ date: 2016-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty