scalarium-api-wrapper 0.2.10 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ spec/functional/scalarium.yml
data/README.markdown CHANGED
@@ -33,7 +33,7 @@ Setup
33
33
  <pre>
34
34
  <code>Scalarium.configuration.api_token = "YOUR TOKEN"</code></pre>
35
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.
36
+ You can obtain your token at ([https://manage.scalarium.com/users](https://manage.scalarium.com/users)) - I highly encourage to setup a new user in scalarium (i.e. devdeploy) and then render him new API_TOKEN.
37
37
 
38
38
 
39
39
 
@@ -54,7 +54,19 @@ and then for example execute a deploy for one of your applications:
54
54
  <code>api.deploy_application('application_id')</code>
55
55
  </pre>
56
56
 
57
- to obtain list of all possible applications execute:
57
+ This will return hash containing information about current deploy:
58
+ [Scalarium Documentation details](http://support.scalarium.com/kb/api/fetching-deployment-details)
59
+
60
+ We can then use the 'id' from the above hash and current application id to call for information about the progress:
61
+
62
+ <pre>
63
+ <code>api.fetch_deployment_details('application_id','deployment_id')</code>
64
+ </pre>
65
+
66
+ NOTE: We can always see the deploy status if we know proper deployment_id (even from the deploys that have been already finished)
67
+
68
+
69
+ to obtain list of all available applications execute:
58
70
  <pre>
59
71
  <code>api.get_applications</code>
60
72
  </pre>
@@ -100,13 +112,18 @@ Here are the fields returned in each hash:
100
112
 
101
113
  for their meaning check Scalarium's documentation and examples
102
114
 
115
+ Ruby on Rails integration
116
+ --
117
+
118
+ Here is a simple [RAKE task](https://gist.github.com/1037410) that illustrates how this library could be used with Rails application.
119
+
103
120
 
104
121
 
105
122
 
106
123
  License
107
124
  --
108
125
 
109
- Copyright (c) 2010 Lukasz Lazewski
126
+ Copyright (c) 2011 Lukasz Lazewski
110
127
 
111
128
  Permission is hereby granted, free of charge, to any person obtaining
112
129
  a copy of this software and associated documentation files (the
@@ -1,9 +1,11 @@
1
1
  module Scalarium
2
2
 
3
+ # @return [String] url for the clouds
3
4
  def self.clouds_url
4
5
  Scalarium.configuration.clouds_url
5
6
  end
6
7
 
8
+ # @return [String] url for the applications
7
9
  def self.applications_url
8
10
  Scalarium.configuration.applications_url
9
11
  end
@@ -16,6 +18,11 @@ module Scalarium
16
18
  def self.configuration
17
19
  @configuration ||= Scalarium::Configuration.new
18
20
  end
21
+
22
+ # setting an alias for :configuration
23
+ class << self
24
+ alias configure configuration
25
+ end
19
26
  end
20
27
 
21
28
 
@@ -7,7 +7,6 @@ module Scalarium
7
7
 
8
8
  # Method fetches all clouds on the server
9
9
  #
10
- # @option headers [Hash] - hash for of headers details for authentication
11
10
  # @returns array [Array] - array containing all the clouds
12
11
  #
13
12
  def get_clouds
@@ -16,13 +15,21 @@ module Scalarium
16
15
 
17
16
  # Method fetches all applications on the server
18
17
  #
19
- # @option headers [Hash] - hash for of headers details for authentication
20
18
  # @returns array [Array] - array containing all the applications
21
19
  #
22
20
  def get_applications
23
21
  http_get_request(Scalarium.applications_url)
24
22
  end
25
23
 
24
+ # Method pings scalarium to check the details of the deploy (i.e. progress)
25
+ # @see http://support.scalarium.com/kb/api/fetching-deployment-details
26
+ #
27
+ # @returns hash [Hash] - Hash contains all the deployment details
28
+ #
29
+ def fetch_deployment_details(app_id, deployment_id)
30
+ http_get_request(Scalarium.applications_url+"/#{app_id}/deployments/#{deployment_id}")
31
+ end
32
+
26
33
  # Method allows to deploy application in scalarium
27
34
  #
28
35
  # @option app_id [String] - The ID of application we want to deploy.
@@ -1,7 +1,7 @@
1
1
  module Scalarium
2
2
  module Api
3
3
  module Wrapper
4
- VERSION = "0.2.10"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
7
7
  end
@@ -11,6 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.summary = %q{This is scalarium API wrapper}
12
12
  s.description = %q{This is scalarium API wrapper, allowing to execute API calls to scalarium backend}
13
13
 
14
+ s.add_dependency('json')
14
15
  s.add_development_dependency('rake')
15
16
  s.add_development_dependency('rspec', '~> 2.0')
16
17
 
data/spec/api_spec.rb CHANGED
@@ -38,5 +38,10 @@ describe "Scalarium::API", "when first created" do
38
38
  it "should be able to get all the applications" do
39
39
  @api.should respond_to(:get_applications)
40
40
  end
41
+
42
+ it "should be able to get deployment status aka deployment details" do
43
+ @api.should respond_to(:fetch_deployment_details)
44
+ end
45
+
41
46
 
42
47
  end
@@ -6,9 +6,19 @@ describe "Scalarium.configuration", "when first created" do
6
6
  Scalarium.configuration.api_token.should == nil
7
7
  end
8
8
 
9
+ it "should has no api token set yet - testing thru alias" do
10
+ Scalarium.configure.api_token.should == nil
11
+ end
12
+
9
13
  it "we should be able to set api token and check it's presence" do
10
14
  Scalarium.configuration.api_token = "FAKE_TOKEN"
11
15
  Scalarium.configuration.api_token.should == "FAKE_TOKEN"
12
16
  end
13
17
 
18
+ it "by using alias we should be able to obtain details set thru 'configuration' check it's presence change it and check again" do
19
+ Scalarium.configure.api_token.should == "FAKE_TOKEN"
20
+ Scalarium.configure.api_token = "FAKE_TOKEN_NEW"
21
+ Scalarium.configure.api_token.should == "FAKE_TOKEN_NEW"
22
+ end
23
+
14
24
  end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+ require 'yaml'
3
+
4
+
5
+ describe "Scalarium functional tests", "when first created" do
6
+
7
+ before(:all) do
8
+ # we load configuration
9
+ config = YAML::load(File.open("./scalarium.yml"))
10
+ raise "!!! scalarium.yml file is missing - have your renamed scalarium.yml.sample into scalarium.yml? !!!" if config.nil?
11
+
12
+ Scalarium.configuration.api_token = config["api_token"]
13
+ @application_id = config["app_id"]
14
+ @comment = "This is test deploy by functional testing from scalarium-api-wrapper gem"
15
+
16
+ @api = Scalarium::API.new
17
+
18
+ # @response_status - this is initial response status
19
+ # returned after we make initial call to deploy application
20
+ @response_status = nil
21
+ # @status_check_response - this is status response for when we check
22
+ # progress of our deployment
23
+ @status_check_response = nil
24
+ end
25
+
26
+ it "should obtain list of applications and present an array" do
27
+ @api.get_applications.class.should == Array
28
+ end
29
+
30
+ it "should obtain list of clouds and present an array" do
31
+ @api.get_clouds.class.should == Array
32
+ end
33
+
34
+ it "should redeploy application with specified ID and comment: #{@comment} returning status should be in proper state" do
35
+ @response_status = @api.deploy_application(@application_id, :comment => @comment)
36
+ @response_status.class.should == Hash
37
+ @response_status["status"].should == "running"
38
+ @response_status["command"].should == "deploy"
39
+ @response_status["application_id"].should == @application_id
40
+
41
+ sleep 2
42
+ id_of_deployment = @response_status["id"]
43
+ @status_check_response = @api.fetch_deployment_details(@application_id, id_of_deployment)
44
+ @status_check_response.class.should == Hash
45
+ @status_check_response["status"].should == "running"
46
+ end
47
+
48
+ end
@@ -0,0 +1,5 @@
1
+ # IMPORTANT NOTE: functional test will deploy this application during testing
2
+ # so please make sure you are okay with that!
3
+
4
+ api_token: SET_YOUR_TOKEN_HERE
5
+ app_id: SET_YOUR_APPLICATION_ID
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scalarium-api-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,23 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-20 00:00:00.000000000 +02:00
12
+ date: 2011-06-24 00:00:00.000000000 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ requirement: &2153054260 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2153054260
15
26
  - !ruby/object:Gem::Dependency
16
27
  name: rake
17
- requirement: &2156892240 !ruby/object:Gem::Requirement
28
+ requirement: &2153053800 !ruby/object:Gem::Requirement
18
29
  none: false
19
30
  requirements:
20
31
  - - ! '>='
@@ -22,10 +33,10 @@ dependencies:
22
33
  version: '0'
23
34
  type: :development
24
35
  prerelease: false
25
- version_requirements: *2156892240
36
+ version_requirements: *2153053800
26
37
  - !ruby/object:Gem::Dependency
27
38
  name: rspec
28
- requirement: &2156891520 !ruby/object:Gem::Requirement
39
+ requirement: &2153053200 !ruby/object:Gem::Requirement
29
40
  none: false
30
41
  requirements:
31
42
  - - ~>
@@ -33,7 +44,7 @@ dependencies:
33
44
  version: '2.0'
34
45
  type: :development
35
46
  prerelease: false
36
- version_requirements: *2156891520
47
+ version_requirements: *2153053200
37
48
  description: This is scalarium API wrapper, allowing to execute API calls to scalarium
38
49
  backend
39
50
  email:
@@ -53,6 +64,8 @@ files:
53
64
  - scalarium-api-wrapper.gemspec
54
65
  - spec/api_spec.rb
55
66
  - spec/configuration_spec.rb
67
+ - spec/functional/api_functional_spec.rb
68
+ - spec/functional/scalarium.yml.sample
56
69
  - spec/spec_helper.rb
57
70
  has_rdoc: true
58
71
  homepage: ''
@@ -82,4 +95,6 @@ summary: This is scalarium API wrapper
82
95
  test_files:
83
96
  - spec/api_spec.rb
84
97
  - spec/configuration_spec.rb
98
+ - spec/functional/api_functional_spec.rb
99
+ - spec/functional/scalarium.yml.sample
85
100
  - spec/spec_helper.rb