dnsimple-ruby 1.4.1 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +0 -3
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +1 -0
  5. data/CHANGELOG.md +8 -0
  6. data/README.md +2 -4
  7. data/dnsimple-ruby.gemspec +3 -6
  8. data/features/README.md +9 -0
  9. data/lib/dnsimple/certificate.rb +37 -36
  10. data/lib/dnsimple/client.rb +7 -4
  11. data/lib/dnsimple/contact.rb +49 -48
  12. data/lib/dnsimple/domain.rb +79 -79
  13. data/lib/dnsimple/extended_attribute.rb +1 -1
  14. data/lib/dnsimple/record.rb +7 -12
  15. data/lib/dnsimple/service.rb +2 -2
  16. data/lib/dnsimple/template.rb +11 -17
  17. data/lib/dnsimple/template_record.rb +4 -4
  18. data/lib/dnsimple/transfer_order.rb +1 -1
  19. data/lib/dnsimple/user.rb +6 -14
  20. data/lib/dnsimple/version.rb +1 -1
  21. data/spec/ci/.dnsimple.test +1 -1
  22. data/spec/dnsimple/certificate_spec.rb +40 -30
  23. data/spec/dnsimple/client_spec.rb +9 -9
  24. data/spec/dnsimple/contact_spec.rb +34 -26
  25. data/spec/dnsimple/domain_spec.rb +21 -74
  26. data/spec/dnsimple/extended_attributes_spec.rb +42 -9
  27. data/spec/dnsimple/record_spec.rb +35 -43
  28. data/spec/dnsimple/template_spec.rb +27 -5
  29. data/spec/dnsimple/user_spec.rb +22 -14
  30. data/spec/files/certificates/index/success.http +19 -0
  31. data/spec/files/certificates/show/notfound.http +17 -0
  32. data/spec/files/certificates/show/success.http +19 -0
  33. data/spec/files/contacts/show/notfound.http +17 -0
  34. data/spec/files/contacts/show/success.http +19 -0
  35. data/spec/files/domains/show/notfound.http +17 -0
  36. data/spec/files/domains/show/success.http +19 -0
  37. data/spec/files/extended_attributes/ca.http +19 -0
  38. data/spec/files/extended_attributes/com.http +19 -0
  39. data/spec/files/extended_attributes/success.http +19 -0
  40. data/spec/files/records/index/success.http +19 -0
  41. data/spec/files/records/show/notfound.http +17 -0
  42. data/spec/files/records/show/success.http +19 -0
  43. data/spec/files/templates/show/notfound.http +17 -0
  44. data/spec/files/templates/show/success.http +19 -0
  45. data/spec/files/users/me/success.http +19 -0
  46. data/spec/spec_helper.rb +14 -17
  47. data/spec/support/helpers.rb +15 -0
  48. data/spec/support/webmock.rb +11 -0
  49. metadata +65 -84
  50. data/features/README +0 -12
  51. data/fixtures/vcr_cassettes/DNSimple_Certificate/_all.yml +0 -57
  52. data/fixtures/vcr_cassettes/DNSimple_Certificate/_purchase.yml +0 -57
  53. data/fixtures/vcr_cassettes/DNSimple_Certificate/_submit.yml +0 -57
  54. data/fixtures/vcr_cassettes/DNSimple_Contact/a_new_contact.yml +0 -50
  55. data/fixtures/vcr_cassettes/DNSimple_Contact/an_existing_contact.yml +0 -50
  56. data/fixtures/vcr_cassettes/DNSimple_Domain/_all.yml +0 -149
  57. data/fixtures/vcr_cassettes/DNSimple_Domain/applying_templates.yml +0 -246
  58. data/fixtures/vcr_cassettes/DNSimple_Domain/creating_a_new_domain.yml +0 -51
  59. data/fixtures/vcr_cassettes/DNSimple_Domain/finding_an_existing_domain/by_id.yml +0 -51
  60. data/fixtures/vcr_cassettes/DNSimple_Domain/finding_an_existing_domain/by_name.yml +0 -51
  61. data/fixtures/vcr_cassettes/DNSimple_Domain/registration/with_a_new_registrant_contact.yml +0 -52
  62. data/fixtures/vcr_cassettes/DNSimple_Domain/registration/with_an_existing_contact.yml +0 -52
  63. data/fixtures/vcr_cassettes/DNSimple_ExtendedAttribute/list_extended_attributes/for_ca.yml +0 -273
  64. data/fixtures/vcr_cassettes/DNSimple_ExtendedAttribute/list_extended_attributes/for_com.yml +0 -46
  65. data/fixtures/vcr_cassettes/DNSimple_Record/_all.yml +0 -195
  66. data/fixtures/vcr_cassettes/DNSimple_Record/creating_a_new_record.yml +0 -51
  67. data/fixtures/vcr_cassettes/DNSimple_Record/find_a_record.yml +0 -51
  68. data/fixtures/vcr_cassettes/DNSimple_Template/a_template.yml +0 -53
  69. data/fixtures/vcr_cassettes/DNSimple_User/_me.yml +0 -49
  70. data/spec/README +0 -10
@@ -38,7 +38,7 @@ module DNSimple
38
38
 
39
39
  # Find the extended attributes for the given TLD
40
40
  def self.find(tld, options={})
41
- response = DNSimple::Client.get("extended_attributes/#{tld}", options)
41
+ response = DNSimple::Client.get("/v1/extended_attributes/#{tld}", options)
42
42
 
43
43
  case response.code
44
44
  when 200
@@ -7,18 +7,13 @@ module DNSimple
7
7
  }
8
8
 
9
9
  attr_accessor :id
10
-
11
10
  attr_accessor :domain
12
-
13
11
  attr_accessor :name
14
-
15
12
  attr_accessor :content
16
-
17
- attr_accessor :record_type
18
-
19
13
  attr_accessor :ttl
20
-
21
14
  attr_accessor :prio
15
+ attr_accessor :record_type
16
+
22
17
 
23
18
  def fqdn
24
19
  [name, domain.name].delete_if { |v| v !~ DNSimple::BLANK_REGEX }.join(".")
@@ -32,7 +27,7 @@ module DNSimple
32
27
 
33
28
  options.merge!(:body => {:record => record_hash})
34
29
 
35
- response = DNSimple::Client.put("domains/#{domain.id}/records/#{id}", options)
30
+ response = DNSimple::Client.put("/v1/domains/#{domain.id}/records/#{id}", options)
36
31
 
37
32
  case response.code
38
33
  when 200
@@ -43,7 +38,7 @@ module DNSimple
43
38
  end
44
39
 
45
40
  def delete(options={})
46
- DNSimple::Client.delete("domains/#{domain.id}/records/#{id}", options)
41
+ DNSimple::Client.delete("/v1/domains/#{domain.id}/records/#{id}", options)
47
42
  end
48
43
  alias :destroy :delete
49
44
 
@@ -59,7 +54,7 @@ module DNSimple
59
54
 
60
55
  options.merge!({:body => {:record => record_hash}})
61
56
 
62
- response = DNSimple::Client.post("domains/#{domain.name}/records", options)
57
+ response = DNSimple::Client.post("/v1/domains/#{domain.name}/records", options)
63
58
 
64
59
  case response.code
65
60
  when 201
@@ -72,7 +67,7 @@ module DNSimple
72
67
  end
73
68
 
74
69
  def self.find(domain, id, options={})
75
- response = DNSimple::Client.get("domains/#{domain.name}/records/#{id}", options)
70
+ response = DNSimple::Client.get("/v1/domains/#{domain.name}/records/#{id}", options)
76
71
 
77
72
  case response.code
78
73
  when 200
@@ -85,7 +80,7 @@ module DNSimple
85
80
  end
86
81
 
87
82
  def self.all(domain, options={})
88
- response = DNSimple::Client.get("domains/#{domain.name}/records", options)
83
+ response = DNSimple::Client.get("/v1/domains/#{domain.name}/records", options)
89
84
 
90
85
  case response.code
91
86
  when 200
@@ -14,7 +14,7 @@ module DNSimple
14
14
  # Find a service by its ID or short name
15
15
  def self.find(id_or_short_name, options={})
16
16
  id = id_or_short_name
17
- response = DNSimple::Client.get("services/#{id}", options)
17
+ response = DNSimple::Client.get("/v1/services/#{id}", options)
18
18
 
19
19
  case response.code
20
20
  when 200
@@ -28,7 +28,7 @@ module DNSimple
28
28
 
29
29
  # Get all of the services that can be applied to a domain
30
30
  def self.all(options={})
31
- response = DNSimple::Client.get("services", options)
31
+ response = DNSimple::Client.get("/v1/services", options)
32
32
 
33
33
  case response.code
34
34
  when 200
@@ -1,25 +1,11 @@
1
1
  module DNSimple
2
-
3
2
  class Template < Base
4
3
 
5
- # The template ID in DNSimple
6
4
  attr_accessor :id
7
-
8
- # The template name
9
5
  attr_accessor :name
10
-
11
- # The template short name
12
6
  attr_accessor :short_name
13
-
14
- # The template description
15
7
  attr_accessor :description
16
8
 
17
- # Delete the template from DNSimple. WARNING: this cannot
18
- # be undone.
19
- def delete(options={})
20
- DNSimple::Client.delete("templates/#{id}", options)
21
- end
22
- alias :destroy :delete
23
9
 
24
10
  def self.create(name, short_name, description=nil, options={})
25
11
  template_hash = {
@@ -30,7 +16,7 @@ module DNSimple
30
16
 
31
17
  options.merge!(:body => {:dns_template => template_hash})
32
18
 
33
- response = DNSimple::Client.post("templates", options)
19
+ response = DNSimple::Client.post("/v1/templates", options)
34
20
 
35
21
  case response.code
36
22
  when 201
@@ -42,7 +28,7 @@ module DNSimple
42
28
 
43
29
  def self.find(id_or_short_name, options={})
44
30
  id = id_or_short_name
45
- response = DNSimple::Client.get("templates/#{id}", options)
31
+ response = DNSimple::Client.get("/v1/templates/#{id}", options)
46
32
 
47
33
  case response.code
48
34
  when 200
@@ -55,7 +41,7 @@ module DNSimple
55
41
  end
56
42
 
57
43
  def self.all(options={})
58
- response = DNSimple::Client.get("templates", options)
44
+ response = DNSimple::Client.get("/v1/templates", options)
59
45
 
60
46
  case response.code
61
47
  when 200
@@ -65,5 +51,13 @@ module DNSimple
65
51
  end
66
52
  end
67
53
 
54
+
55
+ # Delete the template from DNSimple.
56
+ # WARNING: this cannot be undone.
57
+ def delete(options={})
58
+ DNSimple::Client.delete("/v1/templates/#{id}", options)
59
+ end
60
+ alias :destroy :delete
61
+
68
62
  end
69
63
  end
@@ -25,7 +25,7 @@ module DNSimple
25
25
  attr_accessor :prio
26
26
 
27
27
  def delete(options={})
28
- DNSimple::Client.delete("templates/#{template.id}/template_records/#{id}", options)
28
+ DNSimple::Client.delete("/v1/templates/#{template.id}/template_records/#{id}", options)
29
29
  end
30
30
  alias :destroy :delete
31
31
 
@@ -38,7 +38,7 @@ module DNSimple
38
38
 
39
39
  options.merge!({:query => {:dns_template_record => record_hash}})
40
40
 
41
- response = DNSimple::Client.post("templates/#{template.id}/template_records", options)
41
+ response = DNSimple::Client.post("/v1/templates/#{template.id}/template_records", options)
42
42
 
43
43
  case response.code
44
44
  when 201
@@ -50,7 +50,7 @@ module DNSimple
50
50
 
51
51
  def self.find(short_name, id, options={})
52
52
  template = DNSimple::Template.find(short_name)
53
- response = DNSimple::Client.get("templates/#{template.id}/template_records/#{id}", options)
53
+ response = DNSimple::Client.get("/v1/templates/#{template.id}/template_records/#{id}", options)
54
54
 
55
55
  case response.code
56
56
  when 200
@@ -66,7 +66,7 @@ module DNSimple
66
66
  # given short name.
67
67
  def self.all(short_name, options={})
68
68
  template = DNSimple::Template.find(short_name)
69
- response = DNSimple::Client.get("templates/#{template.id}/template_records", options)
69
+ response = DNSimple::Client.get("/v1/templates/#{template.id}/template_records", options)
70
70
 
71
71
  case response.code
72
72
  when 200
@@ -20,7 +20,7 @@ module DNSimple
20
20
 
21
21
  options.merge!({:body => body})
22
22
 
23
- response = DNSimple::Client.post("domain_transfers", options)
23
+ response = DNSimple::Client.post("/v1/domain_transfers", options)
24
24
 
25
25
  case response.code
26
26
  when 201
data/lib/dnsimple/user.rb CHANGED
@@ -2,29 +2,21 @@ module DNSimple
2
2
  class User < Base
3
3
 
4
4
  attr_accessor :id
5
-
6
- attr_accessor :created_at
7
-
8
- attr_accessor :updated_at
9
-
10
5
  attr_accessor :email
11
-
6
+ attr_accessor :domain_count
7
+ attr_accessor :domain_limit
12
8
  attr_accessor :login_count
13
-
14
9
  attr_accessor :failed_login_count
10
+ attr_accessor :created_at
11
+ attr_accessor :updated_at
15
12
 
16
- attr_accessor :domain_count
17
-
18
- attr_accessor :domain_limit
19
13
 
20
- def self.me(options={})
21
- response = DNSimple::Client.get("users/me", options)
14
+ def self.me
15
+ response = DNSimple::Client.get("/v1/users/me")
22
16
 
23
17
  case response.code
24
18
  when 200
25
19
  new(response["user"])
26
- when 404
27
- raise RecordNotFound, "Could not find account with current credentials"
28
20
  else
29
21
  raise RequestError.new("Error finding account", response)
30
22
  end
@@ -1,3 +1,3 @@
1
1
  module DNSimple
2
- VERSION = '1.4.1'
2
+ VERSION = '1.5.1'
3
3
  end
@@ -1,3 +1,3 @@
1
1
  username: username
2
2
  password: password
3
- base_uri: https://test.dnsimple.com
3
+ base_uri: https://api.ci.dnsimple.com
@@ -1,45 +1,55 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DNSimple::Certificate do
4
- let(:domain_name) { 'example.com' }
5
- let(:domain) { DNSimple::Domain.new(:name => domain_name) }
6
4
 
7
- describe "#fqdn" do
8
- it "joins the name and domain name" do
9
- certificate = DNSimple::Certificate.new(:name => 'www')
10
- certificate.domain = domain
11
- certificate.fqdn.should eq("www.#{domain_name}")
5
+ let(:domain) { DNSimple::Domain.new(:name => "example.com") }
6
+
7
+
8
+ describe ".find" do
9
+ before do
10
+ stub_request(:get, %r[/v1/domains/example.com/certificates/2]).
11
+ to_return(read_fixture("certificates/show/success.http"))
12
12
  end
13
- it "strips blank parts from name" do
14
- certificate = DNSimple::Certificate.new(:name => '')
15
- certificate.domain = domain
16
- certificate.fqdn.should eq(domain_name)
13
+
14
+ it "builds the correct request" do
15
+ described_class.find(domain, "2")
16
+
17
+ WebMock.should have_requested(:get, "https://#{CONFIG['username']}:#{CONFIG['password']}@#{CONFIG['host']}/v1/domains/example.com/certificates/2").
18
+ with(:headers => { 'Accept' => 'application/json' })
17
19
  end
18
- end
19
20
 
20
- describe ".purchase" do
21
- let(:contact) { DNSimple::Contact.new(:id => 1) }
22
- use_vcr_cassette
23
- it "purchases a certificate" do
24
- certificate = DNSimple::Certificate.purchase(domain, 'www', contact)
25
- certificate.fqdn.should eq("www.#{domain_name}")
21
+ context "when the certificate exists" do
22
+ it "returns the certificate" do
23
+ result = described_class.find(domain, "2")
24
+
25
+ expect(result.id).to eq(4576)
26
+ expect(result.domain).to eq(domain)
27
+ expect(result.name).to eq("www")
28
+ expect(result.csr).to eq("-----BEGIN NEW CERTIFICATE REQUEST-----\nRHr2akB4KMba6FMAsvlStnO/2ika16hNx+d3smPNsER+HA==\n-----END NEW CERTIFICATE REQUEST-----\n")
29
+ expect(result.ssl_certificate).to eq("-----BEGIN CERTIFICATE-----\nXwTkw5UCPpaVyUYcwHlvaprOe9ZbwIyEHm2AT1rW+70=\n-----END CERTIFICATE-----\n")
30
+ expect(result.private_key).to eq("-----BEGIN RSA PRIVATE KEY-----\nUeXbFi7o+nuPfRhpBFQEKwacKFc3Hnc1hH6UsnC0KY25cUif7yz38A==\n-----END RSA PRIVATE KEY-----\n")
31
+ expect(result.approver_email).to eq("example@example.net")
32
+ expect(result.created_at).to eq("2013-09-17T21:54:42Z")
33
+ expect(result.updated_at).to eq("2013-09-17T22:25:36Z")
34
+
35
+ expect(result.available_approver_emails).to be_nil
36
+ expect(result.certificate_status).to be_nil
37
+ end
26
38
  end
27
39
  end
28
40
 
29
- describe ".all" do
30
- use_vcr_cassette
31
- it "returns all certificates for the specific domain" do
32
- certificates = DNSimple::Certificate.all(domain)
33
- certificates.length.should eq(1)
34
- certificates.first.fqdn.should eq('www.example.com')
41
+
42
+ describe "#fqdn" do
43
+ it "joins the name and domain name" do
44
+ certificate = described_class.new(:name => 'www')
45
+ certificate.domain = domain
46
+ expect(certificate.fqdn).to eq("www.#{domain.name}")
35
47
  end
36
- end
37
48
 
38
- describe "#submit" do
39
- use_vcr_cassette
40
- let(:certificate) { DNSimple::Certificate.new(:id => 1, :domain => domain) }
41
- it "submits a certificate for purchase" do
42
- certificate.submit("admin@example.com")
49
+ it "strips blank parts from name" do
50
+ certificate = described_class.new(:name => '')
51
+ certificate.domain = domain
52
+ expect(certificate.fqdn).to eq(domain.name)
43
53
  end
44
54
  end
45
55
 
@@ -26,40 +26,40 @@ describe DNSimple::Client do
26
26
  DNSimple::Client.username = 'user'
27
27
  DNSimple::Client.password = 'pass'
28
28
  DNSimple::Client.api_token = nil
29
- DNSimple::Client.base_uri = 'https://test.example.com'
29
+ DNSimple::Client.base_uri = 'https://api.example.com/'
30
30
 
31
31
  HTTParty.expects(method).
32
- with('https://test.example.com/domains',
32
+ with('https://api.example.com/domains',
33
33
  :format => :json, :headers => {'Accept' => 'application/json'},
34
- :basic_auth => {:username => 'user', :password => 'pass'}).
34
+ :basic_auth => { :username => 'user', :password => 'pass'}).
35
35
  returns(response)
36
36
 
37
- DNSimple::Client.send(method, 'domains')
37
+ DNSimple::Client.send(method, '/domains')
38
38
  end
39
39
 
40
40
  it "uses header authentication if there's an api token provided" do
41
41
  DNSimple::Client.username = 'user'
42
42
  DNSimple::Client.password = nil
43
43
  DNSimple::Client.api_token = 'token'
44
- DNSimple::Client.base_uri = 'https://test.example.com'
44
+ DNSimple::Client.base_uri = 'https://api.example.com/'
45
45
 
46
46
  HTTParty.expects(method).
47
- with('https://test.example.com/domains',
47
+ with('https://api.example.com/domains',
48
48
  :format => :json, :headers => {'Accept' => 'application/json',
49
49
  'X-DNSimple-Token' => 'user:token'}).
50
50
  returns(response)
51
51
 
52
- DNSimple::Client.send(method, 'domains')
52
+ DNSimple::Client.send(method, '/domains')
53
53
  end
54
54
 
55
55
  it "raises an error if there's no password or api token provided" do
56
56
  DNSimple::Client.username = 'user'
57
57
  DNSimple::Client.password = nil
58
58
  DNSimple::Client.api_token = nil
59
- DNSimple::Client.base_uri = 'https://test.example.com'
59
+ DNSimple::Client.base_uri = 'https://api.example.com/'
60
60
 
61
61
  lambda {
62
- DNSimple::Client.send(method, 'domains')
62
+ DNSimple::Client.send(method, '/domains')
63
63
  }.should raise_error(DNSimple::Error, 'A password or API token is required for all API requests.')
64
64
  end
65
65
  end
@@ -2,35 +2,43 @@ require 'spec_helper'
2
2
 
3
3
  describe DNSimple::Contact do
4
4
 
5
- describe "a new contact" do
6
- use_vcr_cassette
7
-
8
- let(:contact_attributes) {
9
- {
10
- :first_name => 'John',
11
- :last_name => 'Doe',
12
- :address1 => '1 SW 1st Street',
13
- :city => 'Miami',
14
- :state_province => 'FL',
15
- :postal_code => '33143',
16
- :country => 'US',
17
- :email_address => 'john.doe@example.com',
18
- :phone => '305 111 2222'
19
- }
20
- }
21
- it "has specific attributes" do
22
- contact = DNSimple::Contact.create(contact_attributes)
23
- contact.first_name.should eql(contact_attributes[:first_name])
24
- contact.id.should_not be_nil
5
+ describe ".find" do
6
+ before do
7
+ stub_request(:get, %r[/v1/contacts/2]).
8
+ to_return(read_fixture("contacts/show/success.http"))
25
9
  end
26
- end
27
10
 
28
- describe "an existing contact" do
29
- use_vcr_cassette
11
+ it "builds the correct request" do
12
+ described_class.find("2")
13
+
14
+ WebMock.should have_requested(:get, "https://#{CONFIG['username']}:#{CONFIG['password']}@#{CONFIG['host']}/v1/contacts/2").
15
+ with(:headers => { 'Accept' => 'application/json' })
16
+ end
17
+
18
+ context "when the contact exists" do
19
+ it "returns the contact" do
20
+ result = described_class.find("2")
21
+
22
+ expect(result).to be_a(described_class)
23
+ expect(result.id).to eq(2)
24
+ expect(result.first_name).to eq("Simone")
25
+ expect(result.last_name).to eq("Carletti")
26
+ expect(result.job_title).to eq("Underwater Programmer")
27
+ expect(result.organization_name).to eq("DNSimple")
28
+ expect(result.email_address).to eq("example@example.com")
29
+ expect(result.phone).to eq("+1 111 000000")
30
+ expect(result.fax).to eq("+1 222 000000")
31
+ expect(result.address1).to eq("Awesome Street")
32
+ expect(result.address2).to eq("c/o Someone")
33
+ expect(result.city).to eq("Rome")
34
+ expect(result.state_province).to eq("RM")
35
+ expect(result.postal_code).to eq("00171")
36
+ expect(result.country).to eq("IT")
37
+ expect(result.created_at).to eq("2013-11-08T17:23:15Z")
38
+ expect(result.updated_at).to eq("2013-11-08T17:23:15Z")
30
39
 
31
- it "can be found by id" do
32
- contact = DNSimple::Contact.find(1)
33
- contact.should_not be_nil
40
+ expect(result.phone_ext).to be_nil
41
+ end
34
42
  end
35
43
  end
36
44