dnsimple-ruby 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.7
1
+ 0.9.8
data/features/README ADDED
@@ -0,0 +1,12 @@
1
+ Before running the DNSimple Ruby Client cucumber feature files, you must do the following:
2
+
3
+ 1.) If you haven't already go to https://test.dnsimple.com and create an account. Activate your account to the Platinum level using the credit card number of "1".
4
+
5
+ 2.) Create a file in your home directory called .dnsimple.test and include the following:
6
+
7
+ username: YOUR_USERNAME
8
+ password: YOUR_PASSWORD
9
+ site: https://test.dnsimple.com
10
+
11
+
12
+
@@ -0,0 +1,10 @@
1
+ Feature: purchase a certificate with the CLI
2
+ As a user
3
+ In order to purchase a certificate
4
+ I should be able to use the CLI for purchasing a certificate
5
+
6
+ @announce-cmd @announce-stdout
7
+ Scenario:
8
+ Given I have set up my credentials
9
+ When I run `dnsimple certificate:purchase` with a domain I created
10
+ Then the output should show that a certificate was purchased
@@ -0,0 +1,3 @@
1
+ Then /^the output should show that a certificate was purchased$/ do
2
+ steps %Q(Then the output should contain "Purchased certificate for #{@domain_name}")
3
+ end
@@ -1,3 +1,8 @@
1
1
  Given /^I have set up my credentials$/ do
2
- File.exists?(File.expand_path('~/.dnsimple')).should be_true, "Please set up your ~/.dnsimple file to continue"
2
+ path = DNSimple::Client.config_path
3
+ File.exists?(File.expand_path(path)).should be_true, "Please set up your #{path} file to continue"
4
+ credentials = YAML.load(File.new(File.expand_path(path)))
5
+ credentials['username'].should_not be_nil, "You must specify a username in your #{path} file"
6
+ credentials['password'].should_not be_nil, "You must specify a password in your #{path} file"
7
+ credentials['site'].should_not be_nil, "For cucumber to run, you must specify a site in your #{path} file"
3
8
  end
@@ -8,13 +8,13 @@ When /^I run `(.*)` with a in\-addr\.arpa domain$/ do |cmd|
8
8
  steps %Q(When I run `#{cmd} #{@domain_name}`)
9
9
  end
10
10
 
11
- When /^I run `dnsimple delete` with a domain I created$/ do
11
+ When /^I run `(.*)` with a domain I created$/ do |cmd|
12
12
  steps %Q(
13
13
  When I run `dnsimple create` with a new domain
14
14
  )
15
15
  steps %Q(
16
- And I run `dnsimple delete #{@domain_name}`
17
- )
16
+ And I run `#{cmd} #{@domain_name}`
17
+ )
18
18
  end
19
19
 
20
20
  Then /^the output should show that the domain was created$/ do
@@ -1,7 +1,10 @@
1
1
  require 'aruba/cucumber'
2
+ $:.unshift('lib')
3
+ require 'dnsimple'
2
4
 
3
5
  Before do
4
6
  @aruba_timeout_seconds = 30
7
+ ENV['DNSIMPLE_CONFIG'] = '~/.dnsimple.test'
5
8
  end
6
9
 
7
10
  After do |scenario|
data/lib/dnsimple.rb CHANGED
@@ -12,3 +12,4 @@ require 'dnsimple/template_record'
12
12
  require 'dnsimple/transfer_order'
13
13
  require 'dnsimple/extended_attribute'
14
14
  require 'dnsimple/service'
15
+ require 'dnsimple/certificate'
@@ -0,0 +1,58 @@
1
+ module DNSimple #:nodoc:
2
+ class Certificate
3
+ include HTTParty
4
+ #debug_output $stdout
5
+
6
+ # The certificate ID in DNSimple
7
+ attr_accessor :id
8
+
9
+ attr_accessor :domain
10
+
11
+ # The subdomain on the certificate
12
+ attr_accessor :name
13
+
14
+ # When the certificate was purchased
15
+ attr_accessor :created_at
16
+
17
+ # When the certificate was last updated
18
+ attr_accessor :updated_at
19
+
20
+ #:nodoc:
21
+ def initialize(attributes)
22
+ attributes.each do |key, value|
23
+ m = "#{key}=".to_sym
24
+ self.send(m, value) if self.respond_to?(m)
25
+ end
26
+ end
27
+
28
+ def fqdn
29
+ [name, domain.name].delete_if { |p| p !~ /\S+/ }.join(".")
30
+ end
31
+
32
+ def self.purchase(domain_name, name, options={})
33
+ domain = DNSimple::Domain.find(domain_name)
34
+
35
+ certificate_hash = {
36
+ :name => name
37
+ }
38
+
39
+ options.merge!(DNSimple::Client.standard_options_with_credentials)
40
+ options.merge!({:body => {:certificate => certificate_hash}})
41
+
42
+ response = self.post("#{DNSimple::Client.base_uri}/domains/#{domain.id}/certificates", options)
43
+
44
+ pp response if DNSimple::Client.debug?
45
+
46
+ case response.code
47
+ when 201
48
+ return DNSimple::Certificate.new({:domain => domain}.merge(response["certificate"]))
49
+ when 401
50
+ raise RuntimeError, "Authentication failed"
51
+ when 406
52
+ raise DNSimple::CertificateExists.new("#{name}.#{domain_name}", response["errors"])
53
+ else
54
+ raise DNSimple::Error.new("#{name}.#{domain_name}", response["errors"])
55
+ end
56
+ end
57
+ end
58
+ end
data/lib/dnsimple/cli.rb CHANGED
@@ -65,7 +65,9 @@ module DNSimple
65
65
  'service:applied' => DNSimple::Commands::ListAppliedServices,
66
66
  'service:available' => DNSimple::Commands::ListAvailableServices,
67
67
  'service:add' => DNSimple::Commands::AddService,
68
- 'service:remove' => DNSimple::Commands::RemoveService
68
+ 'service:remove' => DNSimple::Commands::RemoveService,
69
+
70
+ 'certificate:purchase' => DNSimple::Commands::PurchaseCertificate
69
71
  }
70
72
  end
71
73
  end
@@ -110,3 +112,5 @@ require 'dnsimple/commands/list_available_services'
110
112
  require 'dnsimple/commands/list_applied_services'
111
113
  require 'dnsimple/commands/add_service'
112
114
  require 'dnsimple/commands/remove_service'
115
+
116
+ require 'dnsimple/commands/purchase_certificate'
@@ -41,7 +41,11 @@ module DNSimple
41
41
  load_credentials unless credentials_loaded?
42
42
  end
43
43
 
44
- def self.load_credentials(path='~/.dnsimple')
44
+ def self.config_path
45
+ ENV['DNSIMPLE_CONFIG'] || '~/.dnsimple'
46
+ end
47
+
48
+ def self.load_credentials(path=config_path)
45
49
  credentials = YAML.load(File.new(File.expand_path(path)))
46
50
  self.username = credentials['username']
47
51
  self.password = credentials['password']
@@ -0,0 +1,13 @@
1
+ module DNSimple
2
+ module Commands
3
+ class PurchaseCertificate
4
+ def execute(args, options={})
5
+ domain_name = args.shift
6
+ name = args.empty? ? '' : args.shift
7
+
8
+ certificate = Certificate.purchase(domain_name, name)
9
+ puts "Purchased certificate for #{certificate.fqdn}"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -107,9 +107,10 @@ module DNSimple #:nodoc:
107
107
  'last' => 'last_name',
108
108
  'state' => 'state_province',
109
109
  'province' => 'state_province',
110
+ 'state_or_province' => 'state_province',
110
111
  'email' => 'email_address',
111
112
  }
112
- aliases[name] || name
113
+ aliases[name.to_s] || name
113
114
  end
114
115
 
115
116
  def self.resolve_attributes(attributes)
@@ -149,6 +149,7 @@ module DNSimple #:nodoc:
149
149
  end
150
150
  end
151
151
 
152
+ # Purchase a domain name.
152
153
  def self.register(name, registrant={}, extended_attributes={}, options={})
153
154
  options.merge!(DNSimple::Client.standard_options_with_credentials)
154
155
 
@@ -157,7 +158,7 @@ module DNSimple #:nodoc:
157
158
  if registrant[:id]
158
159
  body[:domain][:registrant_id] = registrant[:id]
159
160
  else
160
- body.merge!(:contact => registrant)
161
+ body.merge!(:contact => Contact.resolve_attributes(registrant))
161
162
  end
162
163
  end
163
164
  body.merge!(:extended_attribute => extended_attributes)
@@ -62,6 +62,7 @@ module DNSimple #:nodoc:
62
62
 
63
63
  case response.code
64
64
  when 200
65
+ return [] unless response
65
66
  response.map { |r| ExtendedAttribute.new(r) }
66
67
  when 401
67
68
  raise RuntimeError, "Authentication failed"
@@ -20,7 +20,7 @@ module DNSimple #:nodoc:
20
20
  if registrant[:id]
21
21
  body[:domain][:registrant_id] = registrant[:id]
22
22
  else
23
- body.merge!(:contact => registrant)
23
+ body.merge!(:contact => Contact.resolve_attributes(registrant))
24
24
  end
25
25
 
26
26
  body.merge!(:extended_attribute => extended_attributes)
data/spec/README CHANGED
@@ -1,6 +1,10 @@
1
- Before running the DNSimple Ruby Client specifications, you must create a file in your home directory called .dnsimple.localhost and include the following:
1
+ Before running the DNSimple Ruby Client specifications, you must do the following:
2
+
3
+ 1.) If you haven't already create a new account at https://test.dnsimple.com and activate it using the credit card number of "1"
4
+
5
+ 2.) Create a file in your home directory called .dnsimple.test and include the following:
2
6
 
3
7
  username: YOUR_USERNAME
4
8
  password: YOUR_PASSWORD
5
-
9
+ site: https://test.dnsimple.com
6
10
 
data/spec/domain_spec.rb CHANGED
@@ -45,7 +45,8 @@ describe DNSimple::Domain do
45
45
  :city => 'Miami',
46
46
  :state_or_province => 'FL',
47
47
  :country => 'US',
48
- :postal_code => '33143'
48
+ :postal_code => '33143',
49
+ :phone => '321 555 1212'
49
50
  }
50
51
  domain = DNSimple::Domain.register(name, registrant)
51
52
  domain.name.should eql(name)
@@ -0,0 +1,17 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe DNSimple::ExtendedAttribute do
4
+
5
+ describe "list extended attributes" do
6
+ context "for com" do
7
+ it "is an empty array" do
8
+ DNSimple::ExtendedAttribute.find('com').should be_empty
9
+ end
10
+ end
11
+ context "for ca" do
12
+ it "is not empty" do
13
+ DNSimple::ExtendedAttribute.find('ca').should_not be_empty
14
+ end
15
+ end
16
+ end
17
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'lib/dnsimple'
2
2
 
3
- config = YAML.load(File.new(File.expand_path('~/.dnsimple.localhost')))
3
+ config = YAML.load(File.new(File.expand_path('~/.dnsimple.test')))
4
4
 
5
- DNSimple::Client.base_uri = config['site'] || "http://localhost:3000/"
5
+ DNSimple::Client.base_uri = config['site'] || "https://test.dnsimple.com/"
6
6
  DNSimple::Client.username = config['username']
7
7
  DNSimple::Client.password = config['password']
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dnsimple-ruby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 53
4
+ hash: 43
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 7
10
- version: 0.9.7
9
+ - 8
10
+ version: 0.9.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Anthony Eden
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-07 00:00:00 +01:00
18
+ date: 2011-05-22 00:00:00 -04:00
19
19
  default_executable: dnsimple
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -171,6 +171,8 @@ files:
171
171
  - bin/dnsimple
172
172
  - bin/dnsimple.rb
173
173
  - dnsimple-ruby.gemspec
174
+ - features/README
175
+ - features/cli/certificates/purchase_certificate.feature
174
176
  - features/cli/contacts/create_contact.feature
175
177
  - features/cli/domains/check_domain.feature
176
178
  - features/cli/domains/create_domain.feature
@@ -180,12 +182,14 @@ files:
180
182
  - features/cli/records/create_record.feature
181
183
  - features/cli/records/delete_record.feature
182
184
  - features/cli/templates/apply_template.feature
185
+ - features/step_definitions/certificate_steps.rb
183
186
  - features/step_definitions/cli_steps.rb
184
187
  - features/step_definitions/domain_steps.rb
185
188
  - features/step_definitions/record_steps.rb
186
189
  - features/step_definitions/template_steps.rb
187
190
  - features/support/env.rb
188
191
  - lib/dnsimple.rb
192
+ - lib/dnsimple/certificate.rb
189
193
  - lib/dnsimple/cli.rb
190
194
  - lib/dnsimple/client.rb
191
195
  - lib/dnsimple/commands/add_service.rb
@@ -216,6 +220,7 @@ files:
216
220
  - lib/dnsimple/commands/list_services.rb
217
221
  - lib/dnsimple/commands/list_template_records.rb
218
222
  - lib/dnsimple/commands/list_templates.rb
223
+ - lib/dnsimple/commands/purchase_certificate.rb
219
224
  - lib/dnsimple/commands/register_domain.rb
220
225
  - lib/dnsimple/commands/remove_service.rb
221
226
  - lib/dnsimple/commands/transfer_domain.rb
@@ -234,6 +239,7 @@ files:
234
239
  - spec/README
235
240
  - spec/contact_spec.rb
236
241
  - spec/domain_spec.rb
242
+ - spec/extended_attributes_spec.rb
237
243
  - spec/record_spec.rb
238
244
  - spec/spec_helper.rb
239
245
  - spec/template_spec.rb
@@ -275,6 +281,7 @@ summary: A ruby wrapper for the DNSimple API
275
281
  test_files:
276
282
  - spec/contact_spec.rb
277
283
  - spec/domain_spec.rb
284
+ - spec/extended_attributes_spec.rb
278
285
  - spec/record_spec.rb
279
286
  - spec/spec_helper.rb
280
287
  - spec/template_spec.rb