colombo 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ 8=gP�;� CNr�Kıe���+��BF�m��Px�D�C�ce��~&��ۄ1샽&I�����K[GP��3H��W/x�L �#`l�Ǐ���������2��W�ԯ�ɑ��q�xϚd3��}�T�m�c�����v����� ��epl��,� ?|^��X�g�iI�1��4�y�]/!��`y�`�w��f?l/�Vݓ&<�D?�C�v��g_�;z���+^e��A� �nׂ��m �:sQ��yR�
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ test/colombo/fixtures
6
+ .yardoc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in colombo.gemspec
4
+ gemspec
@@ -0,0 +1,132 @@
1
+ # colombo [![Code Climate](https://codeclimate.com/github/lmmendes/colombo.png)](https://codeclimate.com/github/lmmendes/colombo)
2
+
3
+
4
+ A simple Digital Ocean (http://digitalocean.com) API wrapper
5
+
6
+ NOTE: This version is an experimental version not ready for usage.
7
+
8
+ ## Install
9
+
10
+ ```
11
+ gem install columbus
12
+ ```
13
+
14
+ ## Examples
15
+
16
+ ### Configuration
17
+
18
+ ```ruby
19
+ # You can set Columbus configuration at class level like so
20
+ Colombo.configure do |c|
21
+ c.api_key = ENV['DO_API_KEY']
22
+ c.client_id = ENV['DO_CLIENT_ID']
23
+ end
24
+
25
+ # Or configure each instance independently
26
+ @client = Colombo.new(
27
+ :api_key => ENV['DO_API_KEY'],
28
+ :client_id => ENV['DO_CLIENT_ID']
29
+ )
30
+ ```
31
+
32
+ ### Droplets
33
+
34
+ ```ruby
35
+ # This method returns all active droplets that are currently running in your account
36
+ @client.droplets()
37
+
38
+ # This method returns full information for a specific droplet ID
39
+ @client.droplets.find( droplet_id )
40
+
41
+ # This method allows you to create a new droplet.
42
+ new_droplet = droplets.create({
43
+ :name => COLOMBO_DROPLET_NAME ,
44
+ :image_id => COLOMBO_IMAGE_ID ,
45
+ :region_id => COLOMBO_REGION_ID ,
46
+ :size_id => COLOMBO_SIZE_ID
47
+ })
48
+
49
+ # This method allows you to reboot a droplet.
50
+ # This is the preferred method to use if a server is not responding.
51
+ @client.droplets.find( droplet_id ).reboot()
52
+
53
+ # This method allows you to power cycle a droplet.
54
+ # This will turn off the droplet and then turn it back on.
55
+ @client.droplets.find( droplet_id ).power_cycle()
56
+
57
+ # This method allows you to shutdown a running droplet.
58
+ # The droplet will remain in your account.
59
+ @client.droplets.find( droplet_id ).shutdown()
60
+
61
+ ```
62
+
63
+ ### Regions
64
+ ```ruby
65
+ # Return all the available regions within the Digital Ocean cloud.
66
+ @client.regions
67
+ ```
68
+
69
+ ### Images
70
+ ```ruby
71
+ # This method returns all the available images that can be accessed by your
72
+ # client ID. You will have access to all public images by default, and any
73
+ # snapshots or backups that you have created in your own account.
74
+ @client.images
75
+
76
+ # This method displays the attributes of an image.
77
+ @client.images.find(image_id)
78
+
79
+ # This method allows you to destroy an image. There is no way to restore a
80
+ # deleted image so be careful and ensure your data is properly backed up.
81
+ @client.images.find( image_id ).destroy
82
+ ```
83
+
84
+ ### SSH Keys
85
+ ```ruby
86
+ # This method lists all the available public SSH keys in your account
87
+ # that can be added to a droplet.
88
+ @client.ssh_keys
89
+
90
+ # Shows a specific public SSH key in your account that can be added to a droplet.
91
+ @client.find( ssh_key_id )
92
+
93
+ # This method allows you to add a new public SSH key to your account.
94
+ ssh_key = @client.ssh_keys.create({
95
+ :name => 'my ssh key name',
96
+ :ssh_pub_key => 'my ssh key ...'
97
+ })
98
+
99
+ # This method allows you to modify an existing public SSH key in your account.
100
+ ssh_key.update(:ssh_pub_key => 'my new ssh key')
101
+
102
+ # This method will delete the SSH key from your account.
103
+ ssh_key.destroy
104
+
105
+ ```
106
+
107
+ ### Sizes
108
+ ```ruby
109
+ # This method returns all the available sizes that can be used to create a droplet.
110
+ @client.sizes
111
+ ```
112
+
113
+
114
+ ## Bug reports and other issues
115
+
116
+ * https://github.com/lmmendes/colombo/issues
117
+
118
+ ## Help and Docs
119
+
120
+ * https://github.com/lmmendes/colombo/wiki
121
+
122
+ ## Contributing
123
+
124
+ * Fork the project.
125
+ * Make your feature addition or bug fix.
126
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
127
+ * Send me a pull request. Bonus points for topic branches.
128
+
129
+ ## License
130
+
131
+ Colombo is free software distributed under the terms of the MIT license reproduced [here](http://opensource.org/licenses/mit-license.html).
132
+
@@ -0,0 +1,15 @@
1
+ #/usr/bin/env rake
2
+
3
+ require 'rubygems'
4
+
5
+ require 'bundler/gem_tasks'
6
+ require 'rake/testtask'
7
+
8
+ Rake::TestTask.new do |test|
9
+ test.libs << 'lib' << 'test'
10
+ test.ruby_opts << '-rubygems'
11
+ test.pattern = 'test/**/*_test.rb'
12
+ test.verbose = true
13
+ end
14
+
15
+ task :default => :test
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+ require "colombo/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "colombo"
8
+ s.version = Colombo::VERSION
9
+ s.authors = ["Luis Mendes"]
10
+ s.email = ["lmmendes@gmail.com"]
11
+ s.homepage = "http://github.com/lmmendes/colombo"
12
+ s.summary = %q{Digital Ocean API client}
13
+ s.description = %q{A simple ruby client for Digital Ocean API}
14
+
15
+ s.rubyforge_project = "colombo"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ # specify any dependencies here; for example:
23
+ # s.add_development_dependency "rspec"
24
+
25
+ s.add_runtime_dependency "rest-client", "~> 1.6.7"
26
+
27
+ s.add_development_dependency "minitest"
28
+ s.add_development_dependency "webmock"
29
+ s.add_development_dependency "vcr"
30
+ s.add_development_dependency "turn"
31
+ s.add_development_dependency "rake"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vp43pvW3JEl8GKUs04W
16
+ LJvv7KFzwoLuJVpW2yWjknFBucSWRtREXGBkr7cXXOaqWvKVmg8LBPFk/aEIK1UT
17
+ s6YUxzQL+IVpo4B9HRjGnG6BG+UVImieLegjUZvGQHGfHstl7dwiBUingU/2WNLR
18
+ 1pHA8Wxk1URb6lqkcQtDYl92SqSJMEcK4ZM3Fl+DS4Epm3PH56eZ4wBXZDHLECnO
19
+ nn8B1u2+
20
+ -----END CERTIFICATE-----
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ $:.unshift File.expand_path(File.dirname(__FILE__))
4
+
5
+ require 'json'
6
+ require 'rest-client'
7
+
8
+ require "colombo/version"
9
+ require "colombo/configuration"
10
+ require "colombo/request"
11
+ require "colombo/droplet"
12
+ require "colombo/droplets"
13
+ require "colombo/region"
14
+ require "colombo/regions"
15
+ require "colombo/image"
16
+ require "colombo/images"
17
+ require "colombo/ssh_keys"
18
+ require "colombo/client"
19
+ require "colombo/sizes"
20
+
21
+
22
+ module Colombo
23
+ extend Configuration
24
+
25
+
26
+ def self.new(options={})
27
+ Client.new(options)
28
+ end
29
+
30
+
31
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ module Colombo
4
+ class Client
5
+
6
+ include Request
7
+
8
+ attr_accessor *Configuration::VALID_CONFIG_KEYS
9
+
10
+ def initialize(options={})
11
+
12
+ merge_options = Colombo.options.merge(options)
13
+ Configuration::VALID_CONFIG_KEYS.each do |key|
14
+ self.send("#{key}=", merge_options[key])
15
+ end
16
+
17
+ end
18
+
19
+ def droplets
20
+ Droplets.new(self)
21
+ end
22
+
23
+ def regions
24
+ Regions.new(self)
25
+ end
26
+
27
+ def images
28
+ Images.new(self)
29
+ end
30
+
31
+ def sizes
32
+ Sizes.new(self)
33
+ end
34
+
35
+ def ssh_keys
36
+ SshKeys.new(self)
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ module Colombo
4
+ module Configuration
5
+
6
+ VALID_CONNECTION_KEYS = [:endpoint, :user_agent].freeze
7
+
8
+ VALID_OPTION_KEYS = [:api_key, :client_id].freeze
9
+
10
+ VALID_CONFIG_KEYS = VALID_CONNECTION_KEYS + VALID_OPTION_KEYS
11
+
12
+ DEFAULT_END_POINT = 'https://api.digitalocean.com'
13
+
14
+ DEFAULT_USER_AGENT = "Mozilla/5.0 (compatible; Colombo a Digital Ocean Ruby API Client/#{Colombo::VERSION}; +https://github/lmmendes/colombo)"
15
+
16
+ DEFAULT_API_KEY = nil
17
+
18
+ DEFAULT_CLIENT_ID = nil
19
+
20
+ attr_accessor *VALID_CONFIG_KEYS
21
+
22
+ def reset
23
+ self.endpoint = DEFAULT_END_POINT
24
+ self.api_key = DEFAULT_API_KEY
25
+ self.client_id = DEFAULT_CLIENT_ID
26
+ self.user_agent = DEFAULT_USER_AGENT
27
+ end
28
+
29
+ def options
30
+ Hash[ *VALID_CONFIG_KEYS.map{ |key| [key, send(key)] }.flatten ]
31
+ end
32
+
33
+
34
+ def configure
35
+ yield self
36
+ end
37
+
38
+ def self.extended(base)
39
+ base.reset
40
+ end
41
+
42
+
43
+ end
44
+ end
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+
3
+ module Colombo
4
+ class Droplet
5
+
6
+ attr_accessor :id, :name, :image_id, :size_id, :region_id
7
+ attr_accessor :backups_active, :ip_address, :status
8
+
9
+ def initialize(client, droplets, droplet_hash)
10
+ @client = client
11
+ if droplet_hash
12
+ droplet_hash.each do |key, value|
13
+ __send__("#{key}=", value) if self.respond_to?( key.to_sym )
14
+ end
15
+ end
16
+ end
17
+
18
+ def reboot
19
+ @client.request(:get, "/droplets/#{self.id}/reboot/") do |response|
20
+ return response['event_id']
21
+ end
22
+ end
23
+
24
+ def power_cycle
25
+ @client.request(:get, "/droplets/#{self.id}/power_cycle/")
26
+ end
27
+
28
+ def shutdown
29
+ @client.request(:get, "/droplets/#{self.id}/shutdown/")
30
+ end
31
+
32
+ def power_on
33
+ @client.request(:get, "/droplets/#{self.id}/power_on/")
34
+ end
35
+
36
+ def password_reset
37
+ @client.request(:get, "/droplets/#{self.id}/password_reset/")
38
+ end
39
+
40
+ def resize(size_id)
41
+ @client.request(:get, "/droplets/#{self.id}/resize/", {
42
+ :size_id => size_id
43
+ })
44
+ end
45
+
46
+ def snapshot(name=nil)
47
+ params = name.nil? ? {} : {:name => name}
48
+ @client.request(:get, "/droplets/#{self.id}/snapshot/", params)
49
+ end
50
+
51
+ def restore(restore_image_id)
52
+ @client.request(:get, "/droplets/#{self.id}/restore/", {
53
+ :image_id => restore_id
54
+ })
55
+ end
56
+
57
+ def rebuild(rebuild_image_id)
58
+ @client.request(:get, "/droplets/#{self.id}/rebuild/", {:image_id => rebuild_image_id}) do |response|
59
+ return response['event_id']
60
+ end
61
+ end
62
+
63
+ def enable_backups
64
+ @client.request(:get, "/droplets/#{self.id}/enable_backups/") do |response|
65
+ return response['event_id']
66
+ end
67
+ end
68
+
69
+ def disable_backups
70
+ @client.request(:get, "/droplets/#{self.id}/disable_backups/") do |response|
71
+ return response['event_id']
72
+ end
73
+ end
74
+
75
+ def destroy(confirm=false)
76
+ return false unless confirm
77
+ @client.request(:get, "/droplets/#{self.id}/destroy/") do |response|
78
+ return response['event_id']
79
+ end
80
+ end
81
+
82
+
83
+ end
84
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ require "colombo/droplet"
4
+
5
+ module Colombo
6
+ class Droplets < Array
7
+
8
+ def initialize(client)
9
+ @client = client
10
+ @client.request(:get, '/droplets/', {}) do |response|
11
+ response['droplets'].each do |droplet|
12
+ self << Droplet.new(@client, self, droplet)
13
+ end
14
+ end
15
+ end
16
+
17
+ def create(options={})
18
+
19
+ [:name,:size_id, :image_id,:region_id].each do |key|
20
+ raise "Required `#{key}` attribute" if not options.include?( key )
21
+ end
22
+
23
+ if not options[:ssh_keys].nil?
24
+ options[:ssh_keys] = options[:ssh_keys].join(',')
25
+ end
26
+
27
+ @client.request(:get, '/droplets/new', options) do |response|
28
+ puts response
29
+ end
30
+
31
+ end
32
+
33
+ def find(droplet_id)
34
+
35
+ droplet = self.select{ |d| d.id == droplet_id }.first
36
+
37
+ return droplet if not droplet.nil?
38
+
39
+ response = @client.request(:get, "/droplets/#{droplet_id}") do |response|
40
+ droplet = Droplet.new(@client, self, response['droplet'])
41
+ self << droplet
42
+ end
43
+
44
+ return droplet
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,6 @@
1
+ module Colombo
2
+
3
+ class Exception < RuntimeError
4
+ end
5
+
6
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ module Colombo
3
+ class Image
4
+
5
+ attr_accessor :id, :name, :distribution
6
+
7
+ def initialize(client, images, image_hash)
8
+ @client = client
9
+ image_hash.each do |key, value|
10
+ __send__("#{key}=", value) if self.respond_to?( key.to_sym )
11
+ end
12
+ end
13
+
14
+ def destroy(confirm=false)
15
+ return unless confirm
16
+ @client.request(:get, "/images/#{self.id}/destroy/") do |response|
17
+ return response['event_id']
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+
3
+ require "colombo/image"
4
+
5
+ module Colombo
6
+ class Images < Array
7
+
8
+ def initialize(client)
9
+ @client = client
10
+ @client.request(:get, '/images/', {}) do |response|
11
+ response['images'].each do |image|
12
+ self << Image.new(@client, self, image)
13
+ end
14
+ end
15
+ end
16
+
17
+ def find(image_id)
18
+
19
+ image = self.select{ |i| i.id == image_id }.first
20
+
21
+ return image if not image.nil?
22
+
23
+ response = @client.request(:get, "/images/#{image_id}") do |response|
24
+ image = Image.new(@client, self, response['image'])
25
+ self << image
26
+ end
27
+
28
+ return image
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ module Colombo
3
+ class Region
4
+
5
+ attr_accessor :id, :name
6
+
7
+ def initialize(client, regions, region_hash)
8
+ @client = client
9
+ @regions = regions
10
+ region_hash.each do |key, value|
11
+ __send__("#{key}=", value) if self.respond_to?( key.to_sym )
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+
3
+ require "colombo/region"
4
+
5
+ module Colombo
6
+ class Regions < Array
7
+
8
+ def initialize(client)
9
+ @client = client
10
+ @client.request(:get, '/regions/', {}) do |response|
11
+ response['regions'].each do |region|
12
+ self[ region['id'].to_i ] = Region.new(@client, self, region)
13
+ end
14
+ end
15
+ end
16
+
17
+ def find(region_id)
18
+
19
+ region = self.select{ |r| r.id == region_id }.first
20
+
21
+ return region if not region.nil?
22
+
23
+ response = @client.request(:get, "/regions/#{region_id}") do |response|
24
+ region = Region.new(@client, self, response['region'])
25
+ self << region
26
+ end
27
+
28
+ return region
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ module Colombo
4
+ module Request
5
+
6
+ def request(method=:get, uri='/', params={}, &block)
7
+
8
+ params[:client_id] = self.client_id
9
+ params[:api_key] = self.api_key
10
+
11
+ url = self.endpoint + uri
12
+
13
+ if method.to_sym == :get
14
+ params = { :params => params }
15
+ params[:client_id] = self.client_id
16
+ params[:api_key] = self.api_key
17
+ else
18
+ url += "?client_id=#{self.client_id}&api_key=#{self.api_key}"
19
+ end
20
+
21
+ # puts "url: #{url}"
22
+
23
+ response = nil
24
+ begin
25
+ response = RestClient.send(method, url, params)
26
+ rescue => e
27
+ $stderr.puts e.inspect
28
+ raise
29
+ end
30
+
31
+ # puts response.inspect
32
+
33
+ response = JSON.parse(response)
34
+ if response['status'].to_s.downcase == 'ok'
35
+ if block_given?
36
+ block.call(response)
37
+ return
38
+ else
39
+ return response
40
+ end
41
+ end
42
+
43
+ raise response['error_message']
44
+
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ module Colombo
3
+ class Size
4
+
5
+ attr_accessor :id, :name
6
+
7
+ def initialize(client, sizes, size_hash)
8
+ @client = client
9
+ @sizes = sizes
10
+ size_hash.each do |key, value|
11
+ __send__("#{key}=", value) if self.respond_to?( key.to_sym )
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ require "colombo/size"
4
+
5
+ module Colombo
6
+ class Sizes < Array
7
+
8
+ def initialize(client)
9
+ @client = client
10
+ @client.request(:get, '/sizes/', {}) do |response|
11
+ response['sizes'].each do |size|
12
+ self << Size.new(@client, self, size)
13
+ end
14
+ end
15
+ end
16
+
17
+ def find(size_id)
18
+ self.select{ |s| s.id == size_id }.first
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ module Colombo
3
+ class SshKey
4
+
5
+ attr_accessor :id, :name, :ssh_pub_key
6
+
7
+ def initialize(client, ssh_keys, ssh_key_hash)
8
+ @client = client
9
+ ssh_key_hash.each do |key, value|
10
+ __send__("#{key}=", value) if self.respond_to?( key.to_sym )
11
+ end
12
+ end
13
+
14
+ def destroy
15
+ @client.request(:get, "/ssh_keys/#{self.id}/destroy/") do |response|
16
+ return true
17
+ end
18
+ return false
19
+ end
20
+
21
+ def update(options={})
22
+ params = {
23
+ :ssh_pub_key => options[:ssh_pub_key]
24
+ }
25
+ response = @client.request(:get, "/ssh_keys/#{self.id}/edit/", params) do |response|
26
+ return true
27
+ end
28
+ return false
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ require "colombo/ssh_key"
4
+
5
+ module Colombo
6
+ class SshKeys < Array
7
+
8
+ def initialize(client)
9
+ @client = client
10
+ @client.request(:get, '/ssh_keys/', {}) do |response|
11
+ response['ssh_keys'].each do |ssh_key|
12
+ self << SshKey.new(@client, self, ssh_key)
13
+ end
14
+ end
15
+ end
16
+
17
+ def find(ssh_key_id)
18
+ ssh_key = self.select{ |o| o == ssh_key_id }.first
19
+
20
+ return ssh_key if ssh_key
21
+
22
+ response = @client.request(:get, "/ssh_keys/#{ssh_key_id}") do |response|
23
+ ssh_key = SshKey.new(@client, self, response['ssh_key'])
24
+ self << ssh_key
25
+ end
26
+
27
+ return ssh_key
28
+ end
29
+
30
+ def create(options={})
31
+
32
+ params = {
33
+ :ssh_pub_key => options[:ssh_pub_key],
34
+ :name => options[:name]
35
+ }
36
+
37
+ ssh_key = nil
38
+
39
+ response = @client.request(:get, "/ssh_keys/new/", params) do |response|
40
+ ssh_key = SshKey.new(@client, self, response['ssh_key'])
41
+ self << ssh_key
42
+ end
43
+
44
+ ssh_key
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ module Colombo
4
+ VERSION = "0.0.3"
5
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../test_helper.rb', __FILE__)
4
+
5
+ describe 'Colombo' do
6
+
7
+ before do
8
+
9
+ Colombo.reset
10
+
11
+ Colombo.configure do |c|
12
+ c.api_key = ENV['DO_API_KEY']
13
+ c.client_id = ENV['DO_CLIENT_ID']
14
+ end
15
+
16
+ end
17
+
18
+ it 'should have a version' do
19
+ Colombo::VERSION.wont_be_nil
20
+ end
21
+
22
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../test_helper.rb', __FILE__)
4
+
5
+ describe 'configuration' do
6
+
7
+ before do
8
+ Colombo.reset
9
+ end
10
+
11
+ describe '.api_key' do
12
+ it '.api_key should be equal to default' do
13
+ Colombo.api_key.must_equal Colombo::Configuration::DEFAULT_API_KEY
14
+ end
15
+ end
16
+
17
+ describe '.client_id' do
18
+ it '.client_id should be equal to default' do
19
+ Colombo.client_id.must_equal Colombo::Configuration::DEFAULT_CLIENT_ID
20
+ end
21
+ end
22
+
23
+ describe '.user_agent' do
24
+ it '.user_agent should be equal to default' do
25
+ Colombo.user_agent.must_equal Colombo::Configuration::DEFAULT_USER_AGENT
26
+ end
27
+ end
28
+
29
+ after do
30
+ Colombo.reset
31
+ end
32
+
33
+ describe '.configuration' do
34
+ Colombo::Configuration::VALID_CONFIG_KEYS.each do |key|
35
+ it "should set #{key}" do
36
+ Colombo.configure do |config|
37
+ config.send("#{key}=", key.to_s)
38
+ Colombo.send("#{key}").must_equal key.to_s
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../test_helper.rb', __FILE__)
4
+
5
+ def self.test_order
6
+ :alpha
7
+ end
8
+
9
+ describe 'Droplets' do
10
+
11
+ before do
12
+ Colombo.reset
13
+
14
+ Colombo.configure do |c|
15
+ c.api_key = ENV['DO_API_KEY']
16
+ c.client_id = ENV['DO_CLIENT_ID']
17
+ end
18
+
19
+ @do = Colombo.new
20
+
21
+ end
22
+
23
+
24
+ it 'list droplets' do
25
+ VCR.use_cassette('droplets') do
26
+ @do.droplets.must_be_instance_of(Colombo::Droplets)
27
+ end
28
+ end
29
+
30
+ it 'create columbus droplet' do
31
+ VCR.use_cassette('create_droplet') do
32
+ @do.droplets.create({
33
+ :name => COLOMBO_DROPLET_NAME ,
34
+ :image_id => COLOMBO_IMAGE_ID ,
35
+ :region_id => COLOMBO_REGION_ID ,
36
+ :size_id => COLOMBO_SIZE_ID
37
+ })
38
+ end
39
+ end
40
+
41
+ it 'find droplet' do
42
+ VCR.use_cassette('droplets_find') do
43
+ # Colombo.new.droplets.find(1)
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../test_helper.rb', __FILE__)
4
+
5
+ describe 'Images' do
6
+
7
+ before do
8
+ Colombo.reset
9
+
10
+ Colombo.configure do |c|
11
+ c.api_key = ENV['DO_API_KEY']
12
+ c.client_id = ENV['DO_CLIENT_ID']
13
+ end
14
+
15
+ @client = Colombo::Client.new
16
+ end
17
+
18
+ it 'images' do
19
+ VCR.use_cassette('images') do
20
+ @client.images.wont_be_empty
21
+ end
22
+ end
23
+
24
+
25
+ it 'find image via find method' do
26
+ VCR.use_cassette('images') do
27
+ @client.images.find(COLOMBO_IMAGE_ID).wont_be_nil
28
+ end
29
+ end
30
+
31
+ it 'find image via [] operator' do
32
+ VCR.use_cassette('images') do
33
+ @client.images.find(COLOMBO_IMAGE_ID).wont_be_nil
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../test_helper.rb', __FILE__)
4
+
5
+ describe 'Regions' do
6
+
7
+ before do
8
+ Colombo.reset
9
+
10
+ Colombo.configure do |c|
11
+ c.api_key = ENV['DO_API_KEY']
12
+ c.client_id = ENV['DO_CLIENT_ID']
13
+ end
14
+
15
+ @client = Colombo::Client.new
16
+ end
17
+
18
+ it 'regions' do
19
+ VCR.use_cassette('regions') do
20
+ @client.regions.wont_be_empty
21
+ # puts "== REGIONS ==="
22
+ # puts @client.regions.inspect
23
+ end
24
+ end
25
+
26
+
27
+ end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../test_helper.rb', __FILE__)
4
+
5
+ describe 'request' do
6
+
7
+ end
8
+
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../test_helper.rb', __FILE__)
4
+
5
+ describe 'Sizes' do
6
+
7
+ before do
8
+ Colombo.reset
9
+
10
+ Colombo.configure do |c|
11
+ c.api_key = ENV['DO_API_KEY']
12
+ c.client_id = ENV['DO_CLIENT_ID']
13
+ end
14
+
15
+ @client = Colombo::Client.new
16
+ end
17
+
18
+ it 'sizes' do
19
+ VCR.use_cassette('sizes') do
20
+ @client.sizes.wont_be_empty
21
+ # puts "== REGIONS ==="
22
+ # puts @client.sizes.inspect
23
+ end
24
+ end
25
+
26
+
27
+ end
@@ -0,0 +1,115 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../test_helper.rb', __FILE__)
4
+
5
+ def self.test_order
6
+ :alpha
7
+ end
8
+
9
+ describe 'SshKeys' do
10
+
11
+ before do
12
+ Colombo.reset
13
+
14
+ Colombo.configure do |c|
15
+ c.api_key = ENV['DO_API_KEY']
16
+ c.client_id = ENV['DO_CLIENT_ID']
17
+ end
18
+
19
+ @client = Colombo::Client.new
20
+ end
21
+
22
+ it 'list ssh keys' do
23
+
24
+ VCR.use_cassette('ssh_keys') do
25
+ @client.ssh_keys.wont_be_nil
26
+ end
27
+
28
+ end
29
+
30
+ it 'add ssh key' do
31
+
32
+ VCR.use_cassette('add ssh key') do
33
+
34
+ ssh_key = @client.ssh_keys.create({
35
+ :name => COLOMBO_SSH_KEY_NAME,
36
+ :ssh_pub_key => COLOMBO_SSH_KEY
37
+ })
38
+
39
+ ssh_key.must_be_instance_of(Colombo::SshKey)
40
+
41
+ ssh_key.name.must_equal COLOMBO_SSH_KEY_NAME
42
+
43
+ ssh_key.ssh_pub_key.must_equal COLOMBO_SSH_KEY
44
+ end
45
+
46
+ end
47
+
48
+ it 'find ssh key by id' do
49
+
50
+ VCR.use_cassette('find ssh keys by id') do
51
+
52
+ # fetch the key list from digital ocean
53
+ ssh_keys = @client.ssh_keys
54
+
55
+ # find the key with COLOMBO_SSH_KEY_NAME inside the digital ocean colection
56
+ do_key = ssh_keys.select{ |k| k.name==COLOMBO_SSH_KEY_NAME }.first
57
+
58
+ # check if the key was found
59
+ do_key.must_be_instance_of(Colombo::SshKey)
60
+
61
+ # let's try find the key in the collection
62
+ ssh_key = @client.ssh_keys.find( do_key.id )
63
+
64
+ # check if it's a ssh_key
65
+ ssh_key.must_be_instance_of(Colombo::SshKey)
66
+
67
+ # check if the values are correct
68
+ ssh_key.name.must_equal COLOMBO_SSH_KEY_NAME
69
+
70
+ # check if the values are correct
71
+ ssh_key.ssh_pub_key.must_equal COLOMBO_SSH_KEY
72
+
73
+ end
74
+
75
+ end
76
+
77
+ it 'update key' do
78
+
79
+ VCR.use_cassette('update key') do
80
+ # fetch the key list from digital ocean
81
+ ssh_keys = @client.ssh_keys
82
+
83
+ # find the key with COLOMBO_SSH_KEY_NAME inside the digital ocean colection
84
+ do_key = ssh_keys.select{ |k| k.name==COLOMBO_SSH_KEY_NAME }.first
85
+
86
+ # check if the key was found and is a SshKey
87
+ do_key.must_be_instance_of(Colombo::SshKey)
88
+
89
+ do_key.update(:ssh_pub_key => COLOMBO_SSH_KEY ).must_equal true
90
+ end
91
+
92
+ end
93
+
94
+ it 'destroy ssh key' do
95
+ VCR.use_cassette('destory ssh key') do
96
+ # fetch the key list from digital ocean
97
+ ssh_keys = @client.ssh_keys
98
+
99
+ # find the key with COLOMBO_SSH_KEY_NAME inside the digital ocean colection
100
+ ssh_keys.each do |ssh_key|
101
+ if ssh_key.name==COLOMBO_SSH_KEY_NAME
102
+ ssh_key.destroy().must_equal true
103
+ end
104
+ end
105
+
106
+ end
107
+
108
+ VCR.use_cassette('are all keys destroyed?') do
109
+ @client.ssh_keys.select{ |key| key.name == COLOMBO_SSH_KEY_NAME }.must_be_empty
110
+ end
111
+
112
+
113
+ end
114
+
115
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'minitest/autorun'
5
+ require 'minitest/spec'
6
+ require 'minitest/pride'
7
+ require 'vcr'
8
+
9
+ VCR.configure do |c|
10
+ c.cassette_library_dir = File.join( File.dirname(__FILE__), 'fixtures/vcr_cassettes')
11
+ c.hook_into :webmock
12
+ end
13
+
14
+ COLOMBO_DROPLET_NAME = 'colombo'
15
+ COLOMBO_REGION_ID = 1 # NY
16
+ COLOMBO_IMAGE_ID = 42735 # Ubuntu
17
+ COLOMBO_SIZE_ID = 63 # 1GB
18
+ COLOMBO_SSH_KEY_NAME = 'colombo gem'
19
+ COLOMBO_SSH_KEY = 'ssh-dss AAAAB3NzaC1kc3MAAACBAK5uLwicCrFEpaVKBzkWxC7RQn+smg5ZQb5keh9RQKo8AszFTol5npgUAr0JWmqKIHv7nof0HndO86x9iIqNjq3vrz9CIVcFfZM7poKBJZ27Hv3v0fmSKfAc6eGdx8eM9UkZe1gzcLXK8UP2HaeY1Y4LlaHXS5tPi/dXooFVgiA7AAAAFQCQl6LZo/VYB9VgPEZzOmsmQevnswAAAIBCNKGsVP5eZ+IJklXheUyzyuL75i04OOtEGW6MO5TymKMwTZlU9r4ukuwxty+T9Ot2LqlNRnLSPQUjb0vplasZ8Ix45JOpRbuSvPovryn7rvS7//klu9hIkFAAQ/AZfGTw+696EjFBg4F5tN6MGMA6KrTQVLXeuYcZeRXwE5t5lwAAAIEAl2xYh098bozJUANQ82DiZznjHc5FW76Xm1apEqsZtVRFuh3V9nc7QNcBekhmHp5Z0sHthXCm1XqnFbkRCdFlX02NpgtNs7OcKpaJP47N8C+C/Yrf8qK/Wt3fExrL2ZLX5XD2tiotugSkwZJMW5Bv0mtjrNt0Q7P45rZjNNTag2c= user@host'
20
+
21
+
22
+ require File.expand_path('../../../lib/colombo.rb', __FILE__)
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: colombo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Luis Mendes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain:
12
+ - !binary |-
13
+ LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURNakNDQWhxZ0F3SUJB
14
+ Z0lCQURBTkJna3Foa2lHOXcwQkFRVUZBREEvTVJFd0R3WURWUVFEREFoc2JX
15
+ MWwKYm1SbGN6RVZNQk1HQ2dtU0pvbVQ4aXhrQVJrV0JXZHRZV2xzTVJNd0VR
16
+ WUtDWkltaVpQeUxHUUJHUllEWTI5dApNQjRYRFRFek1ETXdPVEV6TURFd05W
17
+ b1hEVEUwTURNd09URXpNREV3TlZvd1B6RVJNQThHQTFVRUF3d0liRzF0ClpX
18
+ NWtaWE14RlRBVEJnb0praWFKay9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HQmtyN2NYWE9hcVd2S1ZtZzhM
35
+ QlBGay9hRUlLMVVUCnM2WVV4elFMK0lWcG80QjlIUmpHbkc2QkcrVVZJbWll
36
+ TGVnalVadkdRSEdmSHN0bDdkd2lCVWluZ1UvMldOTFIKMXBIQThXeGsxVVJi
37
+ Nmxxa2NRdERZbDkyU3FTSk1FY0s0Wk0zRmwrRFM0RXBtM1BINTZlWjR3Qlha
38
+ REhMRUNuTwpubjhCMXUyKwotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
39
+ date: 2013-03-10 00:00:00.000000000 Z
40
+ dependencies:
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: &70145160449540 !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: 1.6.7
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: *70145160449540
52
+ - !ruby/object:Gem::Dependency
53
+ name: minitest
54
+ requirement: &70145160448440 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: *70145160448440
63
+ - !ruby/object:Gem::Dependency
64
+ name: webmock
65
+ requirement: &70145160447500 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: *70145160447500
74
+ - !ruby/object:Gem::Dependency
75
+ name: vcr
76
+ requirement: &70145160446620 !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: *70145160446620
85
+ - !ruby/object:Gem::Dependency
86
+ name: turn
87
+ requirement: &70145160446200 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: *70145160446200
96
+ - !ruby/object:Gem::Dependency
97
+ name: rake
98
+ requirement: &70145160445320 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: *70145160445320
107
+ description: A simple ruby client for Digital Ocean API
108
+ email:
109
+ - lmmendes@gmail.com
110
+ executables: []
111
+ extensions: []
112
+ extra_rdoc_files: []
113
+ files:
114
+ - .gitignore
115
+ - Gemfile
116
+ - README.md
117
+ - Rakefile
118
+ - colombo.gemspec
119
+ - gem-public_cert.pem
120
+ - lib/colombo.rb
121
+ - lib/colombo/client.rb
122
+ - lib/colombo/configuration.rb
123
+ - lib/colombo/droplet.rb
124
+ - lib/colombo/droplets.rb
125
+ - lib/colombo/exception.rb
126
+ - lib/colombo/image.rb
127
+ - lib/colombo/images.rb
128
+ - lib/colombo/region.rb
129
+ - lib/colombo/regions.rb
130
+ - lib/colombo/request.rb
131
+ - lib/colombo/size.rb
132
+ - lib/colombo/sizes.rb
133
+ - lib/colombo/ssh_key.rb
134
+ - lib/colombo/ssh_keys.rb
135
+ - lib/colombo/version.rb
136
+ - test/colombo/colombo_test.rb
137
+ - test/colombo/configuration_test.rb
138
+ - test/colombo/droplets_test.rb
139
+ - test/colombo/images_test.rb
140
+ - test/colombo/regions_test.rb
141
+ - test/colombo/request_test.rb
142
+ - test/colombo/sizes_test.rb
143
+ - test/colombo/ssh_keys_test.rb
144
+ - test/colombo/test_helper.rb
145
+ homepage: http://github.com/lmmendes/colombo
146
+ licenses: []
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ! '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ none: false
159
+ requirements:
160
+ - - ! '>='
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ requirements: []
164
+ rubyforge_project: colombo
165
+ rubygems_version: 1.8.17
166
+ signing_key:
167
+ specification_version: 3
168
+ summary: Digital Ocean API client
169
+ test_files:
170
+ - test/colombo/colombo_test.rb
171
+ - test/colombo/configuration_test.rb
172
+ - test/colombo/droplets_test.rb
173
+ - test/colombo/images_test.rb
174
+ - test/colombo/regions_test.rb
175
+ - test/colombo/request_test.rb
176
+ - test/colombo/sizes_test.rb
177
+ - test/colombo/ssh_keys_test.rb
178
+ - test/colombo/test_helper.rb
179
+ has_rdoc:
Binary file