digitalocean_c 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bb5055e68d4065d4dcff591e3c83035b55bce311
4
+ data.tar.gz: b37dc7aaecc8ac9e245d6c0cd1eb8b7c940f33f5
5
+ SHA512:
6
+ metadata.gz: 45bc0fefca29a202fb5c5c6481ba1f19e6c2803f8ad516b13947b071f484f12254b470ac3765198544027dd63ea2e189b3682471360d30a22c24fb1311201ed8
7
+ data.tar.gz: 1507e8c87e78bca48c3a8bc618c6f236b2887f0e08ce3f0084e4ac86c8f449f4d5c78f02810336b16b755ee240c79b551185a0a4bb2dbaef61b52e448ceabc52
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .env
19
+ .idea
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1 @@
1
+ script: "bundle exec rspec"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in digitalocean.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Scott Motte
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,155 @@
1
+ # Digitalocean Rubygem with Updated Faraday version
2
+
3
+ ![](https://raw.github.com/scottmotte/digitalocean/master/digitalocean-rubygem.jpg)
4
+
5
+ ### The easiest and most complete rubygem for [DigitalOcean](https://www.digitalocean.com).
6
+
7
+ [![Build Status](https://travis-ci.org/scottmotte/digitalocean.svg?branch=master)](https://travis-ci.org/scottmotte/digitalocean)
8
+ [![Gem Version](https://badge.fury.io/rb/digitalocean.svg)](http://badge.fury.io/rb/digitalocean)
9
+
10
+ ```ruby
11
+ Digitalocean.client_id = "your_client_id"
12
+ Digitalocean.api_key = "your_api_key"
13
+ result = Digitalocean::Droplet.all
14
+ # =>
15
+ # <RecursiveOpenStruct status="OK", droplets=[
16
+ # {"id"=>12345, "name"=>"dev", "image_id"=>2676, "size_id"=>63, "region_id"=>3, "backups_active"=>false, "ip_address"=>"198.555.55.55", "private_ip_address"=>nil, "locked"=>false, "status"=>"active", "created_at"=>"2013-06-12T03:07:14Z"},
17
+ # {"id"=>234674, "name"=>"server2", "image_id"=>441012, "size_id"=>62, "region_id"=>1, "backups_active"=>false, "ip_address"=>"192.555.55.56", "private_ip_address"=>nil, "locked"=>false, "status"=>"active", "created_at"=>"2013-06-17T00:30:12Z"}
18
+ # ]>
19
+ #
20
+
21
+ result.status
22
+ result.droplets
23
+ result.droplets.first.ip_address
24
+ ```
25
+
26
+ ## Installation
27
+
28
+ Add this line to your application's Gemfile:
29
+
30
+ ```
31
+ gem 'digitalocean_c'
32
+ ```
33
+
34
+ And then execute:
35
+
36
+ ```
37
+ bundle
38
+ ```
39
+
40
+ Or install it yourself as:
41
+
42
+ ```
43
+ gem install digitalocean_c
44
+ ```
45
+
46
+ Then in your application initialize the gem:
47
+
48
+ ```ruby
49
+ Digitalocean.client_id = "your_client_id"
50
+ Digitalocean.api_key = "your_api_key"
51
+ ```
52
+
53
+ You can find your keys at [https://cloud.digitalocean.com/api_access](https://cloud.digitalocean.com/api_access)
54
+
55
+ [![](https://raw2.github.com/scottmotte/digitalocean/master/example.png)](https://cloud.digitalocean.com/api_access)
56
+
57
+ ## Usage
58
+
59
+ ### List Droplets
60
+
61
+ ```ruby
62
+ Digitalocean::Droplet.all
63
+ ```
64
+
65
+ ### Find Droplet
66
+
67
+ ```ruby
68
+ Digitalocean::Droplet.find("id_of_droplet")
69
+ ```
70
+
71
+ ### Create Droplet
72
+
73
+ ```ruby
74
+ Digitalocean::Droplet.create({:name => droplet_name, :size_id => size_id, :image_id => image_id, :region_id => region_id})
75
+ ```
76
+ ## Available Commands
77
+
78
+ ```ruby
79
+ Digitalocean::Domain.all
80
+ Digitalocean::Domain.find(id)
81
+ Digitalocean::Domain.create({name: name, ip_address: ip_address})
82
+ Digitalocean::Domain.destroy(id)
83
+
84
+ Digitalocean::Droplet.all
85
+ Digitalocean::Droplet.find(id)
86
+ Digitalocean::Droplet.rename(id, {name: name})
87
+ Digitalocean::Droplet.reboot(id)
88
+ Digitalocean::Droplet.power_cycle(id)
89
+ Digitalocean::Droplet.shutdown(id)
90
+ Digitalocean::Droplet.power_off(id)
91
+ Digitalocean::Droplet.power_on(id)
92
+ Digitalocean::Droplet.snapshot(id, {name: name})
93
+ Digitalocean::Droplet.create({name: name, size_id: size_id, image_id: image_id, region_id: region_id, ssh_key_ids: ssh_key_ids})
94
+ Digitalocean::Droplet.destroy(id)
95
+ Digitalocean::Droplet.resize(id, {size_id: size_id})
96
+
97
+ Digitalocean::Image.all
98
+ Digitalocean::Image.all({filter: "my_images"})
99
+ Digitalocean::Image.find(id)
100
+ Digitalocean::Image.destroy(id)
101
+ Digitalocean::Image.transfer(id, {region_id: region_id})
102
+
103
+ Digitalocean::Record.all(domain_id)
104
+ Digitalocean::Record.find(domain_id, record_id)
105
+ Digitalocean::Record.create(domain_id, {record_type: record_type, data: data})
106
+ Digitalocean::Record.edit(domain_id, record_id, {record_type: record_type, data: data})
107
+ Digitalocean::Record.destroy(domain_id, record_id)
108
+
109
+ Digitalocean::Region.all
110
+ Digitalocean::Region.find(region_id)
111
+
112
+ Digitalocean::Size.all
113
+ Digitalocean::Size.find(size_id)
114
+
115
+ Digitalocean::SshKey.all
116
+ Digitalocean::SshKey.find(id)
117
+ Digitalocean::SshKey.create({name: name, ssh_pub_key: ssh_pub_key}) # Keep in mind you have to use CGI::escape for your ssh_pub_key
118
+
119
+ Digitalocean::Event.find(id)
120
+ ```
121
+
122
+ ## Example
123
+
124
+ There is a [digitalocean-rubygem-example](https://github.com/scottmotte/digitalocean-rubygem-example) to help jumpstart your development.
125
+
126
+ ## Options
127
+
128
+ ```ruby
129
+ Digitalocean.verify_ssl = false # optionally set this to false. defaults to true.
130
+ ```
131
+
132
+ ## Contributing
133
+
134
+ 1. Fork it
135
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
136
+ 5. Commit your changes (`git commit -am 'Add some feature'`)
137
+ 6. Push to the branch (`git push origin my-new-feature`)
138
+ 7. Create new Pull Request
139
+
140
+ When adding methods, add to the list of DEFINITIONS in `lib/digitalocean.rb`. Additionally, write a spec and add it to the list in the README.
141
+
142
+ ## Running Specs
143
+
144
+ ```
145
+ bundle exec rspec spec/*
146
+ ```
147
+
148
+ ## Publish to RubyGems.org
149
+
150
+ You first need to request access from [scottmotte](http://github.com/scottmotte).
151
+
152
+ ```
153
+ gem build digitalocean.gemspec
154
+ gem push digitalocean-1.0.1.gem
155
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
Binary file
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'digitalocean/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "digitalocean_c"
8
+ gem.version = Digitalocean::VERSION
9
+ gem.authors = ["scottmotte", "sergiocampama"]
10
+ gem.email = ["scott@scottmotte.com", "sergiocampama@gmail.com"]
11
+ gem.description = %q{Ruby bindings for the Digital Ocean API.}
12
+ gem.summary = %q{Ruby bindings for the Digital Ocean API.}
13
+ gem.homepage = "http://github.com/merqlove/digitalocean_c"
14
+
15
+ gem.add_dependency "faraday", "~> 0.9.1"
16
+ gem.add_dependency "faraday_middleware", "~> 0.9.0"
17
+ gem.add_dependency "recursive-open-struct", "~> 0.4.5"
18
+
19
+ gem.add_development_dependency "foreman"
20
+ gem.add_development_dependency "pry"
21
+ gem.add_development_dependency "rake"
22
+ gem.add_development_dependency "rspec"
23
+ gem.add_development_dependency "rspec-its"
24
+
25
+ gem.files = `git ls-files`.split($/)
26
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
27
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
28
+ gem.require_paths = ["lib"]
29
+ end
data/example.png ADDED
Binary file
@@ -0,0 +1,217 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "recursive-open-struct"
4
+ require "digitalocean/version"
5
+
6
+ module Digitalocean
7
+ extend self
8
+
9
+ DEFINITIONS = {
10
+ "Domain" => {
11
+ "all" => "https://api.digitalocean.com/v1/domains?client_id=[your_client_id]&api_key=[your_api_key]",
12
+ "find" => "https://api.digitalocean.com/v1/domains/[domain_id]?client_id=[your_client_id]&api_key=[your_api_key]",
13
+ "create" => "https://api.digitalocean.com/v1/domains/new?client_id=[your_client_id]&api_key=[your_api_key]&name=[domain]&ip_address=[ip_address]",
14
+ "destroy" => "https://api.digitalocean.com/v1/domains/[domain_id]/destroy?client_id=[your_client_id]&api_key=[your_api_key]"
15
+ },
16
+ "Droplet" => {
17
+ "all" => "https://api.digitalocean.com/v1/droplets/?client_id=[your_client_id]&api_key=[your_api_key]",
18
+ "find" => "https://api.digitalocean.com/v1/droplets/[droplet_id]?client_id=[your_client_id]&api_key=[your_api_key]",
19
+ "rename" => "https://api.digitalocean.com/v1/droplets/[droplet_id]/rename/?client_id=[your_client_id]&api_key=[your_api_key]&name=[name]",
20
+ "rebuild" => "https://api.digitalocean.com/v1/droplets/[droplet_id]/rebuild/?image_id=[image_id]&client_id=[client_id]&api_key=[api_key]",
21
+ "reboot" => "https://api.digitalocean.com/v1/droplets/[droplet_id]/reboot/?client_id=[your_client_id]&api_key=[your_api_key]",
22
+ "power_cycle" => "https://api.digitalocean.com/v1/droplets/[droplet_id]/power_cycle/?client_id=[your_client_id]&api_key=[your_api_key]",
23
+ "shutdown" => "https://api.digitalocean.com/v1/droplets/[droplet_id]/shutdown/?client_id=[your_client_id]&api_key=[your_api_key]",
24
+ "power_off" => "https://api.digitalocean.com/v1/droplets/[droplet_id]/power_off/?client_id=[your_client_id]&api_key=[your_api_key]",
25
+ "power_on" => "https://api.digitalocean.com/v1/droplets/[droplet_id]/power_on/?client_id=[your_client_id]&api_key=[your_api_key]",
26
+ "snapshot" => "https://api.digitalocean.com/v1/droplets/[droplet_id]/snapshot/?name=[snapshot_name]&client_id=[your_client_id]&api_key=[your_api_key]",
27
+ "create" => "https://api.digitalocean.com/v1/droplets/new?client_id=[your_client_id]&api_key=[your_api_key]&name=[droplet_name]&size_id=[size_id]&image_id=[image_id]&region_id=[region_id]&ssh_key_ids=[ssh_key_ids]&private_networking=[private_networking]&backups_enabled=[backups_enabled]", # unique case that is not copy/paste
28
+ "destroy" => "https://api.digitalocean.com/v1/droplets/[droplet_id]/destroy/?client_id=[your_client_id]&api_key=[your_api_key]",
29
+ "resize" => "https://api.digitalocean.com/v1/droplets/[droplet_id]/resize/?size_id=[size_id]&client_id=[client_id]&api_key=[api_key]"
30
+ },
31
+ "Image" => {
32
+ "all" => "https://api.digitalocean.com/v1/images/?client_id=[your_client_id]&api_key=[your_api_key]",
33
+ "find" => "https://api.digitalocean.com/v1/images/[image_id]/?client_id=[your_client_id]&api_key=[your_api_key]",
34
+ "destroy" => "https://api.digitalocean.com/v1/images/[image_id]/destroy/?client_id=[your_client_id]&api_key=[your_api_key]",
35
+ "transfer" => "https://api.digitalocean.com/v1/images/[image_id]/transfer/?client_id=[your_client_id]&api_key=[your_api_key]&region_id=[region_id]"
36
+ },
37
+ "Record" => {
38
+ "all" => "https://api.digitalocean.com/v1/domains/[domain_id]/records?client_id=[your_client_id]&api_key=[your_api_key]",
39
+ "find" => "https://api.digitalocean.com/v1/domains/[domain_id]/records/[record_id]?client_id=[your_client_id]&api_key=[your_api_key]",
40
+ "create" => "https://api.digitalocean.com/v1/domains/[domain_id]/records/new?client_id=[your_client_id]&api_key=[your_api_key]&record_type=[record_type]&data=[data]",
41
+ "edit" => "https://api.digitalocean.com/v1/domains/[domain_id]/records/[record_id]/edit?client_id=[your_client_id]&api_key=[your_api_key]",
42
+ "destroy" => "https://api.digitalocean.com/v1/domains/[domain_id]/records/[record_id]/destroy?client_id=[your_client_id]&api_key=[your_api_key]"
43
+ },
44
+ "Region" => {
45
+ "all" => "https://api.digitalocean.com/v1/regions/?client_id=[your_client_id]&api_key=[your_api_key]",
46
+ "find" => "https://api.digitalocean.com/v1/regions/[region_id]?client_id=[your_client_id]&api_key=[your_api_key]"
47
+ },
48
+ "Size" => {
49
+ "all" => "https://api.digitalocean.com/v1/sizes/?client_id=[your_client_id]&api_key=[your_api_key]",
50
+ "find" => "https://api.digitalocean.com/v1/sizes/[size_id]?client_id=[your_client_id]&api_key=[your_api_key]"
51
+ },
52
+ "SshKey" => {
53
+ "all" => "https://api.digitalocean.com/v1/ssh_keys/?client_id=[your_client_id]&api_key=[your_api_key]",
54
+ "find" => "https://api.digitalocean.com/v1/ssh_keys/[ssh_key_id]/?client_id=[your_client_id]&api_key=[your_api_key]",
55
+ "edit" => "https://api.digitalocean.com/v1/ssh_keys/[ssh_key_id]/edit/?name=[ssh_key_name]&ssh_pub_key=[ssh_public_key]&client_id=[client_id]&api_key=[api_key]",
56
+ "create" => "https://api.digitalocean.com/v1/ssh_keys/new/?name=[ssh_key_name]&ssh_pub_key=[ssh_public_key]&client_id=[your_client_id]&api_key=[your_api_key]",
57
+ "destroy" => "https://api.digitalocean.com/v1/ssh_keys/[ssh_key_id]/destroy/?client_id=[your_client_id]&api_key=[your_api_key]"
58
+ },
59
+ "Event" => {
60
+ "find" => "https://api.digitalocean.com/v1/events/[event_id]/?client_id=[your_client_id]&api_key=[your_api_key]"
61
+ }
62
+ }
63
+
64
+ DEFINITIONS.each do |resource|
65
+ resource_name = resource[0]
66
+
67
+ resource_class = Class.new(Object) do
68
+ # http://stackoverflow.com/questions/3026943/define-method-for-instance-of-class
69
+ singleton = class << self; self end
70
+
71
+ DEFINITIONS[resource_name].each do |method_name, url|
72
+ parts = url.split("?")
73
+ pre_query = parts[0]
74
+ post_query = parts[1]
75
+
76
+ singleton.send :define_method, "_#{method_name}" do |*args|
77
+ pre_query_for_method = Digitalocean.process_standard_args_from_part(pre_query, args)
78
+ post_query_for_method = Digitalocean.process_hash_args_from_part(post_query, args)
79
+
80
+ [pre_query_for_method, post_query_for_method].join("?")
81
+ end
82
+
83
+ singleton.send :define_method, method_name do |*args|
84
+ Digitalocean.request_and_respond send("_#{method_name}", *args)
85
+ end
86
+ end
87
+ end
88
+
89
+ Digitalocean.const_set(resource_name, resource_class)
90
+ end
91
+
92
+ def request=(request)
93
+ @request = request
94
+ end
95
+
96
+ def request
97
+ @request
98
+ end
99
+
100
+ def client_id=(client_id)
101
+ @client_id = client_id
102
+ setup_request!
103
+
104
+ @client_id
105
+ end
106
+
107
+ def client_id
108
+ return @client_id if @client_id
109
+ "client_id_required"
110
+ end
111
+
112
+ def api_key=(api_key)
113
+ @api_key = api_key
114
+ setup_request!
115
+
116
+ @api_key
117
+ end
118
+
119
+ def api_key
120
+ return @api_key if @api_key
121
+ "api_key_required"
122
+ end
123
+
124
+ def verify_ssl=(verify_ssl)
125
+ @verify_ssl = verify_ssl
126
+ setup_request!
127
+
128
+ @verify_ssl
129
+ end
130
+
131
+ def verify_ssl
132
+ return @verify_ssl if @verify_ssl != nil
133
+ true
134
+ end
135
+
136
+ def api_endpoint
137
+ "https://api.digitalocean.com"
138
+ end
139
+
140
+ def request_and_respond(url)
141
+ resp = Digitalocean.request.get url
142
+ hash = RecursiveOpenStruct.new(resp.body, :recurse_over_arrays => true)
143
+
144
+ hash
145
+ end
146
+
147
+ def process_standard_args_from_part(part, args)
148
+ parts = part.split(/\[|\]/)
149
+
150
+ if parts.length > 1
151
+ parts.each_with_index do |v, i|
152
+ is_every_other = (i%2 == 1)
153
+ parts[i] = args.shift if is_every_other
154
+ end
155
+ end
156
+
157
+ parts.join("")
158
+ end
159
+
160
+ def process_client_id_and_api_key(parts)
161
+ # Begin by taking care of the client_id and api_key
162
+ client_id_index = parts.index "client_id="
163
+ client_id_index = parts.index "&client_id=" if !client_id_index
164
+ parts[client_id_index+1] = client_id if client_id_index
165
+
166
+ api_key_index = parts.index "api_key="
167
+ api_key_index = parts.index "&api_key=" if !api_key_index
168
+ parts[api_key_index+1] = api_key if api_key_index
169
+
170
+ parts
171
+ end
172
+
173
+ def process_hash_args_from_part(part, args)
174
+ parts = part.split(/\[|\]/)
175
+ parts = process_client_id_and_api_key(parts)
176
+
177
+ hash = args[-1]
178
+ if hash.is_a?(Hash)
179
+ if parts.length > 1
180
+ hash.each do |key, value|
181
+ query_setter = "#{key}="
182
+ query_arg_index = parts.index query_setter
183
+ query_arg_index = parts.index "&#{query_setter}" if !query_arg_index # handle case of ampersand
184
+
185
+ if query_arg_index != nil
186
+ parts[query_arg_index+1] = value
187
+ hash.delete(key) # cleanup
188
+ end
189
+ end
190
+ end
191
+
192
+ # append any additional hash arguments (optional params)
193
+ hash.each do |key, value|
194
+ appendable_param = "&#{key}=#{value}"
195
+ parts.push(appendable_param)
196
+ end
197
+ end
198
+
199
+ parts.join("")
200
+ end
201
+
202
+ private
203
+
204
+ def setup_request!
205
+ options = {
206
+ :headers => {'Accept' => "application/json"},
207
+ :ssl => {:verify => verify_ssl}
208
+ }
209
+
210
+ Digitalocean.request = ::Faraday::Connection.new(options) do |builder|
211
+ builder.use ::Faraday::Request::UrlEncoded
212
+ builder.use ::FaradayMiddleware::ParseJson
213
+ builder.use ::FaradayMiddleware::FollowRedirects
214
+ builder.adapter ::Faraday.default_adapter
215
+ end
216
+ end
217
+ end
@@ -0,0 +1,3 @@
1
+ module Digitalocean
2
+ VERSION = "1.2.0"
3
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Digitalocean::Domain do
4
+ subject(:domain) { described_class }
5
+
6
+ describe "._all" do
7
+ let(:url) { domain._all }
8
+ it { url.should eq "https://api.digitalocean.com/v1/domains?client_id=client_id_required&api_key=api_key_required" }
9
+ end
10
+
11
+ describe "._find" do
12
+ let(:domain_id) { "1234" }
13
+ let(:url) { domain._find(domain_id) }
14
+
15
+ it { url.should eq "https://api.digitalocean.com/v1/domains/#{domain_id}?client_id=client_id_required&api_key=api_key_required" }
16
+ end
17
+
18
+ describe "._create" do
19
+ let(:name) { "test_domain" }
20
+ let(:ip_address) { "test_ip_address" }
21
+ let(:args) { { name: name, ip_address: ip_address } }
22
+
23
+ let(:url) { domain._create(args) }
24
+
25
+ it { url.should eq "https://api.digitalocean.com/v1/domains/new?client_id=client_id_required&api_key=api_key_required&name=test_domain&ip_address=test_ip_address" }
26
+ end
27
+
28
+ describe "._destroy" do
29
+ let(:domain_id) { "test_domain_id" }
30
+ let(:url) { domain._destroy(domain_id) }
31
+
32
+ it { url.should eq "https://api.digitalocean.com/v1/domains/test_domain_id/destroy?client_id=client_id_required&api_key=api_key_required" }
33
+ end
34
+ end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ describe Digitalocean::Droplet do
4
+ subject(:droplet) { described_class }
5
+
6
+ describe "._all" do
7
+ let(:url) { droplet._all }
8
+ it { url.should eq "https://api.digitalocean.com/v1/droplets/?client_id=client_id_required&api_key=api_key_required" }
9
+ end
10
+
11
+ describe "._find" do
12
+ let(:droplet_id) { "1234" }
13
+ let(:url) { droplet._find(droplet_id) }
14
+
15
+ it { url.should eq "https://api.digitalocean.com/v1/droplets/#{droplet_id}?client_id=client_id_required&api_key=api_key_required" }
16
+ end
17
+
18
+ describe "._rename" do
19
+ let(:droplet_id) { "1234" }
20
+ let(:name) { "new_name" }
21
+ let(:url) { droplet._rename(droplet_id, {name: name}) }
22
+
23
+ it { url.should eq "https://api.digitalocean.com/v1/droplets/#{droplet_id}/rename/?client_id=client_id_required&api_key=api_key_required&name=#{name}" }
24
+ end
25
+
26
+ describe "._rebuild" do
27
+ let(:droplet_id) { "1234" }
28
+ let(:image_id) { "11" }
29
+
30
+ let(:url) { droplet._rebuild(droplet_id, {image_id: image_id}) }
31
+
32
+ it { url.should eq "https://api.digitalocean.com/v1/droplets/#{droplet_id}/rebuild/?image_id=#{image_id}&client_id=client_id_required&api_key=api_key_required" }
33
+ end
34
+
35
+ describe "._reboot" do
36
+ let(:droplet_id) { "1234" }
37
+ let(:url) { droplet._reboot(droplet_id) }
38
+
39
+ it { url.should eq "https://api.digitalocean.com/v1/droplets/#{droplet_id}/reboot/?client_id=client_id_required&api_key=api_key_required" }
40
+ end
41
+
42
+ describe "._power_cycle" do
43
+ let(:droplet_id) { "1234" }
44
+ let(:url) { droplet._power_cycle(droplet_id) }
45
+
46
+ it { url.should eq "https://api.digitalocean.com/v1/droplets/#{droplet_id}/power_cycle/?client_id=client_id_required&api_key=api_key_required" }
47
+ end
48
+
49
+ describe "._shutdown" do
50
+ let(:droplet_id) { "1234" }
51
+ let(:url) { droplet._shutdown(droplet_id) }
52
+
53
+ it { url.should eq "https://api.digitalocean.com/v1/droplets/#{droplet_id}/shutdown/?client_id=client_id_required&api_key=api_key_required" }
54
+ end
55
+
56
+ describe "._power_off" do
57
+ let(:droplet_id) { "1234" }
58
+ let(:url) { droplet._power_off(droplet_id) }
59
+
60
+ it { url.should eq "https://api.digitalocean.com/v1/droplets/#{droplet_id}/power_off/?client_id=client_id_required&api_key=api_key_required" }
61
+ end
62
+
63
+ describe "._power_on" do
64
+ let(:droplet_id) { "1234" }
65
+ let(:url) { droplet._power_on(droplet_id) }
66
+
67
+ it { url.should eq "https://api.digitalocean.com/v1/droplets/#{droplet_id}/power_on/?client_id=client_id_required&api_key=api_key_required" }
68
+ end
69
+
70
+ describe "._snapshot" do
71
+ let(:droplet_id) { "1234" }
72
+ let(:snapshot_name) { "test_name" }
73
+
74
+ let(:url) { droplet._snapshot(droplet_id, {name: snapshot_name}) }
75
+
76
+ it { url.should eq "https://api.digitalocean.com/v1/droplets/#{droplet_id}/snapshot/?name=#{snapshot_name}&client_id=client_id_required&api_key=api_key_required" }
77
+ end
78
+
79
+ describe "._create" do
80
+ let(:name) { "test_name" }
81
+ let(:size_id) { "1234" }
82
+ let(:image_id) { "11" }
83
+ let(:region_id) { "44" }
84
+ let(:ssh_key_ids) { "12,92" }
85
+
86
+ let(:url) { droplet._create({name: name, size_id: size_id, image_id: image_id, region_id: region_id, ssh_key_ids: ssh_key_ids}) }
87
+
88
+ it { url.should eq "https://api.digitalocean.com/v1/droplets/new?client_id=client_id_required&api_key=api_key_required&name=#{name}&size_id=#{size_id}&image_id=#{image_id}&region_id=#{region_id}&ssh_key_ids=#{ssh_key_ids}&private_networking=private_networking&backups_enabled=backups_enabled" }
89
+ end
90
+
91
+ describe "._destroy" do
92
+ let(:droplet_id) { "1234" }
93
+ let(:url) { droplet._destroy(droplet_id) }
94
+
95
+ it { url.should eq "https://api.digitalocean.com/v1/droplets/#{droplet_id}/destroy/?client_id=client_id_required&api_key=api_key_required" }
96
+ end
97
+
98
+ describe "._resize" do
99
+ let(:droplet_id) { "1234" }
100
+ let(:size_id) { "45" }
101
+
102
+ let(:url) { droplet._resize(droplet_id, {size_id: size_id}) }
103
+
104
+ it { url.should eq "https://api.digitalocean.com/v1/droplets/#{droplet_id}/resize/?size_id=#{size_id}&client_id=client_id_required&api_key=api_key_required" }
105
+ end
106
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Digitalocean::Event do
4
+ subject(:event) { described_class }
5
+
6
+ describe "._find" do
7
+ let(:event_id) { "1234" }
8
+ let(:url) { event._find(event_id) }
9
+
10
+ it { url.should eq "https://api.digitalocean.com/v1/events/#{event_id}/?client_id=client_id_required&api_key=api_key_required" }
11
+ end
12
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Digitalocean::Image do
4
+ subject(:image) { described_class }
5
+
6
+ describe "._all" do
7
+ let(:url) { image._all }
8
+ it { url.should eq "https://api.digitalocean.com/v1/images/?client_id=client_id_required&api_key=api_key_required" }
9
+ end
10
+
11
+ describe "._all with optional parameters" do
12
+ let(:args) { { filter: "my_images" } }
13
+ let(:url) { image._all(args) }
14
+
15
+ it { url.should eq "https://api.digitalocean.com/v1/images/?client_id=client_id_required&api_key=api_key_required&filter=my_images" }
16
+ end
17
+
18
+ describe "._find" do
19
+ let(:id) { "1234" }
20
+ let(:url) { image._find(id) }
21
+
22
+ it { url.should eq "https://api.digitalocean.com/v1/images/#{id}/?client_id=client_id_required&api_key=api_key_required" }
23
+ end
24
+
25
+ describe "._destroy" do
26
+ let(:id) { "1234" }
27
+ let(:url) { image._destroy(id) }
28
+
29
+ it { url.should eq "https://api.digitalocean.com/v1/images/#{id}/destroy/?client_id=client_id_required&api_key=api_key_required" }
30
+ end
31
+
32
+ describe "._transfer" do
33
+ let(:id) { "1234" }
34
+ let(:region_id) { "44" }
35
+ let(:args) { {region_id: region_id } }
36
+
37
+ let(:url) { image._transfer(id, args) }
38
+
39
+ it { url.should eq "https://api.digitalocean.com/v1/images/#{id}/transfer/?client_id=client_id_required&api_key=api_key_required&region_id=44" }
40
+ end
41
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe "integrations" do
4
+ subject(:region) { Digitalocean::Region }
5
+
6
+ before { Digitalocean.send(:setup_request!) }
7
+
8
+ it "makes a real call" do
9
+ regions = region.all
10
+ regions.status.should eq "ERROR"
11
+ end
12
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe Digitalocean::Record do
4
+ subject(:record) { described_class }
5
+
6
+ describe "._all" do
7
+ let(:domain_id) { "100" }
8
+ let(:url) { record._all(domain_id) }
9
+
10
+ it { url.should eq "https://api.digitalocean.com/v1/domains/#{domain_id}/records?client_id=client_id_required&api_key=api_key_required" }
11
+ end
12
+
13
+ describe "._find" do
14
+ let(:domain_id) { "100" }
15
+ let(:record_id) { "50" }
16
+
17
+ let(:url) { record._find(domain_id, record_id) }
18
+
19
+ it { url.should eq "https://api.digitalocean.com/v1/domains/#{domain_id}/records/#{record_id}?client_id=client_id_required&api_key=api_key_required" }
20
+ end
21
+
22
+ describe "._create" do
23
+ let(:domain_id) { "100" }
24
+ let(:record_type) { "A" }
25
+ let(:data) { "@" }
26
+ let(:attrs) { {record_type: record_type, data: data } }
27
+
28
+ let(:url) { record._create(domain_id, attrs) }
29
+
30
+ it { url.should eq "https://api.digitalocean.com/v1/domains/#{domain_id}/records/new?client_id=client_id_required&api_key=api_key_required&record_type=#{record_type}&data=#{data}" }
31
+ end
32
+
33
+ describe "._edit" do
34
+ let(:domain_id) { "100" }
35
+ let(:record_id) { "50" }
36
+ let(:record_type) { "A" }
37
+ let(:data) { "@" }
38
+ let(:attrs) { {record_type: record_type, data: data } }
39
+
40
+ let(:url) { record._edit(domain_id, record_id, attrs) }
41
+
42
+ it { url.should eq "https://api.digitalocean.com/v1/domains/#{domain_id}/records/#{record_id}/edit?client_id=client_id_required&api_key=api_key_required&record_type=#{record_type}&data=#{data}" }
43
+ end
44
+
45
+ describe "._destroy" do
46
+ let(:domain_id) { "100" }
47
+ let(:record_id) { "50" }
48
+
49
+ let(:url) { record._destroy(domain_id, record_id) }
50
+
51
+ it { url.should eq "https://api.digitalocean.com/v1/domains/#{domain_id}/records/#{record_id}/destroy?client_id=client_id_required&api_key=api_key_required" }
52
+ end
53
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Digitalocean::Region do
4
+ subject(:region) { described_class }
5
+
6
+ describe "._all" do
7
+ let(:url) { region._all }
8
+
9
+ it { url.should eq "https://api.digitalocean.com/v1/regions/?client_id=client_id_required&api_key=api_key_required" }
10
+ end
11
+
12
+ describe "._find" do
13
+ let(:region_id) { "1234" }
14
+ let(:url) { region._find(region_id) }
15
+
16
+ it { url.should eq "https://api.digitalocean.com/v1/regions/#{region_id}?client_id=client_id_required&api_key=api_key_required" }
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Digitalocean::Size do
4
+ subject(:size) { described_class }
5
+
6
+ describe "._all" do
7
+ let(:url) { size._all }
8
+ it { url.should eq "https://api.digitalocean.com/v1/sizes/?client_id=client_id_required&api_key=api_key_required" }
9
+ end
10
+
11
+ describe "._find" do
12
+ let(:size_id) { "1234" }
13
+ let(:url) { size._find(size_id) }
14
+
15
+ it { url.should eq "https://api.digitalocean.com/v1/sizes/#{size_id}?client_id=client_id_required&api_key=api_key_required" }
16
+ end
17
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Digitalocean::SshKey do
4
+ subject(:ssh_key) { described_class }
5
+
6
+ describe "._all" do
7
+ let(:url) { ssh_key._all }
8
+
9
+ it { url.should eq "https://api.digitalocean.com/v1/ssh_keys/?client_id=client_id_required&api_key=api_key_required" }
10
+ end
11
+
12
+ describe "._find" do
13
+ let(:ssh_key_id) { "test_key" }
14
+ let(:url) { ssh_key._find(ssh_key_id) }
15
+
16
+ it { url.should eq "https://api.digitalocean.com/v1/ssh_keys/test_key/?client_id=client_id_required&api_key=api_key_required" }
17
+ end
18
+
19
+ describe "._edit" do
20
+ let(:ssh_key_id) { "test_key" }
21
+ let(:ssh_pub_key) { "test_pub_key" }
22
+ let(:name) { "test_name" }
23
+ let(:attrs) { { name: name, ssh_pub_key: ssh_pub_key } }
24
+ let(:url) { ssh_key._edit(ssh_key_id, attrs) }
25
+
26
+ it { url.should eq "https://api.digitalocean.com/v1/ssh_keys/test_key/edit/?name=#{name}&ssh_pub_key=#{ssh_pub_key}&client_id=client_id_required&api_key=api_key_required" }
27
+ end
28
+
29
+ describe "._create" do
30
+ let(:name) { "test_name" }
31
+ let(:ssh_pub_key) { "test_pub_key" }
32
+ let(:attrs) { { name: name, ssh_pub_key: ssh_pub_key } }
33
+
34
+ let(:url) { ssh_key._create(attrs) }
35
+
36
+ it { url.should eq "https://api.digitalocean.com/v1/ssh_keys/new/?name=#{name}&ssh_pub_key=#{ssh_pub_key}&client_id=client_id_required&api_key=api_key_required" }
37
+ end
38
+
39
+ describe "._destroy" do
40
+ let(:ssh_key_id) { "test_key" }
41
+ let(:url) { ssh_key._destroy(ssh_key_id) }
42
+
43
+ it { url.should eq "https://api.digitalocean.com/v1/ssh_keys/#{ssh_key_id}/destroy/?client_id=client_id_required&api_key=api_key_required" }
44
+ end
45
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Digitalocean do
4
+ subject(:digitalocean) { described_class }
5
+
6
+ before do
7
+ digitalocean.client_id = client_id
8
+ digitalocean.api_key = api_key
9
+ digitalocean.verify_ssl = verify_ssl
10
+ end
11
+
12
+ describe "defaults" do
13
+ let(:client_id) { nil }
14
+ let(:api_key) { nil}
15
+ let(:verify_ssl) { nil }
16
+
17
+ its(:api_endpoint) { should eq "https://api.digitalocean.com" }
18
+ its(:client_id) { should eq "client_id_required" }
19
+ its(:api_key) { should eq "api_key_required" }
20
+ its(:verify_ssl) { should eq true }
21
+
22
+ it { digitalocean::VERSION.should eq "1.2.0" }
23
+ end
24
+
25
+ describe "setting values" do
26
+ let(:client_id) { "1234" }
27
+ let(:api_key) { "adf3434938492fjkdfj" }
28
+ let(:verify_ssl) { false }
29
+
30
+ its(:client_id) { should eq client_id }
31
+ its(:api_key) { should eq api_key }
32
+ its(:verify_ssl) { should eq verify_ssl }
33
+ end
34
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'pry'
4
+ require 'digitalocean'
5
+ require 'securerandom'
6
+ require 'rspec/its'
7
+
8
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
metadata ADDED
@@ -0,0 +1,191 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: digitalocean_c
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ platform: ruby
6
+ authors:
7
+ - scottmotte
8
+ - sergiocampama
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-05-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.9.1
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.9.1
28
+ - !ruby/object:Gem::Dependency
29
+ name: faraday_middleware
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 0.9.0
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 0.9.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: recursive-open-struct
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 0.4.5
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 0.4.5
56
+ - !ruby/object:Gem::Dependency
57
+ name: foreman
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: pry
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rake
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rspec
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: rspec-its
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Ruby bindings for the Digital Ocean API.
127
+ email:
128
+ - scott@scottmotte.com
129
+ - sergiocampama@gmail.com
130
+ executables: []
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - ".gitignore"
135
+ - ".rspec"
136
+ - ".travis.yml"
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - digitalocean-rubygem.jpg
142
+ - digitalocean_c.gemspec
143
+ - example.png
144
+ - lib/digitalocean.rb
145
+ - lib/digitalocean/version.rb
146
+ - spec/digitalocean/domain_spec.rb
147
+ - spec/digitalocean/droplet_spec.rb
148
+ - spec/digitalocean/event_spec.rb
149
+ - spec/digitalocean/image_spec.rb
150
+ - spec/digitalocean/integration_spec.rb
151
+ - spec/digitalocean/record_spec.rb
152
+ - spec/digitalocean/region_spec.rb
153
+ - spec/digitalocean/size_spec.rb
154
+ - spec/digitalocean/ssh_key_spec.rb
155
+ - spec/digitalocean_spec.rb
156
+ - spec/spec_helper.rb
157
+ homepage: http://github.com/merqlove/digitalocean_c
158
+ licenses: []
159
+ metadata: {}
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubyforge_project:
176
+ rubygems_version: 2.2.3
177
+ signing_key:
178
+ specification_version: 4
179
+ summary: Ruby bindings for the Digital Ocean API.
180
+ test_files:
181
+ - spec/digitalocean/domain_spec.rb
182
+ - spec/digitalocean/droplet_spec.rb
183
+ - spec/digitalocean/event_spec.rb
184
+ - spec/digitalocean/image_spec.rb
185
+ - spec/digitalocean/integration_spec.rb
186
+ - spec/digitalocean/record_spec.rb
187
+ - spec/digitalocean/region_spec.rb
188
+ - spec/digitalocean/size_spec.rb
189
+ - spec/digitalocean/ssh_key_spec.rb
190
+ - spec/digitalocean_spec.rb
191
+ - spec/spec_helper.rb