dnsimple-ruby 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -3
- data/lib/dnsimple/client.rb +8 -9
- data/lib/dnsimple/version.rb +1 -1
- data/spec/dnsimple/client_spec.rb +65 -43
- data/spec/spec_helper.rb +7 -7
- 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: 1b267eb164a957a976d1f52b1d1f6ffcdc17dd67
|
4
|
+
data.tar.gz: 266cfc430920141b41cf225a7a719c2acb26a804
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d467e058f14961a4468a4b2c77a8753427f19f60e9e2f536ed1683d75829de7a31c2eacc3e54924d393853bc26735edd6c228b077daabb25a407635fd53435a
|
7
|
+
data.tar.gz: 7b16c351b0203b5266813b5f46e2b736f6a5acfcea865a78867960006059a12e60901487f40a2a5565daa81e8486487b317f556c7598764428f9a8d30495b7b8
|
data/CHANGELOG.md
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
|
3
|
+
#### Release 1.5.2
|
4
|
+
|
5
|
+
- NEW: Provide a meaningful user-agent.
|
6
|
+
|
7
|
+
#### Release 1.5.1
|
4
8
|
|
5
9
|
- FIXED: Invalid base URI.
|
6
10
|
|
7
|
-
|
11
|
+
#### Release 1.5.0
|
8
12
|
|
9
13
|
- CHANGED: Added support for versioned API (GH-33)
|
10
14
|
|
11
|
-
|
15
|
+
#### Release 1.4.0
|
12
16
|
|
13
17
|
- CHANGED: Normalized exception handling. No more RuntimeError.
|
14
18
|
In case of request error, the client raises RequestError, RecordExists or RecodNotFound
|
data/lib/dnsimple/client.rb
CHANGED
@@ -3,7 +3,7 @@ require 'yaml'
|
|
3
3
|
module DNSimple
|
4
4
|
class Client
|
5
5
|
|
6
|
-
|
6
|
+
DEFAULT_BASE_URI = "https://api.dnsimple.com/"
|
7
7
|
|
8
8
|
|
9
9
|
def self.debug?
|
@@ -42,7 +42,7 @@ module DNSimple
|
|
42
42
|
#
|
43
43
|
# @return [String] The qualified API base uri.
|
44
44
|
def self.base_uri
|
45
|
-
@base_uri ||=
|
45
|
+
@base_uri ||= DEFAULT_BASE_URI.chomp("/")
|
46
46
|
end
|
47
47
|
|
48
48
|
# Sets the qualified API base uri.
|
@@ -89,11 +89,11 @@ module DNSimple
|
|
89
89
|
(@credentials_loaded ||= false) or (username and (password or api_token))
|
90
90
|
end
|
91
91
|
|
92
|
-
def self.
|
92
|
+
def self.base_options
|
93
93
|
options = {
|
94
|
-
|
95
|
-
|
96
|
-
|
94
|
+
:format => :json,
|
95
|
+
:headers => { 'Accept' => 'application/json', 'User-Agent' => "dnsimple-ruby/#{DNSimple::VERSION}" },
|
96
|
+
}
|
97
97
|
|
98
98
|
if http_proxy
|
99
99
|
options.merge!(
|
@@ -103,7 +103,7 @@ module DNSimple
|
|
103
103
|
end
|
104
104
|
|
105
105
|
if password
|
106
|
-
options[:basic_auth] = {:username => username, :password => password}
|
106
|
+
options[:basic_auth] = { :username => username, :password => password }
|
107
107
|
elsif api_token
|
108
108
|
options[:headers]['X-DNSimple-Token'] = "#{username}:#{api_token}"
|
109
109
|
else
|
@@ -130,8 +130,7 @@ module DNSimple
|
|
130
130
|
end
|
131
131
|
|
132
132
|
def self.request(method, path, options)
|
133
|
-
response = HTTParty.send(method, "#{base_uri}#{path}",
|
134
|
-
standard_options.merge(options))
|
133
|
+
response = HTTParty.send(method, "#{base_uri}#{path}", base_options.merge(options))
|
135
134
|
|
136
135
|
if response.code == 401
|
137
136
|
raise AuthenticationFailed
|
data/lib/dnsimple/version.rb
CHANGED
@@ -3,65 +3,87 @@ require 'spec_helper'
|
|
3
3
|
describe DNSimple::Client do
|
4
4
|
|
5
5
|
let(:klass) { described_class }
|
6
|
+
let(:response) { stub('response', :code => 200) }
|
6
7
|
|
7
|
-
before
|
8
|
-
@_username =
|
9
|
-
@_password =
|
10
|
-
@_api_token =
|
11
|
-
@_base_uri =
|
8
|
+
before do
|
9
|
+
@_username = described_class.username
|
10
|
+
@_password = described_class.password
|
11
|
+
@_api_token = described_class.api_token
|
12
|
+
@_base_uri = described_class.base_uri
|
12
13
|
end
|
13
14
|
|
14
15
|
after do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
described_class.username = @_username
|
17
|
+
described_class.password = @_password
|
18
|
+
described_class.api_token = @_api_token
|
19
|
+
described_class.base_uri = @_base_uri
|
19
20
|
end
|
20
21
|
|
21
22
|
[:get, :post, :put, :delete].each do |method|
|
22
23
|
describe ".#{method}" do
|
23
|
-
|
24
|
+
it "delegates to .request" do
|
25
|
+
described_class.expects(:request).with(method, '/domains', { :foo => 'bar' })
|
26
|
+
described_class.send(method, '/domains', { :foo => 'bar' })
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
24
30
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
31
|
+
describe ".request" do
|
32
|
+
it "uses HTTP authentication if there's a password provided" do
|
33
|
+
described_class.username = 'user'
|
34
|
+
described_class.password = 'pass'
|
35
|
+
described_class.api_token = nil
|
36
|
+
described_class.base_uri = 'https://api.example.com/'
|
30
37
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
:basic_auth => { :username => 'user', :password => 'pass'}).
|
35
|
-
returns(response)
|
38
|
+
HTTParty.expects(:get).
|
39
|
+
with('https://api.example.com/domains', has_entries(:basic_auth => { :username => 'user', :password => 'pass' })).
|
40
|
+
returns(response)
|
36
41
|
|
37
|
-
|
38
|
-
|
42
|
+
described_class.request(:get, '/domains', {})
|
43
|
+
end
|
39
44
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
+
it "uses header authentication if there's an api token provided" do
|
46
|
+
described_class.username = 'user'
|
47
|
+
described_class.password = nil
|
48
|
+
described_class.api_token = 'token'
|
49
|
+
described_class.base_uri = 'https://api.example.com/'
|
45
50
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
'X-DNSimple-Token' => 'user:token'}).
|
50
|
-
returns(response)
|
51
|
+
HTTParty.expects(:get).
|
52
|
+
with('https://api.example.com/domains', has_entries(:headers => has_entries({ 'X-DNSimple-Token' => 'user:token' }))).
|
53
|
+
returns(response)
|
51
54
|
|
52
|
-
|
53
|
-
|
55
|
+
described_class.request(:get, '/domains', {})
|
56
|
+
end
|
54
57
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
it "raises an error if there's no password or api token provided" do
|
59
|
+
described_class.username = 'user'
|
60
|
+
described_class.password = nil
|
61
|
+
described_class.api_token = nil
|
62
|
+
described_class.base_uri = 'https://api.example.com/'
|
60
63
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
64
|
+
expect {
|
65
|
+
described_class.request(:get, '/domains', {})
|
66
|
+
}.to raise_error(DNSimple::Error, 'A password or API token is required for all API requests.')
|
67
|
+
end
|
68
|
+
|
69
|
+
it "adds a custom user-agent" do
|
70
|
+
HTTParty.expects(:get).
|
71
|
+
with(is_a(String), has_entries(:headers => has_entries({ 'User-Agent' => "dnsimple-ruby/#{DNSimple::VERSION}" }))).
|
72
|
+
returns(response)
|
73
|
+
|
74
|
+
described_class.request(:get, '/foo', {})
|
75
|
+
end
|
76
|
+
|
77
|
+
it "performs a request" do
|
78
|
+
HTTParty.expects(:get).
|
79
|
+
with("#{described_class.base_uri}/foo",
|
80
|
+
:format => :json,
|
81
|
+
:basic_auth => { :username => described_class.username, :password => described_class.password },
|
82
|
+
:headers => { 'Accept' => 'application/json', 'User-Agent' => "dnsimple-ruby/#{DNSimple::VERSION}" }
|
83
|
+
).
|
84
|
+
returns(response)
|
85
|
+
|
86
|
+
described_class.request(:get, '/foo', {})
|
65
87
|
end
|
66
88
|
end
|
67
89
|
|
data/spec/spec_helper.rb
CHANGED
@@ -22,13 +22,13 @@ RSpec.configure do |c|
|
|
22
22
|
c.mock_framework = :mocha
|
23
23
|
|
24
24
|
# Silent the puts call in the commands
|
25
|
-
c.before do
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
c.after do
|
30
|
-
|
31
|
-
end
|
25
|
+
# c.before do
|
26
|
+
# @_stdout = $stdout
|
27
|
+
# $stdout = StringIO.new
|
28
|
+
# end
|
29
|
+
# c.after do
|
30
|
+
# $stdout = @_stdout
|
31
|
+
# end
|
32
32
|
end
|
33
33
|
|
34
34
|
Dir[File.join(SPEC_ROOT, "support/**/*.rb")].each { |f| require f }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dnsimple-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Eden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|