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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ad2f0f53848ebf458ce24ef1c93ffcc13987d20
4
- data.tar.gz: 8dc6ab4a793415fa47675c1b32b98a9cdf8188e1
3
+ metadata.gz: 1b267eb164a957a976d1f52b1d1f6ffcdc17dd67
4
+ data.tar.gz: 266cfc430920141b41cf225a7a719c2acb26a804
5
5
  SHA512:
6
- metadata.gz: 9047c85d1d90c5da44eacf36e79cd729e346efaed3defb34340bf482605d763bad9099ee2446af89787de2bb64149a51953f36bd61ae7d4743616f34a9d1a2eb
7
- data.tar.gz: cde66935f2047f166573598bc7358d7785b659e0aedbec6693dda775186ed4418adba10b348b656e65a3eb889daf01ee90bafd399d247578377e331b48e880e1
6
+ metadata.gz: 5d467e058f14961a4468a4b2c77a8753427f19f60e9e2f536ed1683d75829de7a31c2eacc3e54924d393853bc26735edd6c228b077daabb25a407635fd53435a
7
+ data.tar.gz: 7b16c351b0203b5266813b5f46e2b736f6a5acfcea865a78867960006059a12e60901487f40a2a5565daa81e8486487b317f556c7598764428f9a8d30495b7b8
data/CHANGELOG.md CHANGED
@@ -1,14 +1,18 @@
1
1
  # Changelog
2
2
 
3
- ## Release 1.5.1
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
- ## Release 1.5.0
11
+ #### Release 1.5.0
8
12
 
9
13
  - CHANGED: Added support for versioned API (GH-33)
10
14
 
11
- ## Release 1.4.0
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
@@ -3,7 +3,7 @@ require 'yaml'
3
3
  module DNSimple
4
4
  class Client
5
5
 
6
- API_BASE_URI = "https://api.dnsimple.com/"
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 ||= API_BASE_URI.chomp("/")
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.standard_options
92
+ def self.base_options
93
93
  options = {
94
- :format => :json,
95
- :headers => {'Accept' => 'application/json'},
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
@@ -1,3 +1,3 @@
1
1
  module DNSimple
2
- VERSION = '1.5.1'
2
+ VERSION = '1.5.2'
3
3
  end
@@ -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 :each do
8
- @_username = DNSimple::Client.username
9
- @_password = DNSimple::Client.password
10
- @_api_token = DNSimple::Client.api_token
11
- @_base_uri = DNSimple::Client.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
- DNSimple::Client.username = @_username
16
- DNSimple::Client.password = @_password
17
- DNSimple::Client.api_token = @_api_token
18
- DNSimple::Client.base_uri = @_base_uri
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
- let(:response) { stub('response', :code => 200) }
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
- it "uses HTTP authentication if there's a password provided" do
26
- DNSimple::Client.username = 'user'
27
- DNSimple::Client.password = 'pass'
28
- DNSimple::Client.api_token = nil
29
- DNSimple::Client.base_uri = 'https://api.example.com/'
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
- HTTParty.expects(method).
32
- with('https://api.example.com/domains',
33
- :format => :json, :headers => {'Accept' => 'application/json'},
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
- DNSimple::Client.send(method, '/domains')
38
- end
42
+ described_class.request(:get, '/domains', {})
43
+ end
39
44
 
40
- it "uses header authentication if there's an api token provided" do
41
- DNSimple::Client.username = 'user'
42
- DNSimple::Client.password = nil
43
- DNSimple::Client.api_token = 'token'
44
- DNSimple::Client.base_uri = 'https://api.example.com/'
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
- HTTParty.expects(method).
47
- with('https://api.example.com/domains',
48
- :format => :json, :headers => {'Accept' => 'application/json',
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
- DNSimple::Client.send(method, '/domains')
53
- end
55
+ described_class.request(:get, '/domains', {})
56
+ end
54
57
 
55
- it "raises an error if there's no password or api token provided" do
56
- DNSimple::Client.username = 'user'
57
- DNSimple::Client.password = nil
58
- DNSimple::Client.api_token = nil
59
- DNSimple::Client.base_uri = 'https://api.example.com/'
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
- lambda {
62
- DNSimple::Client.send(method, '/domains')
63
- }.should raise_error(DNSimple::Error, 'A password or API token is required for all API requests.')
64
- end
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
- @_stdout = $stdout
27
- $stdout = StringIO.new
28
- end
29
- c.after do
30
- $stdout = @_stdout
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.1
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-14 00:00:00.000000000 Z
11
+ date: 2014-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty