scalarium-api-wrapper 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.markdown +135 -0
- data/Rakefile +1 -0
- data/lib/scalarium-api-wrapper.rb +24 -0
- data/lib/scalarium-api-wrapper/api.rb +65 -0
- data/lib/scalarium-api-wrapper/configuration.rb +8 -0
- data/lib/scalarium-api-wrapper/version.rb +7 -0
- data/scalarium-api-wrapper.gemspec +23 -0
- data/spec/api_spec.rb +42 -0
- data/spec/configuration_spec.rb +14 -0
- data/spec/spec_helper.rb +11 -0
- metadata +85 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
Scalarium API wrapper
|
2
|
+
===========
|
3
|
+
|
4
|
+
About
|
5
|
+
--
|
6
|
+
Since Scalarium is currently (June 2011) not supporting roles and therefore it is troublesome/risky to give all the development team members full access to the clouds/applications this library will allow easy setup of local environments for anyone minimizing the risk of 'stoping' the production environment.
|
7
|
+
For example limiting only to one cloud or application (development environment).
|
8
|
+
|
9
|
+
All the documentation for Scalarium API - ([http://support.scalarium.com/kb/api](http://support.scalarium.com/kb/api))
|
10
|
+
|
11
|
+
It can:
|
12
|
+
|
13
|
+
* Obtain a list of all clouds
|
14
|
+
* Obtain a list of all applications
|
15
|
+
* Perform deploy of specified application, stop/start/restart clouds
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Install
|
21
|
+
--
|
22
|
+
Clone this repository
|
23
|
+
<pre><code>$ git clone http://github.com/luki3k5/scalarium-api-wrapper</code></pre>
|
24
|
+
or install the gem
|
25
|
+
<pre><code>$ gem install scalarium-api-wrapper</code></pre>
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
Setup
|
31
|
+
--
|
32
|
+
You need to pass your api token to the Scalarium.configuration:
|
33
|
+
<pre>
|
34
|
+
<code>Scalarium.configuration.api_token = "YOUR TOKEN"</code></pre>
|
35
|
+
|
36
|
+
You can obtain your token at ([https://manage.scalarium.com/users](https://manage.scalarium.com/users)) - I highly encourage to setup new user with (i.e. devdeploy) and then render him new API_TOKEN.
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
Usage
|
42
|
+
--
|
43
|
+
|
44
|
+
After the api token is set you can create API class instance:
|
45
|
+
|
46
|
+
|
47
|
+
<pre>
|
48
|
+
<code>api = Scalarium::API.new</code>
|
49
|
+
</pre>
|
50
|
+
|
51
|
+
and then for example execute a deploy for one of your applications:
|
52
|
+
|
53
|
+
<pre>
|
54
|
+
<code>api.deploy_application('application_id')</code>
|
55
|
+
</pre>
|
56
|
+
|
57
|
+
to obtain list of all possible applications execute:
|
58
|
+
<pre>
|
59
|
+
<code>api.get_applications</code>
|
60
|
+
</pre>
|
61
|
+
|
62
|
+
notice that this will return array of all applications currently available for this user account.
|
63
|
+
To get ID one could execute:
|
64
|
+
|
65
|
+
<pre>
|
66
|
+
<code>api.get_applications.each do |app|
|
67
|
+
puts "app name: #{app['name']} -- app id: #{app['id']} "
|
68
|
+
end</code>
|
69
|
+
</pre>
|
70
|
+
|
71
|
+
Here are the fields returned in each hash:
|
72
|
+
<pre>
|
73
|
+
<code>
|
74
|
+
"id",
|
75
|
+
"name",
|
76
|
+
"ssl_certificate",
|
77
|
+
"scm_url",
|
78
|
+
"application_type",
|
79
|
+
"rails_env",
|
80
|
+
"deleted_at",
|
81
|
+
"ssl_certificate_key",
|
82
|
+
"scm_revision",
|
83
|
+
"ssl_support",
|
84
|
+
"scm_ssh_key",
|
85
|
+
"scm_user",
|
86
|
+
"domain_names",
|
87
|
+
"document_root",
|
88
|
+
"created_at",
|
89
|
+
"scm_password",
|
90
|
+
"auto_bundle_on_deploy",
|
91
|
+
"updated_at",
|
92
|
+
"mounted_at",
|
93
|
+
"description",
|
94
|
+
"domain_name",
|
95
|
+
"ssl_certificate_ca",
|
96
|
+
"cluster_id",
|
97
|
+
"scm_type",
|
98
|
+
"slug_name"</code>
|
99
|
+
</pre>
|
100
|
+
|
101
|
+
for their meaning check Scalarium's documentation and examples
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
License
|
107
|
+
--
|
108
|
+
|
109
|
+
Copyright (c) 2010 Lukasz Lazewski
|
110
|
+
|
111
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
112
|
+
a copy of this software and associated documentation files (the
|
113
|
+
"Software"), to deal in the Software without restriction, including
|
114
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
115
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
116
|
+
permit persons to whom the Software is furnished to do so, subject to
|
117
|
+
the following conditions:
|
118
|
+
|
119
|
+
The above copyright notice and this permission notice shall be
|
120
|
+
included in all copies or substantial portions of the Software.
|
121
|
+
|
122
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
123
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
124
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
125
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
126
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
127
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
128
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
129
|
+
|
130
|
+
|
131
|
+
Credits
|
132
|
+
--
|
133
|
+
|
134
|
+
luki3k5 (Lukasz Lazewski)
|
135
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Scalarium
|
2
|
+
|
3
|
+
def self.clouds_url
|
4
|
+
Scalarium.configuration.clouds_url
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.applications_url
|
8
|
+
Scalarium.configuration.applications_url
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.headers
|
12
|
+
return {'X-Scalarium-Token' => "#{Scalarium.configuration.api_token}", 'Accept' => 'application/vnd.scalarium-v1+json' }
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [Configuration] The configuration singleton.
|
16
|
+
def self.configuration
|
17
|
+
@configuration ||= Scalarium::Configuration.new
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
require "scalarium-api-wrapper/version"
|
23
|
+
require "scalarium-api-wrapper/configuration"
|
24
|
+
require "scalarium-api-wrapper/api"
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Scalarium
|
5
|
+
|
6
|
+
class API
|
7
|
+
|
8
|
+
# Method fetches all clouds on the server
|
9
|
+
#
|
10
|
+
# @option headers [Hash] - hash for of headers details for authentication
|
11
|
+
# @returns array [Array] - array containing all the clouds
|
12
|
+
#
|
13
|
+
def get_clouds
|
14
|
+
http_get_request(Scalarium.clouds_url)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Method fetches all applications on the server
|
18
|
+
#
|
19
|
+
# @option headers [Hash] - hash for of headers details for authentication
|
20
|
+
# @returns array [Array] - array containing all the applications
|
21
|
+
#
|
22
|
+
def get_applications
|
23
|
+
http_get_request(Scalarium.applications_url)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Method allows to deploy application in scalarium
|
27
|
+
#
|
28
|
+
# @option app_id [String] - The ID of application we want to deploy.
|
29
|
+
#
|
30
|
+
# @option options [Hash] - Hash with options:
|
31
|
+
# :comment - comment to be displayed on the deployment
|
32
|
+
# :migrate - boolean indicating if we should run the migrations too (false by default)
|
33
|
+
#
|
34
|
+
# @returns [Hash] response of the progress and details
|
35
|
+
#
|
36
|
+
def deploy_application(app_id, options = {:comment => nil, :migrate => false})
|
37
|
+
json_command = JSON.dump(:command => 'deploy',
|
38
|
+
:comment => options[:comment],
|
39
|
+
:migrate => options[:migrate])
|
40
|
+
http_post_request(Scalarium.applications_url+"/#{app_id}/deploy", json_command)
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
private
|
45
|
+
def get_headers
|
46
|
+
# quick validation if the header is set
|
47
|
+
if Scalarium.headers['X-Scalarium-Token'].nil? || Scalarium.headers['X-Scalarium-Token'] == ""
|
48
|
+
raise AttributeException "X-Scalarium-Token is not set"
|
49
|
+
end
|
50
|
+
Scalarium.headers
|
51
|
+
end
|
52
|
+
|
53
|
+
# Method uses RestClient to make a HTTP POST request to Scalarium API
|
54
|
+
def http_post_request(url, json_command)
|
55
|
+
JSON.parse(RestClient.post(url, json_command, get_headers))
|
56
|
+
end
|
57
|
+
|
58
|
+
# Method uses RestClient to make a HTTP GET request to Scalarium API
|
59
|
+
def http_get_request(url)
|
60
|
+
JSON.parse(RestClient.get(url, get_headers))
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "scalarium-api-wrapper/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "scalarium-api-wrapper"
|
7
|
+
s.version = Scalarium::Api::Wrapper::VERSION
|
8
|
+
s.authors = ["luki3k5"]
|
9
|
+
s.email = ["luki3k5@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{This is scalarium API wrapper}
|
12
|
+
s.description = %q{This is scalarium API wrapper, allowing to execute API calls to scalarium backend}
|
13
|
+
|
14
|
+
s.add_development_dependency('rake')
|
15
|
+
s.add_development_dependency('rspec', '~> 2.0')
|
16
|
+
|
17
|
+
s.rubyforge_project = "scalarium-api-wrapper"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
data/spec/api_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Scalarium::API", "when first created" do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
Scalarium.configuration.api_token = "FAKE_TOKEN"
|
7
|
+
@api = Scalarium::API.new
|
8
|
+
@clouds_url = "https://manage.scalarium.com/api/clouds"
|
9
|
+
@applications_url = "https://manage.scalarium.com/api/applications"
|
10
|
+
end
|
11
|
+
|
12
|
+
# notice that get_headers is private method so we test it thru send
|
13
|
+
it "should have api token in headers set" do
|
14
|
+
@api.send(:get_headers)['X-Scalarium-Token'].should == "FAKE_TOKEN"
|
15
|
+
end
|
16
|
+
|
17
|
+
# notice that get_headers is private method so we test it thru send
|
18
|
+
it "should have Accept piece of header set automatically " do
|
19
|
+
@api.send(:get_headers)['Accept'].should == "application/vnd.scalarium-v1+json"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "Scalarium Module should return correct applications url" do
|
23
|
+
Scalarium.applications_url.should == @applications_url
|
24
|
+
end
|
25
|
+
|
26
|
+
it "Scalarium Module should return correct clouds url" do
|
27
|
+
Scalarium.clouds_url.should == @clouds_url
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be able to deploy application" do
|
31
|
+
@api.should respond_to(:deploy_application)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be able to get all the clouds" do
|
35
|
+
@api.should respond_to(:get_clouds)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be able to get all the applications" do
|
39
|
+
@api.should respond_to(:get_applications)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Scalarium.configuration", "when first created" do
|
4
|
+
|
5
|
+
it "should has no api token set yet" do
|
6
|
+
Scalarium.configuration.api_token.should == nil
|
7
|
+
end
|
8
|
+
|
9
|
+
it "we should be able to set api token and check it's presence" do
|
10
|
+
Scalarium.configuration.api_token = "FAKE_TOKEN"
|
11
|
+
Scalarium.configuration.api_token.should == "FAKE_TOKEN"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scalarium-api-wrapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.9
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- luki3k5
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-06-20 00:00:00.000000000 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rake
|
17
|
+
requirement: &2164547980 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2164547980
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
requirement: &2164547360 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *2164547360
|
37
|
+
description: This is scalarium API wrapper, allowing to execute API calls to scalarium
|
38
|
+
backend
|
39
|
+
email:
|
40
|
+
- luki3k5@gmail.com
|
41
|
+
executables: []
|
42
|
+
extensions: []
|
43
|
+
extra_rdoc_files: []
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- Gemfile
|
47
|
+
- README.markdown
|
48
|
+
- Rakefile
|
49
|
+
- lib/scalarium-api-wrapper.rb
|
50
|
+
- lib/scalarium-api-wrapper/api.rb
|
51
|
+
- lib/scalarium-api-wrapper/configuration.rb
|
52
|
+
- lib/scalarium-api-wrapper/version.rb
|
53
|
+
- scalarium-api-wrapper.gemspec
|
54
|
+
- spec/api_spec.rb
|
55
|
+
- spec/configuration_spec.rb
|
56
|
+
- spec/spec_helper.rb
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: ''
|
59
|
+
licenses: []
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project: scalarium-api-wrapper
|
78
|
+
rubygems_version: 1.6.2
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: This is scalarium API wrapper
|
82
|
+
test_files:
|
83
|
+
- spec/api_spec.rb
|
84
|
+
- spec/configuration_spec.rb
|
85
|
+
- spec/spec_helper.rb
|