dnsimple-ruby 1.3.2 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +9 -2
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile +0 -2
- data/LICENSE +2 -2
- data/README.md +121 -0
- data/Rakefile +30 -14
- data/bin/dnsimple.rb +1 -1
- data/dnsimple-ruby.gemspec +9 -8
- data/features/README +1 -1
- data/features/step_definitions/cli_steps.rb +1 -1
- data/features/support/env.rb +4 -4
- data/fixtures/vcr_cassettes/DNSimple_Certificate/_all.yml +45 -32
- data/fixtures/vcr_cassettes/DNSimple_Certificate/_purchase.yml +45 -32
- data/fixtures/vcr_cassettes/DNSimple_Certificate/_submit.yml +45 -32
- data/fixtures/vcr_cassettes/DNSimple_Contact/a_new_contact.yml +39 -31
- data/fixtures/vcr_cassettes/DNSimple_Contact/an_existing_contact.yml +39 -31
- data/fixtures/vcr_cassettes/DNSimple_Domain/_all.yml +113 -94
- data/fixtures/vcr_cassettes/DNSimple_Domain/applying_templates.yml +186 -156
- data/fixtures/vcr_cassettes/DNSimple_Domain/creating_a_new_domain.yml +39 -32
- data/fixtures/vcr_cassettes/DNSimple_Domain/finding_an_existing_domain/by_id.yml +39 -32
- data/fixtures/vcr_cassettes/DNSimple_Domain/finding_an_existing_domain/by_name.yml +39 -32
- data/fixtures/vcr_cassettes/DNSimple_Domain/registration/with_a_new_registrant_contact.yml +40 -32
- data/fixtures/vcr_cassettes/DNSimple_Domain/registration/with_an_existing_contact.yml +40 -32
- data/fixtures/vcr_cassettes/DNSimple_ExtendedAttribute/list_extended_attributes/for_ca.yml +262 -29
- data/fixtures/vcr_cassettes/DNSimple_ExtendedAttribute/list_extended_attributes/for_com.yml +35 -29
- data/fixtures/vcr_cassettes/DNSimple_Record/_all.yml +147 -125
- data/fixtures/vcr_cassettes/DNSimple_Record/creating_a_new_record.yml +39 -32
- data/fixtures/vcr_cassettes/DNSimple_Record/find_a_record.yml +39 -32
- data/fixtures/vcr_cassettes/DNSimple_Template/a_template.yml +41 -32
- data/fixtures/vcr_cassettes/DNSimple_User/_me.yml +38 -31
- data/lib/dnsimple.rb +14 -1
- data/lib/dnsimple/base.rb +7 -5
- data/lib/dnsimple/certificate.rb +100 -95
- data/lib/dnsimple/cli.rb +92 -93
- data/lib/dnsimple/client.rb +109 -99
- data/lib/dnsimple/commands/{describe_certificate.rb → certificate_describe.rb} +2 -2
- data/lib/dnsimple/commands/{list_certificates.rb → certificate_list.rb} +2 -2
- data/lib/dnsimple/commands/{purchase_certificate.rb → certificate_purchase.rb} +3 -5
- data/lib/dnsimple/commands/{submit_certificate.rb → certificate_submit.rb} +3 -5
- data/lib/dnsimple/commands/{create_contact.rb → contact_create.rb} +8 -6
- data/lib/dnsimple/commands/{delete_contact.rb → contact_delete.rb} +2 -2
- data/lib/dnsimple/commands/{describe_contact.rb → contact_describe.rb} +2 -2
- data/lib/dnsimple/commands/{list_contacts.rb → contact_list.rb} +2 -2
- data/lib/dnsimple/commands/{update_contact.rb → contact_update.rb} +2 -2
- data/lib/dnsimple/commands/{apply_template.rb → domain_apply_template.rb} +2 -2
- data/lib/dnsimple/commands/{check_domain.rb → domain_check.rb} +2 -2
- data/lib/dnsimple/commands/{clear_domain.rb → domain_clear.rb} +2 -2
- data/lib/dnsimple/commands/{create_domain.rb → domain_create.rb} +2 -2
- data/lib/dnsimple/commands/{delete_domain.rb → domain_delete.rb} +2 -2
- data/lib/dnsimple/commands/{describe_domain.rb → domain_describe.rb} +2 -2
- data/lib/dnsimple/commands/{list_domains.rb → domain_list.rb} +2 -2
- data/lib/dnsimple/commands/{register_domain.rb → domain_register.rb} +2 -2
- data/lib/dnsimple/commands/{transfer_domain.rb → domain_transfer.rb} +2 -2
- data/lib/dnsimple/commands/{list_extended_attributes.rb → extended_attribute_list.rb} +2 -2
- data/lib/dnsimple/commands/{describe_user.rb → me.rb} +2 -2
- data/lib/dnsimple/commands/{create_record.rb → record_create.rb} +5 -7
- data/lib/dnsimple/commands/{delete_record.rb → record_delete.rb} +2 -2
- data/lib/dnsimple/commands/{describe_record.rb → record_describe.rb} +2 -2
- data/lib/dnsimple/commands/{list_records.rb → record_list.rb} +4 -6
- data/lib/dnsimple/commands/{update_record.rb → record_update.rb} +2 -2
- data/lib/dnsimple/commands/{add_service.rb → service_add.rb} +3 -5
- data/lib/dnsimple/commands/{describe_service.rb → service_describe.rb} +2 -2
- data/lib/dnsimple/commands/{list_services.rb → service_list.rb} +2 -2
- data/lib/dnsimple/commands/{list_applied_services.rb → service_list_applied.rb} +2 -2
- data/lib/dnsimple/commands/{list_available_services.rb → service_list_available.rb} +2 -2
- data/lib/dnsimple/commands/{remove_service.rb → service_remove.rb} +2 -2
- data/lib/dnsimple/commands/{create_template.rb → template_create.rb} +2 -2
- data/lib/dnsimple/commands/{delete_template.rb → template_delete.rb} +2 -2
- data/lib/dnsimple/commands/{add_template_record.rb → template_record_create.rb} +2 -2
- data/lib/dnsimple/commands/{delete_template_record.rb → template_record_delete.rb} +2 -2
- data/lib/dnsimple/commands/{list_template_records.rb → template_record_list.rb} +2 -2
- data/lib/dnsimple/commands/{list_templates.rb → templates_list.rb} +2 -2
- data/lib/dnsimple/contact.rb +115 -110
- data/lib/dnsimple/domain.rb +134 -132
- data/lib/dnsimple/error.rb +8 -19
- data/lib/dnsimple/extended_attribute.rb +39 -33
- data/lib/dnsimple/record.rb +71 -67
- data/lib/dnsimple/service.rb +31 -24
- data/lib/dnsimple/template.rb +52 -46
- data/lib/dnsimple/template_record.rb +61 -53
- data/lib/dnsimple/transfer_order.rb +24 -18
- data/lib/dnsimple/user.rb +22 -18
- data/lib/dnsimple/version.rb +1 -1
- data/spec/README +1 -1
- data/spec/ci/.dnsimple.test +3 -0
- data/spec/commands/{purchase_certificate_spec.rb → certificate_purchase_spec.rb} +3 -4
- data/spec/commands/{submit_certificate_spec.rb → certificate_submit_spec.rb} +3 -4
- data/spec/commands/{create_record_spec.rb → record_create_spec.rb} +4 -4
- data/spec/commands/{list_records_spec.rb → records_list_spec.rb} +2 -13
- data/spec/commands/{add_service_spec.rb → service_add_spec.rb} +3 -12
- data/spec/{certificate_spec.rb → dnsimple/certificate_spec.rb} +0 -0
- data/spec/dnsimple/client_spec.rb +45 -18
- data/spec/{contact_spec.rb → dnsimple/contact_spec.rb} +3 -1
- data/spec/{domain_spec.rb → dnsimple/domain_spec.rb} +2 -0
- data/spec/{extended_attributes_spec.rb → dnsimple/extended_attributes_spec.rb} +4 -0
- data/spec/{record_spec.rb → dnsimple/record_spec.rb} +2 -0
- data/spec/{template_spec.rb → dnsimple/template_spec.rb} +0 -0
- data/spec/{user_spec.rb → dnsimple/user_spec.rb} +2 -0
- data/spec/spec_helper.rb +24 -10
- metadata +96 -99
- data/Gemfile.lock +0 -71
- data/README +0 -108
- data/README.rdoc +0 -108
- data/README.textile +0 -138
- data/lib/dnsimple/command.rb +0 -10
- data/spec/command_spec.rb +0 -19
@@ -1,72 +1,80 @@
|
|
1
|
-
|
2
|
-
# The id of the template record
|
3
|
-
attr_accessor :id
|
1
|
+
module DNSimple
|
4
2
|
|
5
|
-
#
|
6
|
-
|
3
|
+
# A single record in a template.
|
4
|
+
class TemplateRecord < Base
|
7
5
|
|
8
|
-
|
9
|
-
|
6
|
+
# The id of the template record
|
7
|
+
attr_accessor :id
|
10
8
|
|
11
|
-
|
12
|
-
|
9
|
+
# The template the record belongs to
|
10
|
+
attr_accessor :template
|
13
11
|
|
14
|
-
|
15
|
-
|
12
|
+
# The name the record points to. This may be blank.
|
13
|
+
attr_accessor :name
|
16
14
|
|
17
|
-
|
18
|
-
|
15
|
+
# The content for the record.
|
16
|
+
attr_accessor :content
|
19
17
|
|
20
|
-
|
21
|
-
|
18
|
+
# The record type
|
19
|
+
attr_accessor :record_type
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
alias :destroy :delete
|
21
|
+
# The time-to-live
|
22
|
+
attr_accessor :ttl
|
27
23
|
|
28
|
-
|
29
|
-
|
24
|
+
# The priority (only for MX records)
|
25
|
+
attr_accessor :prio
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
def delete(options={})
|
28
|
+
DNSimple::Client.delete("templates/#{template.id}/template_records/#{id}", options)
|
29
|
+
end
|
30
|
+
alias :destroy :delete
|
34
31
|
|
35
|
-
|
32
|
+
def self.create(short_name, name, record_type, content, options={})
|
33
|
+
template = DNSimple::Template.find(short_name)
|
36
34
|
|
37
|
-
|
35
|
+
record_hash = {:name => name, :record_type => record_type, :content => content}
|
36
|
+
record_hash[:ttl] = options.delete(:ttl) || 3600
|
37
|
+
record_hash[:prio] = options.delete(:prio) || ''
|
38
38
|
|
39
|
-
|
40
|
-
when 201
|
41
|
-
return new({:template => template}.merge(response["dns_template_record"]))
|
42
|
-
else
|
43
|
-
raise DNSimple::Error.new("#{name}", response["errors"])
|
44
|
-
end
|
45
|
-
end
|
39
|
+
options.merge!({:query => {:dns_template_record => record_hash}})
|
46
40
|
|
47
|
-
|
48
|
-
template = DNSimple::Template.find(short_name)
|
49
|
-
response = DNSimple::Client.get("templates/#{template.id}/template_records/#{id}.json", options)
|
41
|
+
response = DNSimple::Client.post("templates/#{template.id}/template_records", options)
|
50
42
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
43
|
+
case response.code
|
44
|
+
when 201
|
45
|
+
new({:template => template}.merge(response["dns_template_record"]))
|
46
|
+
else
|
47
|
+
raise RequestError.new("Error creating template record", response)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.find(short_name, id, options={})
|
52
|
+
template = DNSimple::Template.find(short_name)
|
53
|
+
response = DNSimple::Client.get("templates/#{template.id}/template_records/#{id}", options)
|
54
|
+
|
55
|
+
case response.code
|
56
|
+
when 200
|
57
|
+
new({:template => template}.merge(response["dns_template_record"]))
|
58
|
+
when 404
|
59
|
+
raise RecordNotFound, "Could not find template record #{id} for template #{template.id}"
|
60
|
+
else
|
61
|
+
raise RequestError.new("Error finding template record", response)
|
62
|
+
end
|
56
63
|
end
|
57
|
-
end
|
58
64
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
65
|
+
# Get all of the template records for the template with the
|
66
|
+
# given short name.
|
67
|
+
def self.all(short_name, options={})
|
68
|
+
template = DNSimple::Template.find(short_name)
|
69
|
+
response = DNSimple::Client.get("templates/#{template.id}/template_records", options)
|
70
|
+
|
71
|
+
case response.code
|
72
|
+
when 200
|
73
|
+
response.map { |r| new({:template => template}.merge(r["dns_template_record"])) }
|
74
|
+
else
|
75
|
+
raise RequestError.new("Error listing template records", response)
|
76
|
+
end
|
70
77
|
end
|
78
|
+
|
71
79
|
end
|
72
80
|
end
|
@@ -1,28 +1,34 @@
|
|
1
|
-
|
2
|
-
attr_accessor :id
|
1
|
+
module DNSimple
|
3
2
|
|
4
|
-
|
3
|
+
# Represents a transfer order.
|
4
|
+
class TransferOrder < Base
|
5
5
|
|
6
|
-
|
7
|
-
body = {:domain => {:name => name}, :transfer_order => {:authinfo => authinfo}}
|
6
|
+
attr_accessor :id
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
body
|
13
|
-
end
|
8
|
+
attr_accessor :status
|
9
|
+
|
10
|
+
def self.create(name, authinfo='', registrant={}, extended_attributes={}, options={})
|
11
|
+
body = {:domain => {:name => name}, :transfer_order => {:authinfo => authinfo}}
|
14
12
|
|
15
|
-
|
13
|
+
if registrant[:id]
|
14
|
+
body[:domain][:registrant_id] = registrant[:id]
|
15
|
+
else
|
16
|
+
body.merge!(:contact => Contact.resolve_attributes(registrant))
|
17
|
+
end
|
16
18
|
|
17
|
-
|
19
|
+
body.merge!(:extended_attribute => extended_attributes)
|
18
20
|
|
19
|
-
|
21
|
+
options.merge!({:body => body})
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
response = DNSimple::Client.post("domain_transfers", options)
|
24
|
+
|
25
|
+
case response.code
|
26
|
+
when 201
|
27
|
+
new(response["transfer_order"])
|
28
|
+
else
|
29
|
+
raise RequestError.new("Error creating transfer order", response)
|
30
|
+
end
|
26
31
|
end
|
32
|
+
|
27
33
|
end
|
28
34
|
end
|
data/lib/dnsimple/user.rb
CHANGED
@@ -1,30 +1,34 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module DNSimple
|
2
|
+
class User < Base
|
3
3
|
|
4
|
-
|
4
|
+
attr_accessor :id
|
5
5
|
|
6
|
-
|
6
|
+
attr_accessor :created_at
|
7
7
|
|
8
|
-
|
8
|
+
attr_accessor :updated_at
|
9
9
|
|
10
|
-
|
10
|
+
attr_accessor :email
|
11
11
|
|
12
|
-
|
12
|
+
attr_accessor :login_count
|
13
13
|
|
14
|
-
|
14
|
+
attr_accessor :failed_login_count
|
15
15
|
|
16
|
-
|
16
|
+
attr_accessor :domain_count
|
17
17
|
|
18
|
-
|
19
|
-
response = DNSimple::Client.get("users/me.json", options)
|
18
|
+
attr_accessor :domain_limit
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
def self.me(options={})
|
21
|
+
response = DNSimple::Client.get("users/me", options)
|
22
|
+
|
23
|
+
case response.code
|
24
|
+
when 200
|
25
|
+
new(response["user"])
|
26
|
+
when 404
|
27
|
+
raise RecordNotFound, "Could not find account with current credentials"
|
28
|
+
else
|
29
|
+
raise RequestError.new("Error finding account", response)
|
30
|
+
end
|
28
31
|
end
|
32
|
+
|
29
33
|
end
|
30
34
|
end
|
data/lib/dnsimple/version.rb
CHANGED
data/spec/README
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'dnsimple/certificate'
|
3
|
-
require 'dnsimple/commands/
|
3
|
+
require 'dnsimple/commands/certificate_purchase'
|
4
4
|
|
5
|
-
describe DNSimple::Commands::
|
6
|
-
let(:out) { StringIO.new }
|
5
|
+
describe DNSimple::Commands::CertificatePurchase do
|
7
6
|
let(:domain_name) { 'example.com' }
|
8
7
|
let(:domain) { stub('domain') }
|
9
8
|
let(:contact) { stub('contact') }
|
@@ -19,7 +18,7 @@ describe DNSimple::Commands::PurchaseCertificate do
|
|
19
18
|
with(domain, 'certname', contact).
|
20
19
|
returns(stub("certificate", :fqdn => domain_name))
|
21
20
|
|
22
|
-
DNSimple::Commands::
|
21
|
+
DNSimple::Commands::CertificatePurchase.new.
|
23
22
|
execute([domain_name, 'certname', stub('contact id')])
|
24
23
|
end
|
25
24
|
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'dnsimple/commands/
|
2
|
+
require 'dnsimple/commands/certificate_submit'
|
3
3
|
|
4
|
-
describe DNSimple::Commands::
|
5
|
-
let(:out) { StringIO.new }
|
4
|
+
describe DNSimple::Commands::CertificateSubmit do
|
6
5
|
let(:domain) { DNSimple::Domain.new(:name => domain_name) }
|
7
6
|
let(:domain_name) { 'example.com' }
|
8
7
|
let(:name) { 'www' }
|
@@ -14,6 +13,6 @@ describe DNSimple::Commands::SubmitCertificate do
|
|
14
13
|
DNSimple::Domain.stubs(:find).with(domain_name).returns(domain)
|
15
14
|
DNSimple::Certificate.expects(:find).with(domain, certificate_id).returns(certificate)
|
16
15
|
certificate.expects(:submit).with(approver_email)
|
17
|
-
DNSimple::Commands::
|
16
|
+
DNSimple::Commands::CertificateSubmit.new.execute([domain_name, certificate_id, approver_email])
|
18
17
|
end
|
19
18
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'dnsimple/domain'
|
3
3
|
require 'dnsimple/record'
|
4
|
-
require 'dnsimple/commands/
|
4
|
+
require 'dnsimple/commands/record_create'
|
5
5
|
|
6
|
-
describe DNSimple::Commands::
|
7
|
-
let(:out) { StringIO.new }
|
6
|
+
describe DNSimple::Commands::RecordCreate do
|
8
7
|
let(:domain_name) { 'example.com' }
|
9
8
|
let(:record_name) { 'www' }
|
10
9
|
let(:record_type) { 'CNAME' }
|
11
10
|
let(:ttl) { "3600" }
|
11
|
+
|
12
12
|
context "with one argument" do
|
13
13
|
it "purchases the certificate" do
|
14
14
|
domain_stub = stub("domain", :name => domain_name)
|
@@ -16,7 +16,7 @@ describe DNSimple::Commands::CreateRecord do
|
|
16
16
|
DNSimple::Domain.expects(:find).with(domain_name).returns(domain_stub)
|
17
17
|
DNSimple::Record.expects(:create).with(domain_stub, record_name, record_type, domain_name, :ttl => ttl, :prio => nil).returns(record_stub)
|
18
18
|
|
19
|
-
DNSimple::Commands::
|
19
|
+
DNSimple::Commands::RecordCreate.new.execute([domain_name, record_name, record_type, domain_name, ttl])
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'dnsimple/commands/
|
2
|
+
require 'dnsimple/commands/record_list'
|
3
3
|
|
4
|
-
describe DNSimple::Commands::
|
4
|
+
describe DNSimple::Commands::RecordList do
|
5
5
|
before do
|
6
6
|
DNSimple::Record.expects(:all).with(instance_of(DNSimple::Domain)).returns(records)
|
7
7
|
end
|
@@ -18,17 +18,6 @@ describe DNSimple::Commands::ListRecords do
|
|
18
18
|
let(:args) { [ domain_name ] }
|
19
19
|
let(:domain_name) { 'example.com' }
|
20
20
|
let(:domain) { DNSimple::Domain.new(:name => domain_name) }
|
21
|
-
let(:out) { StringIO.new }
|
22
21
|
|
23
|
-
it 'should retrieve all records and print them' do
|
24
|
-
described_class.new(out).execute(args)
|
25
|
-
|
26
|
-
out.string.should include(ttl)
|
27
|
-
out.string.should include(id)
|
28
|
-
out.string.should include(record_type)
|
29
|
-
out.string.should include(name)
|
30
|
-
out.string.should include(domain_name)
|
31
|
-
out.string.should include(content)
|
32
|
-
end
|
33
22
|
end
|
34
23
|
|
@@ -1,12 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'dnsimple/commands/
|
3
|
-
|
4
|
-
describe DNSimple::Commands::AddService do
|
5
|
-
let(:out) { StringIO.new }
|
2
|
+
require 'dnsimple/commands/service_add'
|
6
3
|
|
4
|
+
describe DNSimple::Commands::ServiceAdd do
|
7
5
|
let(:domain_name) { 'example.com' }
|
8
6
|
let(:short_name) { 'service-name' }
|
9
|
-
let(:args) { [domain_name, short_name] }
|
10
7
|
|
11
8
|
let(:domain) { DNSimple::Domain.new(:name => domain_name) }
|
12
9
|
let(:service) { stub("service", :name => "Service") }
|
@@ -18,12 +15,6 @@ describe DNSimple::Commands::AddService do
|
|
18
15
|
|
19
16
|
it "adds a service to a domain" do
|
20
17
|
domain.expects(:add_service).with(short_name)
|
21
|
-
DNSimple::Commands::
|
22
|
-
end
|
23
|
-
|
24
|
-
it "reports to the caller" do
|
25
|
-
domain.stubs(:add_service)
|
26
|
-
DNSimple::Commands::AddService.new(out).execute(args)
|
27
|
-
out.string.should eq("Added #{service.name} to #{domain_name}\n")
|
18
|
+
DNSimple::Commands::ServiceAdd.new.execute([domain_name, short_name])
|
28
19
|
end
|
29
20
|
end
|
File without changes
|
@@ -1,15 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DNSimple::Client do
|
4
|
+
|
5
|
+
let(:klass) { described_class }
|
6
|
+
|
4
7
|
before :each do
|
5
|
-
@
|
6
|
-
|
8
|
+
@_username = DNSimple::Client.username
|
9
|
+
@_password = DNSimple::Client.password
|
10
|
+
@_api_token = DNSimple::Client.api_token
|
11
|
+
@_base_uri = DNSimple::Client.base_uri
|
7
12
|
end
|
8
13
|
|
9
|
-
after
|
10
|
-
DNSimple::Client.username
|
11
|
-
DNSimple::Client.password
|
12
|
-
DNSimple::Client.api_token
|
14
|
+
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
|
13
19
|
end
|
14
20
|
|
15
21
|
[:get, :post, :put, :delete].each do |method|
|
@@ -17,12 +23,13 @@ describe DNSimple::Client do
|
|
17
23
|
let(:response) { stub('response', :code => 200) }
|
18
24
|
|
19
25
|
it "uses HTTP authentication if there's a password provided" do
|
20
|
-
DNSimple::Client.username
|
21
|
-
DNSimple::Client.password
|
22
|
-
DNSimple::Client.api_token
|
26
|
+
DNSimple::Client.username = 'user'
|
27
|
+
DNSimple::Client.password = 'pass'
|
28
|
+
DNSimple::Client.api_token = nil
|
29
|
+
DNSimple::Client.base_uri = 'https://test.example.com'
|
23
30
|
|
24
31
|
HTTParty.expects(method).
|
25
|
-
with('
|
32
|
+
with('https://test.example.com/domains',
|
26
33
|
:format => :json, :headers => {'Accept' => 'application/json'},
|
27
34
|
:basic_auth => {:username => 'user', :password => 'pass'}).
|
28
35
|
returns(response)
|
@@ -31,12 +38,13 @@ describe DNSimple::Client do
|
|
31
38
|
end
|
32
39
|
|
33
40
|
it "uses header authentication if there's an api token provided" do
|
34
|
-
DNSimple::Client.username
|
35
|
-
DNSimple::Client.password
|
36
|
-
DNSimple::Client.api_token
|
41
|
+
DNSimple::Client.username = 'user'
|
42
|
+
DNSimple::Client.password = nil
|
43
|
+
DNSimple::Client.api_token = 'token'
|
44
|
+
DNSimple::Client.base_uri = 'https://test.example.com'
|
37
45
|
|
38
46
|
HTTParty.expects(method).
|
39
|
-
with('
|
47
|
+
with('https://test.example.com/domains',
|
40
48
|
:format => :json, :headers => {'Accept' => 'application/json',
|
41
49
|
'X-DNSimple-Token' => 'user:token'}).
|
42
50
|
returns(response)
|
@@ -45,14 +53,33 @@ describe DNSimple::Client do
|
|
45
53
|
end
|
46
54
|
|
47
55
|
it "raises an error if there's no password or api token provided" do
|
48
|
-
DNSimple::Client.username
|
49
|
-
DNSimple::Client.password
|
50
|
-
DNSimple::Client.api_token
|
56
|
+
DNSimple::Client.username = 'user'
|
57
|
+
DNSimple::Client.password = nil
|
58
|
+
DNSimple::Client.api_token = nil
|
59
|
+
DNSimple::Client.base_uri = 'https://test.example.com'
|
51
60
|
|
52
61
|
lambda {
|
53
62
|
DNSimple::Client.send(method, 'domains')
|
54
|
-
}.should raise_error(
|
63
|
+
}.should raise_error(DNSimple::Error, 'A password or API token is required for all API requests.')
|
55
64
|
end
|
56
65
|
end
|
57
66
|
end
|
67
|
+
|
68
|
+
|
69
|
+
describe ".base_uri" do
|
70
|
+
it "returns the qualified API uri" do
|
71
|
+
klass.base_uri = "http://api.dnsimple.com"
|
72
|
+
klass.base_uri.should eq("http://api.dnsimple.com")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe ".base_uri=" do
|
77
|
+
it "sets the base_uri" do
|
78
|
+
klass.base_uri = "http://api1.dnsimple.com/"
|
79
|
+
klass.base_uri.should eq("http://api1.dnsimple.com")
|
80
|
+
klass.base_uri = "http://api2.dnsimple.com"
|
81
|
+
klass.base_uri.should eq("http://api2.dnsimple.com")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
58
85
|
end
|