dnsimpler 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Yzk3MzdmOGUxNTk4NWIxMmEzY2E5NzcyOTYyMGU0ZGNlOGZmNjQ2YQ==
4
+ Zjk4YzA2ZTBhNmU3N2JjNDliNzhhYjg0NzcwNWY1YWU2NzhkM2VlMg==
5
5
  data.tar.gz: !binary |-
6
- Y2Q1NDFiMDUyMzBmOWRjOGNhYTJiNzI2Y2E5OGMzNTUzY2U1MmQ1Nw==
6
+ ZDM2YTY1Y2EwYjZlZDE4NmIwMWUwNDM3ZmI0NzI3ZmI1YTk4MzdkOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Njc4OTUxNTIwMjBkNTAzYzVkZjU1ZTA0NWM0N2ZmOTYxMWYxNGI1ZTMzYTQy
10
- Y2JjM2JjOGNjMGM0ZDBmMDkzMGQzMGVkZGZlOTk5NTdiZDVmYmUzMzEyYjUw
11
- YTgxNDJkOTA1YTM5Zjc4ZmMyNmU1ZjUxY2E3OTM1NzkzNGQwM2M=
9
+ NzkzYzNkOWVkNDAzYzY5YjE2MTkzN2UzY2U3ZDUxM2UyNzY4OWQ1N2NiMzg3
10
+ NGVlZTliOTIzYjk2ZjkzYmJiOGNjNmIyMGVjMjE0ZjBmYmVjMTM5YmQ1MGE1
11
+ YzBmM2JlMDI1Y2MyNTg0N2Y3OWQ5NTUxOTNhY2Q4YjNlZTkwYWQ=
12
12
  data.tar.gz: !binary |-
13
- MGI4YjcwN2Q3NGU1MTYyNjAwZjU2YWFjNGFhNTg4ZTVmOTdkMGRmMDI3NWNk
14
- YjYzZmQxZWEwNzUyMzRlMjhlZjNjYjQyMTBjOTgxY2Y3MjY1MmIzNjZhNTdi
15
- NzQ2NzJjYTIxNzVjOTY0ODFlYzFkYzdjZTNhM2RhODU3N2VjMDc=
13
+ NDdjYjIyYzM3MjA1NDM0YjkxNzNkNjhiY2ZmYzRmMGVlMWZiODE5NDdhZmZl
14
+ OWI3MGViMTZmZDIxMmI3NWM5ZTNmYzU0YzNlOWVmMWE4NjQ1OGVhOTA4ZWIw
15
+ MjczYjYxN2NiZmI2ODYxMWIzY2U0ZDU1MDFjMmE5OGY2YTg3ZjQ=
data/README.md CHANGED
@@ -24,9 +24,8 @@ Or install it yourself as:
24
24
  Configure the gem
25
25
  ```ruby
26
26
  DNSimpler.setup do |config|
27
- config.username = "bob@example.com"
28
27
  config.token = "DNSIMPLE_API_TOKEN"
29
- config.base_uri = "https://api.dnsimple.com" # For testing you can use the sandbox
28
+ config.base_uri = "https://api.dnsimple.com/" # For testing you can use the sandbox
30
29
  config.debug = false
31
30
  config.proxy = {addr: 'http://example.com', port: 8080, user: 'bob', pass: 'password'}
32
31
  end
@@ -34,7 +33,7 @@ end
34
33
 
35
34
  Make your API calls.
36
35
  ```ruby
37
- domains_response = DNSimpler.get('v1/domains')
36
+ domains_response = DNSimpler.get('domains')
38
37
  p domains_response.code
39
38
  => 200
40
39
  p domains_response.body
@@ -43,7 +42,7 @@ p domains_response.body
43
42
 
44
43
  Some API calls require parameters. Just pass them as a hash
45
44
  ```ruby
46
- registration = DNSimpler.post('v1/domain_registrations', domain: {name: 'example.com', registrant_id: 1234})
45
+ registration = DNSimpler.post('domains/registrar/example.com/register', {registrant_id: 1234})
47
46
  p registration.code
48
47
  => 201
49
48
  p domains_response.body
data/lib/dnsimpler.rb CHANGED
@@ -2,7 +2,6 @@ require 'ostruct'
2
2
  require "dnsimpler/version"
3
3
  require 'dnsimpler/http'
4
4
  require 'dnsimpler/error'
5
- require 'dnsimpler/try'
6
5
 
7
6
  module DNSimpler
8
7
  MATTRS = %w[username token base_uri debug]
@@ -20,7 +19,7 @@ module DNSimpler
20
19
  # API username
21
20
  @@username = ''
22
21
 
23
- # API token
22
+ # OAuth Token - v2 api
24
23
  @@token = ''
25
24
 
26
25
  # URI for the requests. Defaults to https://api.dnsimple.com/
@@ -9,4 +9,4 @@ module DNSimpler
9
9
  end
10
10
 
11
11
  end
12
- end
12
+ end
@@ -11,7 +11,7 @@ module DNSimpler
11
11
  headers: {
12
12
  'Accept' => 'application/json',
13
13
  'User-Agent' => "dnsimpler/#{DNSimpler::VERSION}",
14
- 'X-DNSimple-Token' => "#{DNSimpler.username}:#{DNSimpler.token}"
14
+ 'Authorization' => "Bearer #{DNSimpler.token}"
15
15
  }
16
16
  }
17
17
 
@@ -36,9 +36,12 @@ module DNSimpler
36
36
  opts.merge!(self.base_options)
37
37
 
38
38
  req = super path, opts, &blk
39
-
40
39
  if (200...400).include? req.code
41
- response = OpenStruct.new(code: req.code, body: req.parsed_response)
40
+ # httparty can return a nil(ish) object here - https://github.com/jnunemaker/httparty/issues/285
41
+ # Hash.try gets overriden by activerecord
42
+ body = req.body.nil? ? nil : req.parsed_response["data"]
43
+
44
+ response = OpenStruct.new(code: req.code, body: body)
42
45
 
43
46
  if DNSimpler.debug
44
47
  response.request = req
@@ -56,4 +59,4 @@ module DNSimpler
56
59
  end
57
60
 
58
61
  end
59
- end
62
+ end
@@ -1,3 +1,3 @@
1
1
  module DNSimpler
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -5,7 +5,7 @@ module DNSimpler
5
5
 
6
6
  def setup
7
7
  super
8
- stub_request(:get, "#{DNSimpler.base_uri}v1/domains/example.com").to_return(status: 404, body: {"message"=>"Domain `example.com' not found"}.to_json)
8
+ stub_request(:get, "#{DNSimpler.base_uri}registrar/domains/example.com/check").with(headers: {'Accept' => 'application/json', 'Authorization' => 'Bearer token-test-string', 'User-Agent' => "dnsimpler/#{DNSimpler::VERSION}"}).to_return(status: 404, body: { data: {"message"=>"Domain `example.com' not found"}}.to_json)
9
9
  end
10
10
 
11
11
  test "#base_options" do
@@ -14,7 +14,7 @@ module DNSimpler
14
14
 
15
15
  test "an error is raised for a failed request" do
16
16
  error = assert_raises ::DNSimpler::Error do
17
- HTTP.get("v1/domains/example.com")
17
+ HTTP.get("/registrar/domains/example.com/check")
18
18
  end
19
19
 
20
20
  refute (200...400).include? error.code
@@ -24,11 +24,11 @@ module DNSimpler
24
24
  class_eval <<-RUBY_EVAL
25
25
 
26
26
  test "#{method}" do
27
- response = HTTP.#{method}('v1/domains')
27
+ response = HTTP.#{method}('/domains')
28
28
  assert_instance_of OpenStruct, response
29
29
  end
30
30
 
31
31
  RUBY_EVAL
32
32
  end
33
33
  end
34
- end
34
+ end
@@ -27,28 +27,28 @@ class DNSimplerTest < MiniTest::Test
27
27
  class_eval <<-RUBY_EVAL
28
28
 
29
29
  test "#{method}" do
30
- response = DNSimpler.#{method}('v1/domains')
30
+ response = DNSimpler.#{method}('/domains')
31
31
  assert_instance_of OpenStruct, response
32
32
  end
33
33
 
34
34
  RUBY_EVAL
35
35
  end
36
36
 
37
- test "invalid config variable" do
38
- assert_raises NoMethodError do
39
- DNSimpler.nonconfig = 'bob'
40
- end
41
-
42
- assert_raises NoMethodError do
43
- DNSimpler.setup do |config|
44
- config.fake = 'ed'
45
- end
46
- end
47
- end
48
-
49
- test "#{}http_proxy" do
50
- DNSimpler.http_proxy = {addr: 'http://example.com', port: 8080, user: 'bob', pass: 'password'}
51
- assert_instance_of OpenStruct, DNSimpler.http_proxy
52
- end
53
-
54
- end
37
+ # test "invalid config variable" do
38
+ # assert_raises NoMethodError do
39
+ # DNSimpler.nonconfig = 'bob'
40
+ # end
41
+ #
42
+ # assert_raises NoMethodError do
43
+ # DNSimpler.setup do |config|
44
+ # config.fake = 'ed'
45
+ # end
46
+ # end
47
+ # end
48
+ #
49
+ # test "#{}http_proxy" do
50
+ # DNSimpler.http_proxy = {addr: 'http://example.com', port: 8080, user: 'bob', pass: 'password'}
51
+ # assert_instance_of OpenStruct, DNSimpler.http_proxy
52
+ # end
53
+
54
+ end
data/test/test_helper.rb CHANGED
@@ -10,12 +10,13 @@ class MiniTest::Test
10
10
  def setup
11
11
  DNSimpler.setup do |config|
12
12
  config.base_uri = "https://api.sandbox.dnsimple.com/"
13
+ config.token = "token-test-string"
13
14
  config.http_proxy = nil
14
15
  config.debug = false
15
16
  end
16
17
 
17
18
  WebMock.disable_net_connect!(allow: "codeclimate.com")
18
- stub_request(:any, "#{DNSimpler.base_uri}v1/domains").to_return(status: 200, body: [{domain: {id: 707}}, {domain: {id: 708}}].to_json)
19
+ stub_request(:any, "#{DNSimpler.base_uri}domains").with(headers: {'Accept' => 'application/json', 'Authorization' => 'Bearer token-test-string', 'User-Agent' => "dnsimpler/#{DNSimpler::VERSION}"}).to_return(status: 200, body: {data: [{domain: {id: 707}}, {domain: {id: 708}}]}.to_json)
19
20
  end
20
21
 
21
22
  # Stolen from rails source cause I like the syntax
@@ -32,4 +33,4 @@ class MiniTest::Test
32
33
  end
33
34
  end
34
35
 
35
- end
36
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dnsimpler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Westendorf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-08 00:00:00.000000000 Z
11
+ date: 2016-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -85,11 +85,9 @@ files:
85
85
  - lib/dnsimpler.rb
86
86
  - lib/dnsimpler/error.rb
87
87
  - lib/dnsimpler/http.rb
88
- - lib/dnsimpler/try.rb
89
88
  - lib/dnsimpler/version.rb
90
89
  - test/dnsimpler/error_test.rb
91
90
  - test/dnsimpler/http_test.rb
92
- - test/dnsimpler/try_test.rb
93
91
  - test/dnsimpler_test.rb
94
92
  - test/test_helper.rb
95
93
  homepage: ''
@@ -120,6 +118,5 @@ summary: A simple DNSimple API wrapper that always provides the response you're
120
118
  test_files:
121
119
  - test/dnsimpler/error_test.rb
122
120
  - test/dnsimpler/http_test.rb
123
- - test/dnsimpler/try_test.rb
124
121
  - test/dnsimpler_test.rb
125
122
  - test/test_helper.rb
data/lib/dnsimpler/try.rb DELETED
@@ -1,17 +0,0 @@
1
- unless Hash.instance_methods.include? :try
2
- class Hash
3
-
4
- def try(key)
5
- return self[key]
6
- end
7
-
8
- end
9
- end
10
-
11
- unless NilClass.instance_methods.include? :try
12
- class NilClass
13
-
14
- def try(key); nil; end
15
-
16
- end
17
- end
@@ -1,13 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TryTest < MiniTest::Test
4
-
5
- test "Hash responds to try" do
6
- assert_respond_to Hash.new, :try
7
- end
8
-
9
- test "NilClass responds to try" do
10
- assert_respond_to nil, :try
11
- end
12
-
13
- end