vultr 0.1.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e142d816214635f78fab04817c5f7f4b412565c6
4
+ data.tar.gz: 21277d12ff5b76a024a218a64643ad61c5ec5b49
5
+ SHA512:
6
+ metadata.gz: ba2bd17e851b7ea401feb348a77b604922162438f011cd4568b740aeb365b5948376af7e92383634e2bd0dd86300472984172267aca5b0a1628e1e189c68bad8
7
+ data.tar.gz: 89b80771fbf11942c10463c884a3b5fc1eeb538df9bd01f87c9e142adf9fc7d7279fa35f5fa64f1c75a1ceee743f03023934428203005c477cb934c7bc7e30a3
@@ -0,0 +1,22 @@
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
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
@@ -0,0 +1,9 @@
1
+ == 0.1.1 / 2014-06-10
2
+
3
+ * Update README.
4
+ * Refine API output result.
5
+ * Minor bug fixes.
6
+
7
+ == 0.1.0 / 2014-06-10
8
+
9
+ * Birthday!
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vultr.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Tolbkni Kao
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.
@@ -0,0 +1,86 @@
1
+ # VULTR Rubygem
2
+
3
+ The easiest and most complete rubygem for [VULTR](https://www.vultr.com).
4
+
5
+ ```ruby
6
+ Vultr.api_key = "your_api_key"
7
+ r = Vultr::Server.list
8
+ # => {
9
+ # :status=>200,
10
+ # :result=>[40, 11, 45, 29, 41, 61, 46, 35, 12, 30, 42, 3, 39, 13, 60, 36, 37, 43, 27, 28, 38]
11
+ # }
12
+
13
+ r[:status]
14
+ r[:result]
15
+ ```
16
+
17
+ You can find your keys at [https://my.vultr.com/settings/#API](https://my.vultr.com/settings/#API)
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ gem 'vultr'
24
+
25
+ And then execute:
26
+
27
+ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ gem install vultr
32
+
33
+ ## Usage
34
+
35
+ ### List Servers
36
+
37
+ ```ruby
38
+ Vultr::Server.list
39
+ ```
40
+
41
+ ### Create Server
42
+
43
+ ```ruby
44
+ Vultr::Server.create({DCID: dc_id, VPSPLANID: vps_plan_id, OSID: os_id})
45
+ ```
46
+
47
+ ## Available Commands
48
+
49
+ ```ruby
50
+ Vultr::Snapshot.list
51
+ Vultr::Snapshot.destroy(SNAPSHOTID: snapshot_id)
52
+ Vultr::Snapshot.create(SUBID: sub_id)
53
+
54
+ Vultr::Plan.list
55
+
56
+ Vultr::Region.list
57
+ Vultr::Region.availability(DCID: dc_id)
58
+
59
+ Vultr::StartupScript.list
60
+ Vultr::StartupScript.destroy(SCRIPTID: script_id)
61
+ Vultr::StartupScript.create({name: name, script: script})
62
+
63
+ Vultr::Server.list
64
+ Vultr::Server.reboot(SUBID: sub_id)
65
+ Vultr::Server.halt(SUBID: sub_id)
66
+ Vultr::Server.start(SUBID: sub_id)
67
+ Vultr::Server.destroy(SUBID: sub_id)
68
+ Vultr::Server.create({DCID: dc_id, VPSPLANID: vps_plan_id, OSID: os_id,
69
+ ipxe_chain_url: ipxe_chain_url, SCRIPTID: script_id, SNAPSHOTID: snapshot_id})
70
+
71
+ Vultr::OS.list
72
+ ```
73
+
74
+ ## Contributing
75
+
76
+ 1. Fork it ( https://github.com/tolbkni/vultr/fork )
77
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
78
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
79
+ 4. Push to the branch (`git push origin my-new-feature`)
80
+ 5. Create a new Pull Request
81
+
82
+ When adding methods, add to the list of DEFINITIONS in lib/vultr.rb. Additionally, write a spec and add it to the list in the README.
83
+
84
+ ## Thanks
85
+
86
+ Thanks Scott Motte and his [DigitalOcean](https://github.com/scottmotte/digitalocean) rubygem project.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,162 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "vultr/version"
4
+
5
+ module Vultr
6
+ extend self
7
+
8
+ DEFINITIONS = {
9
+ Snapshot: {
10
+ list: [:get, "/v1/snapshot/list?api_key=[api_key]"],
11
+ destroy: [:post, "/v1/snapshot/destroy?api_key=[api_key]", "SNAPSHOTID"],
12
+ create: [:post, "/v1/snapshot/create?api_key=[api_key]", "SUBID"]
13
+ },
14
+ Plan: {
15
+ list: [:get, "/v1/plans/list"]
16
+ },
17
+ Region: {
18
+ list: [:get, "/v1/regions/list"],
19
+ availability: [:get, "/v1/regions/availability?DCID=[DCID]"]
20
+ },
21
+ StartupScript: {
22
+ list: [:get, "/v1/startupscript/list?api_key=[api_key]"],
23
+ destroy: [:post, "/v1/startupscript/destroy?api_key=[api_key]", "SCRIPTID"],
24
+ create: [:post, "/v1/startupscript/create?api_key=[api_key]", ["name", "script"]]
25
+ },
26
+ Server: {
27
+ list: [:get, "/v1/server/list?api_key=[api_key]"],
28
+ reboot: [:post, "/v1/server/reboot?api_key=[api_key]", "SUBID"],
29
+ halt: [:post, "/v1/server/halt?api_key=[api_key]", "SUBID"],
30
+ start: [:post, "/v1/server/start?api_key=[api_key]", "SUBID"],
31
+ destroy: [:post, "/v1/server/destroy?api_key=[api_key]", "SUBID"],
32
+ create: [:post, "/v1/server/create?api_key=[api_key]",
33
+ ["DCID", "VPSPLANID", "OSID", "ipxe_chain_url", "SCRIPTID", "SNAPSHOTID"]]
34
+ },
35
+ OS: {
36
+ list: [:get, "/v1/os/list"]
37
+ }
38
+ }
39
+
40
+ DEFINITIONS.each do |resource|
41
+ resource_name = resource[0]
42
+
43
+ resource_class = Class.new(Object) do
44
+ DEFINITIONS[resource_name].each do |action, array|
45
+ method_name = array[0]
46
+ path, query = array[1].split("?")
47
+ params = array[2]
48
+
49
+ define_singleton_method "_#{action}" do |*args|
50
+ query_for_method = Vultr.process_query_args_from_path(query, args)
51
+ url = [Vultr.api_endpoint, path].join("")
52
+
53
+ if query_for_method.nil?
54
+ url
55
+ else
56
+ [url, query_for_method].join("?")
57
+ end
58
+ end
59
+
60
+ define_singleton_method action do |*args|
61
+ post_for_method = Vultr.process_params_args_from_keys(params, args)
62
+ Vultr.request_and_respond(method_name, send("_#{action}", *args), post_for_method)
63
+ end
64
+ end
65
+ end
66
+
67
+ Vultr.const_set(resource_name, resource_class)
68
+ end
69
+
70
+ def request=(request)
71
+ @request = request
72
+ end
73
+
74
+ def request
75
+ @request
76
+ end
77
+
78
+ def api_key=(api_key)
79
+ @api_key = api_key
80
+ setup_request!
81
+
82
+ @api_key
83
+ end
84
+
85
+ def api_key
86
+ return @api_key if @api_key
87
+ "api_key_required"
88
+ end
89
+
90
+ def api_endpoint
91
+ "https://api.vultr.com"
92
+ end
93
+
94
+ def request_and_respond(method_name, url, body = nil)
95
+ if body.nil?
96
+ resp = Vultr.request.send method_name, url
97
+ else
98
+ resp = Vultr.request.send method_name, url, body
99
+ end
100
+ {status: resp.status, result: resp.body}
101
+ end
102
+
103
+ def process_api_key(parts)
104
+ api_key_index = parts.index "api_key="
105
+ api_key_index = parts.index "&api_key=" if !api_key_index
106
+ parts[api_key_index + 1] = api_key if api_key_index
107
+
108
+ parts
109
+ end
110
+
111
+ def process_query_args_from_path(query, args)
112
+ return if query.nil?
113
+
114
+ parts = query.split(/\[|\]/)
115
+ parts = process_api_key(parts)
116
+
117
+ hash = args[-1]
118
+ if hash.is_a?(Hash)
119
+ hash.each do |key, value|
120
+ query_setter = "#{key}="
121
+ query_arg_index = parts.index query_setter
122
+ query_arg_index = parts.index "&#{query_setter}" if !query_arg_index
123
+
124
+ unless query_arg_index.nil?
125
+ parts[query_arg_index+1] = value
126
+ end
127
+ end
128
+ end
129
+
130
+ parts.join("")
131
+ end
132
+
133
+ def process_params_args_from_keys(params, args)
134
+ return if params.nil?
135
+
136
+ body = Hash.new
137
+ hash = args[-1]
138
+ if hash.is_a?(Hash)
139
+ hash.each do |key, value|
140
+ body[key] = value unless params.include? key
141
+ end
142
+ end
143
+
144
+ body unless body.empty?
145
+ end
146
+
147
+ private
148
+
149
+ def setup_request!
150
+ options = {
151
+ headers: {"Accept" => "application/json"},
152
+ ssl: {verify: false}
153
+ }
154
+
155
+ Vultr.request = Faraday.new(options) do |faraday|
156
+ faraday.request :url_encoded
157
+ faraday.response :json, :content_type => "application/json"
158
+ faraday.response :follow_redirects
159
+ faraday.adapter Faraday.default_adapter
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,10 @@
1
+ module Vultr
2
+ module VERSION
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 1
6
+ PRE = nil
7
+
8
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ require "vultr"
2
+ require "minitest/autorun"
3
+
4
+ describe Vultr::OS do
5
+
6
+ let(:os) { Vultr::OS }
7
+
8
+ it "needs to verify list os url" do
9
+ url = os._list
10
+
11
+ url.must_equal "https://api.vultr.com/v1/os/list"
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require "vultr"
2
+ require "minitest/autorun"
3
+
4
+ describe Vultr::Plan do
5
+
6
+ let(:plan) { Vultr::Plan }
7
+
8
+ it "needs to verify list plan url" do
9
+ url = plan._list
10
+
11
+ url.must_equal "https://api.vultr.com/v1/plans/list"
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ require "vultr"
2
+ require "minitest/autorun"
3
+
4
+ describe Vultr::Region do
5
+
6
+ let(:region) { Vultr::Region }
7
+
8
+ it "needs to verify list region url" do
9
+ url = region._list
10
+
11
+ url.must_equal "https://api.vultr.com/v1/regions/list"
12
+ end
13
+
14
+ it "needs to verify availability region url" do
15
+ DCID = "1234"
16
+ url = region._availability("DCID" => "1234")
17
+
18
+ url.must_equal "https://api.vultr.com/v1/regions/availability?DCID=#{DCID}"
19
+ end
20
+ end
@@ -0,0 +1,43 @@
1
+ require "vultr"
2
+ require "minitest/autorun"
3
+
4
+ describe Vultr::Server do
5
+
6
+ let(:server) { Vultr::Server }
7
+
8
+ it "needs to verify list server url" do
9
+ url = server._list
10
+
11
+ url.must_equal "https://api.vultr.com/v1/server/list?api_key=api_key_required"
12
+ end
13
+
14
+ it "needs to verify reboot server url" do
15
+ url = server._reboot
16
+
17
+ url.must_equal "https://api.vultr.com/v1/server/reboot?api_key=api_key_required"
18
+ end
19
+
20
+ it "needs to verify halt server url" do
21
+ url = server._halt
22
+
23
+ url.must_equal "https://api.vultr.com/v1/server/halt?api_key=api_key_required"
24
+ end
25
+
26
+ it "needs to verify start server url" do
27
+ url = server._start
28
+
29
+ url.must_equal "https://api.vultr.com/v1/server/start?api_key=api_key_required"
30
+ end
31
+
32
+ it "needs to verify destroy server url" do
33
+ url = server._destroy
34
+
35
+ url.must_equal "https://api.vultr.com/v1/server/destroy?api_key=api_key_required"
36
+ end
37
+
38
+ it "needs to verify create server url" do
39
+ url = server._create
40
+
41
+ url.must_equal "https://api.vultr.com/v1/server/create?api_key=api_key_required"
42
+ end
43
+ end
@@ -0,0 +1,25 @@
1
+ require "vultr"
2
+ require "minitest/autorun"
3
+
4
+ describe Vultr::Snapshot do
5
+
6
+ let(:snapshot) { Vultr::Snapshot }
7
+
8
+ it "needs to verify list snapshot url" do
9
+ url = snapshot._list
10
+
11
+ url.must_equal "https://api.vultr.com/v1/snapshot/list?api_key=api_key_required"
12
+ end
13
+
14
+ it "needs to verify destroy snapshot url" do
15
+ url = snapshot._destroy
16
+
17
+ url.must_equal "https://api.vultr.com/v1/snapshot/destroy?api_key=api_key_required"
18
+ end
19
+
20
+ it "needs to verify create snapshot url" do
21
+ url = snapshot._create
22
+
23
+ url.must_equal "https://api.vultr.com/v1/snapshot/create?api_key=api_key_required"
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require "vultr"
2
+ require "minitest/autorun"
3
+
4
+ describe Vultr::StartupScript do
5
+
6
+ let(:startupscript) { Vultr::StartupScript }
7
+
8
+ it "needs to verify list snapshot url" do
9
+ url = startupscript._list
10
+
11
+ url.must_equal "https://api.vultr.com/v1/startupscript/list?api_key=api_key_required"
12
+ end
13
+
14
+ it "needs to verify destroy snapshot url" do
15
+ url = startupscript._destroy
16
+
17
+ url.must_equal "https://api.vultr.com/v1/startupscript/destroy?api_key=api_key_required"
18
+ end
19
+
20
+ it "needs to verify create snapshot url" do
21
+ url = startupscript._create
22
+
23
+ url.must_equal "https://api.vultr.com/v1/startupscript/create?api_key=api_key_required"
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vultr/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "vultr"
8
+ s.version = Vultr::VERSION::STRING
9
+ s.authors = ["Tolbkni Kao"]
10
+ s.email = ["tolbkni@gmail.com"]
11
+ s.summary = %q{Ruby bindings for VULTR API.}
12
+ s.description = %q{Ruby bindings for VULTR API.}
13
+ s.homepage = "https://github.com/tolbkni/vultr"
14
+ s.license = "MIT"
15
+
16
+ s.files = `git ls-files -z`.split("\x0")
17
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "faraday", "~> 0.9.0"
22
+ s.add_dependency "faraday_middleware", "~> 0.9.1"
23
+
24
+ s.add_development_dependency "bundler", "~> 1.6"
25
+ s.add_development_dependency "rake"
26
+ s.add_development_dependency "minitest"
27
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vultr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Tolbkni Kao
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-10 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.0
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.0
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.1
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.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Ruby bindings for VULTR API.
84
+ email:
85
+ - tolbkni@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - CHANGELOG.md
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/vultr.rb
97
+ - lib/vultr/version.rb
98
+ - test/vultr/test_vultr_os.rb
99
+ - test/vultr/test_vultr_plan.rb
100
+ - test/vultr/test_vultr_region.rb
101
+ - test/vultr/test_vultr_server.rb
102
+ - test/vultr/test_vultr_snapshot.rb
103
+ - test/vultr/test_vultr_startupscript.rb
104
+ - vultr.gemspec
105
+ homepage: https://github.com/tolbkni/vultr
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.2.2
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Ruby bindings for VULTR API.
129
+ test_files:
130
+ - test/vultr/test_vultr_os.rb
131
+ - test/vultr/test_vultr_plan.rb
132
+ - test/vultr/test_vultr_region.rb
133
+ - test/vultr/test_vultr_server.rb
134
+ - test/vultr/test_vultr_snapshot.rb
135
+ - test/vultr/test_vultr_startupscript.rb