digitalocean 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0bcfea9e0a5aba026b03372ef1667fe125912831
4
+ data.tar.gz: e9fd93b107102e8e1c66716271796f41dc76472b
5
+ SHA512:
6
+ metadata.gz: f298f4774324d7e70b4c4015ee023e7184cc3167d2f93e52d2c4870346e41c2d88b448387625a4aebaff30c184784941a4a47b6ea6168c8d70f73446305b128f
7
+ data.tar.gz: 4c1ddb9a6b0e0e43677e7143f8df7a2efc4e5139d554734332558f0fe2180ca6a64ebcaa0809663179da8286e959918c2e863fb6a2ebb042062dd42e504733e4
data/.gitignore CHANGED
@@ -15,4 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
- .env
18
+ .env
19
+ .idea
data/README.md CHANGED
@@ -33,7 +33,7 @@ Then in your application initialize the gem:
33
33
 
34
34
  ### Create Droplet
35
35
 
36
- $ Digitalocean::Document.create({:name => droplet_name, :size_id => size_id, :image_id => image_id, :region_id => region_id)
36
+ $ Digitalocean::Droplet.create({:name => droplet_name, :size_id => size_id, :image_id => image_id, :region_id => region_id)
37
37
 
38
38
  ## Available Commands
39
39
 
@@ -47,13 +47,31 @@ Then in your application initialize the gem:
47
47
  $ Digitalocean::Droplet.power_on(id)
48
48
  $ Digitalocean::Droplet.snapshot(id)
49
49
  $ Digitalocean::Droplet.destroy(id)
50
+
50
51
  $ Digitalocean::Image.all
52
+ $ Digitalocean::Image.find(id)
53
+ $ Digitalocean::Image.destroy(id)
54
+ $ Digitalocean::Image.transfer(id, region_id)
55
+
51
56
  $ Digitalocean::Region.all
57
+
52
58
  $ Digitalocean::Size.all
59
+
53
60
  $ Digitalocean::SshKey.all
54
61
  $ Digitalocean::SshKey.retrieve(id)
55
62
  $ Digitalocean::SshKey.create({})
56
63
 
64
+ $ Digitalocean::Domain.all
65
+ $ Digitalocean::Domain.find(id)
66
+ $ Digitalocean::Domain.create(domain_name, ip_address)
67
+ $ Digitalocean::Domain.destroy(id)
68
+
69
+ $ Digitalocean::Record.all(domain_id)
70
+ $ Digitalocean::Record.find(domain_id, record_id)
71
+ $ Digitalocean::Record.create(domain_id, record_type, data, [name, priority, port, weight])
72
+ $ Digitalocean::Record.edit(domain_id, record_id, {})
73
+ $ Digitalocean::Record.destroy(domain_id, record_id)
74
+
57
75
  ## Contributing
58
76
 
59
77
  1. Fork it
data/digitalocean.gemspec CHANGED
@@ -6,8 +6,8 @@ require 'digitalocean/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "digitalocean"
8
8
  gem.version = Digitalocean::VERSION
9
- gem.authors = ["scottmotte"]
10
- gem.email = ["scott@scottmotte.com"]
9
+ gem.authors = ["scottmotte", "sergiocampama"]
10
+ gem.email = ["scott@scottmotte.com", "sergiocampama@gmail.com"]
11
11
  gem.description = %q{Ruby bindings for the Digital Ocean API.}
12
12
  gem.summary = %q{Ruby bindings for the Digital Ocean API.}
13
13
  gem.homepage = "http://github.com/scottmotte/digitalocean"
data/lib/digitalocean.rb CHANGED
@@ -7,6 +7,9 @@ require "digitalocean/image"
7
7
  require "digitalocean/region"
8
8
  require "digitalocean/size"
9
9
  require "digitalocean/ssh_key"
10
+ require "digitalocean/domain"
11
+ require "digitalocean/record"
12
+
10
13
 
11
14
  module Digitalocean
12
15
  extend self
@@ -0,0 +1,34 @@
1
+ module Digitalocean
2
+ class Domain
3
+ #
4
+ # Api calls
5
+ #
6
+ def self.all
7
+ response = Digitalocean.request.get "domains"
8
+ RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
9
+ end
10
+
11
+ def self.find(domain_id)
12
+ response = Digitalocean.request.get "domains/#{domain_id}"
13
+ RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
14
+ end
15
+
16
+ # attrs = {
17
+ # :name => domain_name,
18
+ # :ip_address => ip_address
19
+ # }
20
+ def self.create(domain_name, ip_address)
21
+ attrs = {
22
+ name: domain_name,
23
+ ip_address: ip_address
24
+ }
25
+ response = Digitalocean.request.get "domains/new", attrs
26
+ RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
27
+ end
28
+
29
+ def self.destroy(domain_id)
30
+ response = Digitalocean.request.get "domains/#{domain_id}/destroy"
31
+ RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
32
+ end
33
+ end
34
+ end
@@ -13,6 +13,11 @@ module Digitalocean
13
13
  RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
14
14
  end
15
15
 
16
+ def self.rename(droplet_id, name)
17
+ response = Digitalocean.request.get "droplets/#{droplet_id}/rename", :name=>name
18
+ RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
19
+ end
20
+
16
21
  def self.reboot(droplet_id=nil)
17
22
  response = Digitalocean.request.get "droplets/#{droplet_id}/reboot"
18
23
  RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
@@ -7,5 +7,17 @@ module Digitalocean
7
7
  response = Digitalocean.request.get "images", attrs
8
8
  RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
9
9
  end
10
+ def self.find(id)
11
+ response = Digitalocean.request.get "images/#{id}"
12
+ RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true).image
13
+ end
14
+ def self.destroy(id)
15
+ response = Digitalocean.request.get "images/#{id}/destroy"
16
+ RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true).image
17
+ end
18
+ def self.transfer(id, region_id)
19
+ response = Digitalocean.request.get "images/#{id}/transfer", { region_id: region_id }
20
+ RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true).image
21
+ end
10
22
  end
11
23
  end
@@ -0,0 +1,62 @@
1
+ module Digitalocean
2
+ class Record
3
+ #
4
+ # Api calls
5
+ #
6
+ def self.all(domain_id)
7
+ response = Digitalocean.request.get "domains/#{domain_id}/records"
8
+ RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
9
+ end
10
+
11
+ def self.find(domain_id, record_id)
12
+ response = Digitalocean.request.get "domains/#{domain_id}/records/#{record_id}"
13
+ RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
14
+ end
15
+
16
+ # attrs = {
17
+ # :domain_id => domain_id || domain_name,
18
+ # :record_type => 'A' || 'CNAME' || 'NS' || 'TXT' || 'MX' || 'SRV',
19
+ # :data => '@' || '123.123.123.123' || ...,
20
+ # :name => optional, required for A, CNAME, TXT, and SRV records,
21
+ # :priority => optional, required for SRV and MX,
22
+ # :port => optional, required for SRV,
23
+ # :weight => optional, required for SRV
24
+ # }
25
+ def self.create(domain_id, record_type, data, name = nil, priority = nil, port = nil, weight = nil)
26
+ attrs = {
27
+ domain_id: domain_id,
28
+ record_type: record_type,
29
+ data: data,
30
+ name: name,
31
+ priority: priority,
32
+ port: port,
33
+ weight: weight,
34
+ }
35
+ response = Digitalocean.request.get "domains/#{domain_id}/records/new", attrs
36
+ RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
37
+ end
38
+
39
+ # attrs = {
40
+ # :domain_id => domain_id || domain_name,
41
+ # :record_type => 'A' || 'CNAME' || 'NS' || 'TXT' || 'MX' || 'SRV',
42
+ # :data => '@' || '123.123.123.123' || ...,
43
+ # :name => optional, required for A, CNAME, TXT, and SRV records,
44
+ # :priority => optional, required for SRV and MX,
45
+ # :port => optional, required for SRV,
46
+ # :weight => optional, required for SRV
47
+ # }
48
+ def self.edit(domain_id, record_id, attrs)
49
+ attrs.merge({
50
+ domain_id: domain_id,
51
+ record_id: record_id
52
+ })
53
+ response = Digitalocean.request.get "domains/#{domain_id}/records/#{record_id}/edit", attrs
54
+ RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
55
+ end
56
+
57
+ def self.destroy(domain_id, record_id)
58
+ response = Digitalocean.request.get "domains/#{domain_id}/records/#{record_id}/destroy"
59
+ RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
60
+ end
61
+ end
62
+ end
@@ -7,5 +7,8 @@ module Digitalocean
7
7
  response = Digitalocean.request.get "regions"
8
8
  RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
9
9
  end
10
+ def self.find(id)
11
+ self.all.regions.detect{|region| region.id == id}
12
+ end
10
13
  end
11
14
  end
@@ -7,5 +7,8 @@ module Digitalocean
7
7
  response = Digitalocean.request.get "sizes"
8
8
  RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
9
9
  end
10
+ def self.find(id)
11
+ self.all.sizes.detect{|size| size.id == id}
12
+ end
10
13
  end
11
14
  end
@@ -14,7 +14,7 @@ module Digitalocean
14
14
  end
15
15
 
16
16
  def self.create(attrs)
17
- response = Digitalocean.request.get "ssh_keys/new"
17
+ response = Digitalocean.request.get "ssh_keys/new", attrs
18
18
  RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
19
19
  end
20
20
  end
@@ -1,3 +1,3 @@
1
1
  module Digitalocean
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe Digitalocean::Domain do
4
+ let(:ok) { "OK" }
5
+ let(:subject) { Digitalocean::Domain }
6
+
7
+ context "correct api key" do
8
+ before do
9
+ set_client_id_and_api_key!
10
+ end
11
+
12
+ describe ".all" do
13
+ before do
14
+ @response = subject.all
15
+ end
16
+
17
+ context "default" do
18
+ it do
19
+ @response.status.should eq ok
20
+ end
21
+ end
22
+
23
+ describe ".find" do
24
+ before do
25
+ domain_id = @response.domains.first.id
26
+ @response2 = subject.find(domain_id)
27
+ end
28
+
29
+ context "default" do
30
+ it do
31
+ @response2.status.should eq ok
32
+ end
33
+ end
34
+ end
35
+
36
+ describe ".create" do
37
+ let(:domain_name) { ["digitalocean_spec_", SecureRandom.hex(15), ".com"].join }
38
+
39
+ before do
40
+ domain = @response.domains.first
41
+ @response_create = subject.create(domain_name, domain.ip_address)
42
+ end
43
+
44
+ context "default" do
45
+ it do
46
+ @response_create.status.should eq ok
47
+ end
48
+ end
49
+ end
50
+
51
+ describe ".destroy" do
52
+ let(:domain_name) { ["digitalocean_spec_", SecureRandom.hex(15), ".com"].join }
53
+
54
+ before do
55
+ droplet = @response.droplets.first
56
+ @response_create = subject.create(domain_name, droplet.ip_address)
57
+ @response_destroy = subject.destroy(@response_create.id)
58
+ end
59
+
60
+ context "default" do
61
+ it do
62
+ @response_destroy.status.should eq ok
63
+ end
64
+ end
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -20,5 +20,20 @@ describe Digitalocean::Image do
20
20
  end
21
21
  end
22
22
  end
23
+
24
+ describe ".find" do
25
+ before do
26
+ image_id = @response.images.first.id
27
+ @response2 = subject.retrieve(image_id)
28
+ end
29
+
30
+ context "default" do
31
+ it do
32
+ @response.status.should eq ok
33
+ end
34
+ end
35
+ end
36
+
37
+
23
38
  end
24
39
  end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe Digitalocean::Record do
4
+ let(:ok) { "OK" }
5
+ let(:subject) { Digitalocean::Record }
6
+
7
+ context "correct api key" do
8
+ before do
9
+ set_client_id_and_api_key!
10
+ end
11
+
12
+ describe ".all" do
13
+ before do
14
+ domain_id = @response.domains.first.id
15
+ @response = subject.all(domain_id)
16
+ end
17
+
18
+ context "default" do
19
+ it do
20
+ @response.status.should eq ok
21
+ end
22
+ end
23
+
24
+ describe ".find" do
25
+ before do
26
+ domain_id = @response.domains.first.id
27
+ record_id = subject.all(domain_id).first.id
28
+ @response2 = subject.find(domain_id, record_id)
29
+ end
30
+
31
+ context "default" do
32
+ it do
33
+ @response2.status.should eq ok
34
+ end
35
+ end
36
+ end
37
+
38
+ describe ".create" do
39
+ let(:domain_name) { ["digitalocean_spec_", SecureRandom.hex(15), ".com"].join }
40
+
41
+ before do
42
+ domain = @response.domains.first
43
+ @response_create = subject.create(domain.id, 'CNAME', 'www', '@')
44
+ end
45
+
46
+ context "default" do
47
+ it do
48
+ @response_create.status.should eq ok
49
+ end
50
+ end
51
+ end
52
+
53
+ describe ".edit" do
54
+
55
+ before do
56
+ domain = @response.domains.first
57
+ record = subject.all(domain.id).first
58
+ @response_create = subject.edit(domain.id, record.id, { data: '@' })
59
+ end
60
+
61
+ context "default" do
62
+ it do
63
+ @response_create.status.should eq ok
64
+ end
65
+ end
66
+ end
67
+
68
+ describe ".destroy" do
69
+
70
+ before do
71
+ domain = @response.domains.first
72
+ record = subject.all(domain.id).first@response_create = subject.create(domain_name, droplet.ip_address)
73
+ @response_destroy = subject.destroy(domain.id, record.id)
74
+ end
75
+
76
+ context "default" do
77
+ it do
78
+ @response_destroy.status.should eq ok
79
+ end
80
+ end
81
+ end
82
+
83
+ end
84
+ end
85
+ end
metadata CHANGED
@@ -1,131 +1,118 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: digitalocean
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - scottmotte
8
+ - sergiocampama
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-09 00:00:00.000000000 Z
12
+ date: 2014-01-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
16
16
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
17
  requirements:
19
- - - ! '>='
18
+ - - '>='
20
19
  - !ruby/object:Gem::Version
21
20
  version: '0'
22
21
  type: :runtime
23
22
  prerelease: false
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
24
  requirements:
27
- - - ! '>='
25
+ - - '>='
28
26
  - !ruby/object:Gem::Version
29
27
  version: '0'
30
28
  - !ruby/object:Gem::Dependency
31
29
  name: faraday_middleware
32
30
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
31
  requirements:
35
- - - ! '>='
32
+ - - '>='
36
33
  - !ruby/object:Gem::Version
37
34
  version: '0'
38
35
  type: :runtime
39
36
  prerelease: false
40
37
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
38
  requirements:
43
- - - ! '>='
39
+ - - '>='
44
40
  - !ruby/object:Gem::Version
45
41
  version: '0'
46
42
  - !ruby/object:Gem::Dependency
47
43
  name: recursive-open-struct
48
44
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
45
  requirements:
51
- - - ! '>='
46
+ - - '>='
52
47
  - !ruby/object:Gem::Version
53
48
  version: '0'
54
49
  type: :runtime
55
50
  prerelease: false
56
51
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
52
  requirements:
59
- - - ! '>='
53
+ - - '>='
60
54
  - !ruby/object:Gem::Version
61
55
  version: '0'
62
56
  - !ruby/object:Gem::Dependency
63
57
  name: foreman
64
58
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
59
  requirements:
67
- - - ! '>='
60
+ - - '>='
68
61
  - !ruby/object:Gem::Version
69
62
  version: '0'
70
63
  type: :development
71
64
  prerelease: false
72
65
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
66
  requirements:
75
- - - ! '>='
67
+ - - '>='
76
68
  - !ruby/object:Gem::Version
77
69
  version: '0'
78
70
  - !ruby/object:Gem::Dependency
79
71
  name: pry
80
72
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
73
  requirements:
83
- - - ! '>='
74
+ - - '>='
84
75
  - !ruby/object:Gem::Version
85
76
  version: '0'
86
77
  type: :development
87
78
  prerelease: false
88
79
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
80
  requirements:
91
- - - ! '>='
81
+ - - '>='
92
82
  - !ruby/object:Gem::Version
93
83
  version: '0'
94
84
  - !ruby/object:Gem::Dependency
95
85
  name: rake
96
86
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
87
  requirements:
99
- - - ! '>='
88
+ - - '>='
100
89
  - !ruby/object:Gem::Version
101
90
  version: '0'
102
91
  type: :development
103
92
  prerelease: false
104
93
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
94
  requirements:
107
- - - ! '>='
95
+ - - '>='
108
96
  - !ruby/object:Gem::Version
109
97
  version: '0'
110
98
  - !ruby/object:Gem::Dependency
111
99
  name: rspec
112
100
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
101
  requirements:
115
- - - ! '>='
102
+ - - '>='
116
103
  - !ruby/object:Gem::Version
117
104
  version: '0'
118
105
  type: :development
119
106
  prerelease: false
120
107
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
108
  requirements:
123
- - - ! '>='
109
+ - - '>='
124
110
  - !ruby/object:Gem::Version
125
111
  version: '0'
126
112
  description: Ruby bindings for the Digital Ocean API.
127
113
  email:
128
114
  - scott@scottmotte.com
115
+ - sergiocampama@gmail.com
129
116
  executables: []
130
117
  extensions: []
131
118
  extra_rdoc_files: []
@@ -139,14 +126,18 @@ files:
139
126
  - Rakefile
140
127
  - digitalocean.gemspec
141
128
  - lib/digitalocean.rb
129
+ - lib/digitalocean/domain.rb
142
130
  - lib/digitalocean/droplet.rb
143
131
  - lib/digitalocean/image.rb
132
+ - lib/digitalocean/record.rb
144
133
  - lib/digitalocean/region.rb
145
134
  - lib/digitalocean/size.rb
146
135
  - lib/digitalocean/ssh_key.rb
147
136
  - lib/digitalocean/version.rb
137
+ - spec/digitalocean/domain_spec.rb
148
138
  - spec/digitalocean/droplet_spec.rb
149
139
  - spec/digitalocean/image_spec.rb
140
+ - spec/digitalocean/record_spec.rb
150
141
  - spec/digitalocean/region_spec.rb
151
142
  - spec/digitalocean/size_spec.rb
152
143
  - spec/digitalocean/ssh_key_spec.rb
@@ -154,39 +145,35 @@ files:
154
145
  - spec/spec_helper.rb
155
146
  homepage: http://github.com/scottmotte/digitalocean
156
147
  licenses: []
148
+ metadata: {}
157
149
  post_install_message:
158
150
  rdoc_options: []
159
151
  require_paths:
160
152
  - lib
161
153
  required_ruby_version: !ruby/object:Gem::Requirement
162
- none: false
163
154
  requirements:
164
- - - ! '>='
155
+ - - '>='
165
156
  - !ruby/object:Gem::Version
166
157
  version: '0'
167
- segments:
168
- - 0
169
- hash: -3599500042094180118
170
158
  required_rubygems_version: !ruby/object:Gem::Requirement
171
- none: false
172
159
  requirements:
173
- - - ! '>='
160
+ - - '>='
174
161
  - !ruby/object:Gem::Version
175
162
  version: '0'
176
- segments:
177
- - 0
178
- hash: -3599500042094180118
179
163
  requirements: []
180
164
  rubyforge_project:
181
- rubygems_version: 1.8.23
165
+ rubygems_version: 2.0.3
182
166
  signing_key:
183
- specification_version: 3
167
+ specification_version: 4
184
168
  summary: Ruby bindings for the Digital Ocean API.
185
169
  test_files:
170
+ - spec/digitalocean/domain_spec.rb
186
171
  - spec/digitalocean/droplet_spec.rb
187
172
  - spec/digitalocean/image_spec.rb
173
+ - spec/digitalocean/record_spec.rb
188
174
  - spec/digitalocean/region_spec.rb
189
175
  - spec/digitalocean/size_spec.rb
190
176
  - spec/digitalocean/ssh_key_spec.rb
191
177
  - spec/digitalocean_spec.rb
192
178
  - spec/spec_helper.rb
179
+ has_rdoc: