barge 0.1.0

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: a3508385a65f762c38891540ba2c37544e4ab89f
4
+ data.tar.gz: 69b2373c7d80246b12f180f531d65f95c6a6ad85
5
+ SHA512:
6
+ metadata.gz: 4aeeeb86c1a73d8a91c443df99c3eb41242d42b8ad431c845bb3b6c01f6f1c047880e03f293cffa68dd4d417d6e0ba68a8cd708d0c0246f980e00696b3c23bc4
7
+ data.tar.gz: d5f51677663b6f0598db96b64cdf3d6f5b019b7659629186d74ffa486e0a71bb648eb5797f811a133c6884d75376120aa27e694c95f0b3b5bf026dacf9f49dfe
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2014 Ørjan Blom
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,332 @@
1
+ Barge
2
+ =====
3
+
4
+ [![Build Status](http://img.shields.io/travis/boats/barge.svg)][travis]
5
+ [![Coverage Status](http://img.shields.io/coveralls/boats/barge.svg)][coveralls]
6
+ [![Code Climate](http://img.shields.io/codeclimate/github/boats/barge.svg)][codeclimate]
7
+ [![Dependency Status](http://img.shields.io/gemnasium/boats/barge.svg)][gemnasium]
8
+
9
+ [travis]: https://travis-ci.org/boats/barge
10
+ [coveralls]: https://coveralls.io/r/boats/barge
11
+ [codeclimate]: https://codeclimate.com/github/boats/barge
12
+ [gemnasium]: https://gemnasium.com/boats/barge
13
+
14
+ Ruby library for version 2 of
15
+ [DigitalOcean's API](https://developers.digitalocean.com/).
16
+
17
+ **Please note that version 2 of DigitalOcean's API is in beta, and is still
18
+ being developed. Everything is subject to change.**
19
+
20
+ ### Installation
21
+
22
+ ``` sh
23
+ gem install barge
24
+ ```
25
+
26
+ Ruby 1.9 and up is required. See the [.travis.yml](.travis.yml) file for a list
27
+ of supported rubies.
28
+
29
+ ### Initialize
30
+
31
+ ``` ruby
32
+ barge = Barge::Client.new(access_token: 'token')
33
+ ```
34
+
35
+ *or*
36
+
37
+ ``` ruby
38
+ barge = Barge::Client.new do |config|
39
+ config.access_token = 'token'
40
+ end
41
+ ```
42
+
43
+ Resources
44
+ =========
45
+
46
+ General
47
+ -------
48
+
49
+ ### Hashie::Mash
50
+
51
+ [Hashie::Mash](https://github.com/intridea/hashie) is used so that attributes
52
+ can be accessed using dot notation:
53
+
54
+ ``` ruby
55
+ droplet = barge.droplet.show(droplet_id)
56
+ droplet.name # => "foo"
57
+ droplet.image.id # => 123
58
+ droplet.size!.vcpus # => 1
59
+ ```
60
+
61
+ Notice that `size!` and not `size` was used. This is because `size` already is
62
+ a method, and Hashie::Mash will not override it. You can also use square
63
+ brackets:
64
+
65
+ ``` ruby
66
+ droplet[:size][:vcpus] # => 1
67
+ droplet['size']['vcpus'] # => 1
68
+ ```
69
+
70
+ ### success?
71
+
72
+ You can use `success?` to check if a successful HTTP status code was returned:
73
+
74
+ ``` ruby
75
+ barge.droplet.create(options).success? # => true
76
+ ```
77
+
78
+ Droplet
79
+ -------
80
+
81
+ ### Create droplet
82
+
83
+ ``` ruby
84
+ barge.droplet.create(options)
85
+ ```
86
+
87
+ See the [API documentation][droplet-create] for options.
88
+
89
+ [droplet-create]: https://github.com/digitaloceancloud/api-v2-docs#droplet-create-post
90
+
91
+ ### Show all droplets
92
+
93
+ ``` ruby
94
+ barge.droplet.all
95
+ ```
96
+
97
+ ### Show droplet
98
+
99
+ ``` ruby
100
+ barge.droplet.show(droplet_id)
101
+ ```
102
+
103
+ ### Destroy droplet
104
+
105
+ ``` ruby
106
+ barge.droplet.destroy(droplet_id)
107
+ ```
108
+
109
+ ### Rename droplet
110
+
111
+ ``` ruby
112
+ barge.droplet.rename(droplet_id, 'new name')
113
+ ```
114
+
115
+ ### Reboot droplet
116
+
117
+ ``` ruby
118
+ barge.droplet.reboot(droplet_id)
119
+ ```
120
+
121
+ ### Shutdown droplet
122
+
123
+ ``` ruby
124
+ barge.droplet.shutdown(droplet_id)
125
+ ```
126
+
127
+ ### Power off droplet
128
+
129
+ ``` ruby
130
+ barge.droplet.power_off(droplet_id)
131
+ ```
132
+
133
+ ### Power cycle droplet
134
+
135
+ ``` ruby
136
+ barge.droplet.power_cycle(droplet_id)
137
+ ```
138
+
139
+ ### Power on droplet
140
+
141
+ ``` ruby
142
+ barge.droplet.power_on(droplet_id)
143
+ ```
144
+
145
+ ### Resize droplet
146
+
147
+ ``` ruby
148
+ barge.droplet.resize(droplet_id, 'size slug')
149
+ ```
150
+
151
+ Where *size slug* is for example `1024mb`.
152
+
153
+ ### Rebuild droplet
154
+
155
+ ``` ruby
156
+ barge.droplet.rebuild(droplet_id, image_id)
157
+ ```
158
+
159
+ ### Restore droplet
160
+
161
+ ``` ruby
162
+ barge.droplet.restore(droplet_id, image_id)
163
+ ```
164
+
165
+ ### Reset a droplet's password
166
+
167
+ ``` ruby
168
+ barge.droplet.password_reset(droplet_id)
169
+ ```
170
+
171
+ Image
172
+ -----
173
+
174
+ ### Show all images
175
+
176
+ ``` ruby
177
+ barge.image.all
178
+ ```
179
+
180
+ ### Show image
181
+
182
+ By ID:
183
+
184
+ ``` ruby
185
+ barge.image.show(image_id)
186
+ ```
187
+
188
+ By image slug (public images):
189
+
190
+ ``` ruby
191
+ barge.image.show('image slug')
192
+ ```
193
+
194
+ Where *image slug* is for example `ubuntu-13-10-x64`.
195
+
196
+ ### Update image
197
+
198
+ ``` ruby
199
+ barge.image.update(image_id, options)
200
+ ```
201
+
202
+ See the [API documentation][image-update] for options.
203
+
204
+ [image-update]: https://github.com/digitaloceancloud/api-v2-docs#images-update-put
205
+
206
+ ### Destroy image
207
+
208
+ ``` ruby
209
+ barge.image.destroy(image_id)
210
+ ```
211
+
212
+ ### Transfer image
213
+
214
+ ``` ruby
215
+ barge.image.transfer(image_id, 'region slug')
216
+ ```
217
+
218
+ Where *region slug* is for example `sfo1`.
219
+
220
+ Domain
221
+ ------
222
+
223
+ ### Create domain
224
+
225
+ ``` ruby
226
+ barge.domain.create(options)
227
+ ```
228
+
229
+ See the [API documentation][domain-create] for options.
230
+
231
+ [domain-create]: https://github.com/digitaloceancloud/api-v2-docs#domain-records-create-post
232
+
233
+ ### Show all domains
234
+
235
+ ``` ruby
236
+ barge.domain.all
237
+ ```
238
+
239
+ ### Show domain
240
+
241
+ ``` ruby
242
+ barge.domain.show(domain_name)
243
+ ```
244
+
245
+ ### Destroy domain
246
+
247
+ ``` ruby
248
+ barge.domain.destroy(domain_name)
249
+ ```
250
+
251
+ ### Create domain record
252
+
253
+ ``` ruby
254
+ barge.domain.create_record(domain_name, options)
255
+ ```
256
+
257
+ See the [API documentation][domain-create-record] for options.
258
+
259
+ [domain-create-record]: https://github.com/digitaloceancloud/api-v2-docs#domain-records-create-post
260
+
261
+ ### Show all domain records
262
+
263
+ ``` ruby
264
+ barge.domain.records
265
+ ```
266
+
267
+ ### Show domain record
268
+
269
+ ``` ruby
270
+ barge.domain.show_record(domain_name, record_id)
271
+ ```
272
+
273
+ ### Update domain record
274
+
275
+ ``` ruby
276
+ barge.domain.update_record(domain_name, record_id, options)
277
+ ```
278
+
279
+ ### Destroy domain record
280
+
281
+ ``` ruby
282
+ barge.domain.destroy_record(domain_name, record_id)
283
+ ```
284
+
285
+ Key
286
+ ---
287
+
288
+ ### Create key
289
+
290
+ ``` ruby
291
+ barge.key.create(options)
292
+ ```
293
+
294
+ See the [API documentation][key-create] for options.
295
+
296
+ [key-create]: https://github.com/digitaloceancloud/api-v2-docs#keys-create-post
297
+
298
+ ### Show all keys
299
+
300
+ ``` ruby
301
+ barge.key.all
302
+ ```
303
+
304
+ ### Show key
305
+
306
+ ``` ruby
307
+ barge.key.show(key_id_or_fingerprint)
308
+ ```
309
+
310
+ ### Destroy key
311
+
312
+ ``` ruby
313
+ barge.key.destroy(key_id)
314
+ ```
315
+
316
+ Region
317
+ ------
318
+
319
+ ### Show all regions
320
+
321
+ ``` ruby
322
+ barge.region.all
323
+ ```
324
+
325
+ Size
326
+ ----
327
+
328
+ ### Show all sizes
329
+
330
+ ``` ruby
331
+ barge.size.all
332
+ ```
@@ -0,0 +1,62 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ module Barge
5
+ class Client
6
+ attr_accessor :access_token
7
+
8
+ attr_reader :domain
9
+ attr_reader :droplet
10
+ attr_reader :image
11
+ attr_reader :key
12
+ attr_reader :region
13
+ attr_reader :size
14
+
15
+ DEFAULT_OPTIONS = {}
16
+ DIGITAL_OCEAN_URL = 'https://api.digitalocean.com/v2'
17
+ TIMEOUTS = 10
18
+
19
+ def initialize(options = DEFAULT_OPTIONS)
20
+ self.access_token = options.fetch(:access_token, nil)
21
+ yield(self) if block_given?
22
+ fail ArgumentError, 'missing access_token' unless access_token
23
+ initialize_resources
24
+ end
25
+
26
+ private
27
+
28
+ def initialize_resources
29
+ @domain = Resource::Domain.new(faraday)
30
+ @droplet = Resource::Droplet.new(faraday)
31
+ @image = Resource::Image.new(faraday)
32
+ @key = Resource::Key.new(faraday)
33
+ @region = Resource::Region.new(faraday)
34
+ @size = Resource::Size.new(faraday)
35
+ end
36
+
37
+ def faraday
38
+ @faraday ||= Faraday.new faraday_options do |f|
39
+ f.adapter :net_http
40
+
41
+ f.request :json
42
+
43
+ f.response :follow_redirects
44
+ f.response :mashify
45
+ f.response :json
46
+
47
+ f.options.open_timeout = TIMEOUTS
48
+ f.options.timeout = TIMEOUTS
49
+ end
50
+ end
51
+
52
+ def faraday_options
53
+ {
54
+ headers: {
55
+ authorization: "Bearer #{access_token}",
56
+ content_type: 'application/json'
57
+ },
58
+ url: DIGITAL_OCEAN_URL
59
+ }
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,27 @@
1
+ module Barge
2
+ module Resource
3
+ module Base
4
+ attr_reader :faraday
5
+
6
+ def initialize(faraday)
7
+ @faraday = faraday
8
+ end
9
+
10
+ private
11
+
12
+ [:delete, :get, :head, :post, :put].each do |verb|
13
+ define_method verb do |*args|
14
+ request(__method__, *args)
15
+ end
16
+ end
17
+
18
+ def request(verb, *args)
19
+ response = faraday.public_send(verb, *args)
20
+ response.body.tap do |r|
21
+ r.define_singleton_method(:response) { response }
22
+ r.define_singleton_method(:success?) { response.success? }
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,43 @@
1
+ module Barge
2
+ module Resource
3
+ class Domain
4
+ include Resource::Base
5
+
6
+ def create(options)
7
+ post('domains', options.to_json)
8
+ end
9
+
10
+ def all
11
+ get('domains')
12
+ end
13
+
14
+ def show(domain_name)
15
+ get("domains/#{domain_name}")
16
+ end
17
+
18
+ def destroy(domain_name)
19
+ delete("domains/#{domain_name}")
20
+ end
21
+
22
+ def create_record(domain_name, options)
23
+ post("domains/#{domain_name}/records", options.to_json)
24
+ end
25
+
26
+ def records(domain_name)
27
+ get("domains/#{domain_name}/records")
28
+ end
29
+
30
+ def show_record(domain_name, record_id)
31
+ get("domains/#{domain_name}/records/#{record_id}")
32
+ end
33
+
34
+ def update_record(domain_name, record_id, options)
35
+ put("domains/#{domain_name}/records/#{record_id}", options.to_json)
36
+ end
37
+
38
+ def destroy_record(domain_name, record_id)
39
+ delete("domains/#{domain_name}/records/#{record_id}")
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,70 @@
1
+ module Barge
2
+ module Resource
3
+ class Droplet
4
+ include Resource::Base
5
+
6
+ def create(options)
7
+ post('droplets', options.to_json)
8
+ end
9
+
10
+ def all
11
+ get('droplets')
12
+ end
13
+
14
+ def show(droplet_id)
15
+ get("droplets/#{droplet_id}")
16
+ end
17
+
18
+ def destroy(droplet_id)
19
+ delete("droplets/#{droplet_id}")
20
+ end
21
+
22
+ def rename(droplet_id, name)
23
+ action(droplet_id, __method__, name: name)
24
+ end
25
+
26
+ def reboot(droplet_id)
27
+ action(droplet_id, __method__)
28
+ end
29
+
30
+ def shutdown(droplet_id)
31
+ action(droplet_id, __method__)
32
+ end
33
+
34
+ def power_off(droplet_id)
35
+ action(droplet_id, __method__)
36
+ end
37
+
38
+ def power_cycle(droplet_id)
39
+ action(droplet_id, __method__)
40
+ end
41
+
42
+ def power_on(droplet_id)
43
+ action(droplet_id, __method__)
44
+ end
45
+
46
+ def resize(droplet_id, size)
47
+ action(droplet_id, __method__, size: size)
48
+ end
49
+
50
+ def rebuild(droplet_id, image_id)
51
+ action(droplet_id, __method__, image: image_id)
52
+ end
53
+
54
+ def restore(droplet_id, image_id)
55
+ action(droplet_id, __method__, image: image_id)
56
+ end
57
+
58
+ def password_reset(droplet_id)
59
+ action(droplet_id, __method__)
60
+ end
61
+
62
+ private
63
+
64
+ def action(droplet_id, type, params = {})
65
+ post("droplets/#{droplet_id}/actions",
66
+ { type: type, params: params }.to_json)
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,34 @@
1
+ module Barge
2
+ module Resource
3
+ class Image
4
+ include Resource::Base
5
+
6
+ def all
7
+ get('images')
8
+ end
9
+
10
+ def show(image_id)
11
+ get("images/#{image_id}")
12
+ end
13
+
14
+ def update(image_id, options)
15
+ put("images/#{image_id}", options.to_json)
16
+ end
17
+
18
+ def destroy(image_id)
19
+ delete("images/#{image_id}")
20
+ end
21
+
22
+ def transfer(image_id, region)
23
+ action(image_id, __method__, region: region)
24
+ end
25
+
26
+ private
27
+
28
+ def action(image_id, type, params = {})
29
+ post("images/#{image_id}/actions",
30
+ { type: type, params: params }.to_json)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ module Barge
2
+ module Resource
3
+ class Key
4
+ include Resource::Base
5
+
6
+ def create(options)
7
+ post('account/keys', options.to_json)
8
+ end
9
+
10
+ def all
11
+ get('account/keys')
12
+ end
13
+
14
+ def show(key_id)
15
+ get("account/keys/#{key_id}")
16
+ end
17
+
18
+ def destroy(key_id)
19
+ delete("account/keys/#{key_id}")
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ module Barge
2
+ module Resource
3
+ class Region
4
+ include Resource::Base
5
+
6
+ def all
7
+ get('regions')
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Barge
2
+ module Resource
3
+ class Size
4
+ include Resource::Base
5
+
6
+ def all
7
+ get('sizes')
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require 'barge/resource/base'
2
+
3
+ require 'barge/resource/domain'
4
+ require 'barge/resource/droplet'
5
+ require 'barge/resource/image'
6
+ require 'barge/resource/key'
7
+ require 'barge/resource/region'
8
+ require 'barge/resource/size'
9
+
10
+ module Barge
11
+ module Resource
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Barge
2
+ class Version
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ PATCH = 0
6
+
7
+ def self.to_s
8
+ [MAJOR, MINOR, PATCH].join '.'
9
+ end
10
+ end
11
+ end
data/lib/barge.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'hashie'
2
+
3
+ require 'barge/client'
4
+ require 'barge/resource'
5
+ require 'barge/version'
6
+
7
+ module Barge
8
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: barge
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "Ørjan Blom"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hashie
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Ruby library for version 2 of DigitalOcean's API
56
+ email:
57
+ - blom@blom.tv
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE
63
+ - README.md
64
+ - lib/barge.rb
65
+ - lib/barge/client.rb
66
+ - lib/barge/resource.rb
67
+ - lib/barge/resource/base.rb
68
+ - lib/barge/resource/domain.rb
69
+ - lib/barge/resource/droplet.rb
70
+ - lib/barge/resource/image.rb
71
+ - lib/barge/resource/key.rb
72
+ - lib/barge/resource/region.rb
73
+ - lib/barge/resource/size.rb
74
+ - lib/barge/version.rb
75
+ homepage: https://github.com/boats/barge
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 1.9.2
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Ruby library for DigitalOcean
99
+ test_files: []
100
+ has_rdoc: