pagoda-client 0.1.0
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/Rakefile +9 -0
- data/lib/.DS_Store +0 -0
- data/lib/pagoda-client/apis/app.rb +73 -0
- data/lib/pagoda-client/apis/billing.rb +6 -0
- data/lib/pagoda-client/apis/collaborator.rb +6 -0
- data/lib/pagoda-client/apis/componant.rb +13 -0
- data/lib/pagoda-client/apis/database.rb +35 -0
- data/lib/pagoda-client/apis/email.rb +6 -0
- data/lib/pagoda-client/apis/transaction.rb +15 -0
- data/lib/pagoda-client/apis/user.rb +13 -0
- data/lib/pagoda-client/client.rb +105 -0
- data/lib/pagoda-client.rb +5 -0
- data/pagoda-client.gemspec +31 -0
- data/spec/client_spec.rb +135 -0
- metadata +106 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/lib/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Pagoda
|
2
|
+
module Api
|
3
|
+
module App
|
4
|
+
|
5
|
+
#############
|
6
|
+
# Get
|
7
|
+
#############
|
8
|
+
def app_available?(app)
|
9
|
+
json get("/apps/#{app}/available.json")
|
10
|
+
end
|
11
|
+
|
12
|
+
def app_list
|
13
|
+
json get("/apps.json")
|
14
|
+
end
|
15
|
+
|
16
|
+
def app_info(app)
|
17
|
+
json get("/apps/#{app}")
|
18
|
+
end
|
19
|
+
|
20
|
+
#############
|
21
|
+
# put
|
22
|
+
#############
|
23
|
+
|
24
|
+
|
25
|
+
def app_scale_up(app, qty=1)
|
26
|
+
put("/apps/#{app}/scale-up", {:quantity => qty})
|
27
|
+
end
|
28
|
+
|
29
|
+
def app_scale_down(app, qty=1)
|
30
|
+
put("/apps/#{app}/scale-down", {:quantity => qty})
|
31
|
+
end
|
32
|
+
|
33
|
+
def app_update(app, updates)
|
34
|
+
put("/apps/#{app}", {:app => updates}).to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
#############
|
39
|
+
# post
|
40
|
+
#############
|
41
|
+
def app_create(name)
|
42
|
+
user_id = user_info[:id]
|
43
|
+
json post("/apps", {:app => {:name => name, :owner_id => user_id}})
|
44
|
+
end
|
45
|
+
|
46
|
+
def app_deploy_latest(app)
|
47
|
+
post("/apps/#{app}/deploys")
|
48
|
+
end
|
49
|
+
|
50
|
+
def app_deploy(app, branch, commit)
|
51
|
+
post("/apps/#{app}/deploys", {:deploy => {:git_branch => branch, :commit => commit}})
|
52
|
+
end
|
53
|
+
|
54
|
+
def app_rollback(app)
|
55
|
+
json post("/apps/#{app}/deploys/rollback")
|
56
|
+
end
|
57
|
+
|
58
|
+
def app_fast_forward(app)
|
59
|
+
# Not sure what goes in here yet
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
#############
|
64
|
+
# Delete
|
65
|
+
#############
|
66
|
+
|
67
|
+
def app_destroy(app)
|
68
|
+
delete("/apps/#{app}.json")
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Pagoda
|
2
|
+
module Api
|
3
|
+
module Database
|
4
|
+
|
5
|
+
def database_list(app)
|
6
|
+
json get("/apps/#{app}/databases")
|
7
|
+
end
|
8
|
+
|
9
|
+
def database_info(app, database)
|
10
|
+
json get("/apps/#{app}/databases/#{database}")
|
11
|
+
end
|
12
|
+
|
13
|
+
def database_create(app)
|
14
|
+
post("/apps/#{app}/databases", {:type => :mysql})
|
15
|
+
end
|
16
|
+
|
17
|
+
def database_destroy(app, database)
|
18
|
+
delete("/apps/#{app}/databases/#{database}")
|
19
|
+
end
|
20
|
+
|
21
|
+
def database_update(app, database, cpu, ram)
|
22
|
+
# \/ maybe???
|
23
|
+
# put("/apps/#{app}/databases/#{database}", { :update => {:cpu => cpu, :ram => ram } } )
|
24
|
+
end
|
25
|
+
|
26
|
+
def database_exists?(app, database)
|
27
|
+
get("/apps/#{app}/databases/#{database}")
|
28
|
+
true
|
29
|
+
rescue RestClient::ResourceNotFound => e
|
30
|
+
false
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Pagoda
|
2
|
+
module Api
|
3
|
+
module Transaction
|
4
|
+
|
5
|
+
def transaction_info(app, transaction)
|
6
|
+
json get("/apps/#{app}/transactions/#{transaction}")
|
7
|
+
end
|
8
|
+
|
9
|
+
def transaction_list(app)
|
10
|
+
json get("/apps/#{app}/transactions")
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest_client'
|
3
|
+
|
4
|
+
# Mix-In's
|
5
|
+
require 'pagoda-client/apis/app'
|
6
|
+
require 'pagoda-client/apis/user'
|
7
|
+
require 'pagoda-client/apis/componant'
|
8
|
+
require 'pagoda-client/apis/billing'
|
9
|
+
require 'pagoda-client/apis/email'
|
10
|
+
require 'pagoda-client/apis/collaborator'
|
11
|
+
require 'pagoda-client/apis/transaction'
|
12
|
+
require 'pagoda-client/apis/database'
|
13
|
+
|
14
|
+
module Pagoda
|
15
|
+
class Client
|
16
|
+
VERSION = "0.1.0"
|
17
|
+
|
18
|
+
# Mix ins (cleaner)
|
19
|
+
include Api::App
|
20
|
+
include Api::User
|
21
|
+
include Api::Componant
|
22
|
+
include Api::Billing
|
23
|
+
include Api::Email
|
24
|
+
include Api::Collaborator
|
25
|
+
include Api::Transaction
|
26
|
+
include Api::Database
|
27
|
+
|
28
|
+
attr_reader :user, :password
|
29
|
+
|
30
|
+
def initialize(user, password)
|
31
|
+
@user = user
|
32
|
+
@password = password
|
33
|
+
end
|
34
|
+
|
35
|
+
class << self
|
36
|
+
def version
|
37
|
+
VERSION
|
38
|
+
end
|
39
|
+
|
40
|
+
def gem_version_string
|
41
|
+
"pagoda-gem/#{version}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def api_key
|
46
|
+
user_info[:authentication_token]
|
47
|
+
end
|
48
|
+
|
49
|
+
def valid_credentials?
|
50
|
+
get("/apps")
|
51
|
+
true
|
52
|
+
rescue RestClient::Unauthorized
|
53
|
+
false
|
54
|
+
#will poke pagoda and validate credentials
|
55
|
+
end
|
56
|
+
|
57
|
+
def host
|
58
|
+
"https://dashboard.newpagodabox.com"
|
59
|
+
end
|
60
|
+
|
61
|
+
protected
|
62
|
+
|
63
|
+
def resource(uri)
|
64
|
+
RestClient.proxy = ENV['HTTP_PROXY'] || ENV['http_proxy']
|
65
|
+
# RestClient::Resource.new("http://127.0.0.1:3000#{uri}", :user => @user, :password => @password, :content_type => 'application/json')
|
66
|
+
RestClient::Resource.new("#{host}#{uri}", @user, @password)
|
67
|
+
end
|
68
|
+
|
69
|
+
def get(uri, extra_headers={})
|
70
|
+
process(:get, uri, extra_headers)
|
71
|
+
end
|
72
|
+
|
73
|
+
def post(uri, payload="", extra_headers={})
|
74
|
+
process(:post, uri, extra_headers, payload)
|
75
|
+
end
|
76
|
+
|
77
|
+
def put(uri, payload="", extra_headers={})
|
78
|
+
process(:put, uri, extra_headers, payload)
|
79
|
+
end
|
80
|
+
|
81
|
+
def delete(uri, extra_headers={})
|
82
|
+
process(:delete, uri, extra_headers)
|
83
|
+
end
|
84
|
+
|
85
|
+
def process(method, uri, extra_headers={}, payload=nil)
|
86
|
+
headers = pagoda_headers.merge(extra_headers)
|
87
|
+
args = [method, payload, headers].compact
|
88
|
+
response = resource(uri).send(*args)
|
89
|
+
end
|
90
|
+
|
91
|
+
def pagoda_headers
|
92
|
+
{
|
93
|
+
'User-Agent' => self.class.gem_version_string,
|
94
|
+
'X-Ruby-Version' => RUBY_VERSION,
|
95
|
+
'X-Ruby-Platform' => RUBY_PLATFORM,
|
96
|
+
'Accept' => 'application/json'
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
def json(content)
|
101
|
+
JSON.parse(content, :symbolize_names => true)
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "pagoda-client"
|
6
|
+
s.version = "0.1.0"
|
7
|
+
s.authors = ["Lyon"]
|
8
|
+
s.email = ["lyon@pagodabox.com"]
|
9
|
+
s.homepage = "http://www.pagodabox.com"
|
10
|
+
s.summary = %q{Pagodabox API client}
|
11
|
+
s.description = %q{Api client used to talk to pagodabox.}
|
12
|
+
|
13
|
+
s.rubyforge_project = "pagoda-client"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
# testing dependencies
|
21
|
+
s.add_development_dependency "rspec"
|
22
|
+
s.add_development_dependency "webmock"
|
23
|
+
# s.add_development_dependency "simplecov"
|
24
|
+
|
25
|
+
|
26
|
+
# real dependencies
|
27
|
+
s.add_dependency "rest-client"
|
28
|
+
s.add_dependency "json_pure"
|
29
|
+
|
30
|
+
|
31
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'webmock'
|
3
|
+
|
4
|
+
require 'pagoda-client'
|
5
|
+
|
6
|
+
include WebMock::API
|
7
|
+
|
8
|
+
def stub_api_request(method, path, body=nil)
|
9
|
+
url = "https://user:password@api.pagodabox.com"
|
10
|
+
(body ? stub_request(method, "#{url}#{path}").with(body: body) : stub_request(method, "#{url}#{path}"))
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
describe Pagoda::Client do
|
15
|
+
|
16
|
+
before :all do
|
17
|
+
@client = Pagoda::Client.new("user","password")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have more functionality added" do
|
21
|
+
pending("additional functionality needed to make this a real client")
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
describe "app" do
|
26
|
+
|
27
|
+
it "gathers the app list correctly" do
|
28
|
+
stub = [
|
29
|
+
{id: 1, name: "app1", componants: 3},
|
30
|
+
{id: 2, name: 'appledumpling', componants: 6}
|
31
|
+
]
|
32
|
+
stub_api_request(:get, "/apps").to_return(body: stub.to_json)
|
33
|
+
@client.app_list.should == stub
|
34
|
+
end
|
35
|
+
|
36
|
+
it "collects informationt about the app" do
|
37
|
+
stub = {
|
38
|
+
:name => "App",
|
39
|
+
:git_url => "github.com",
|
40
|
+
:owner => {
|
41
|
+
:username => "lyon",
|
42
|
+
:email => "lyon@pagodabox.com"
|
43
|
+
},
|
44
|
+
:collaborators => [
|
45
|
+
{
|
46
|
+
:username => "tyler",
|
47
|
+
:email => "tyler@pagodabox.com"
|
48
|
+
},
|
49
|
+
{
|
50
|
+
:username => "clay",
|
51
|
+
:email => "clay@pagodabox.com"
|
52
|
+
}
|
53
|
+
]
|
54
|
+
}
|
55
|
+
stub_api_request(:get, "/apps/app").to_return(body: stub.to_json)
|
56
|
+
@client.app_info("app").should == stub
|
57
|
+
end
|
58
|
+
|
59
|
+
it "show the transaction list for an app" do
|
60
|
+
stub = [
|
61
|
+
{:id => '1', :name => 'app.increment', :description => 'spawn new instance of app', :state => 'started', :status => nil},
|
62
|
+
{:id => '2', :name => 'app.deploy', :description => 'deploy code', :state => 'ready', :status => nil}
|
63
|
+
]
|
64
|
+
stub_api_request(:get, "/apps/testapp/transactions").to_return(:body => stub.to_json)
|
65
|
+
@client.app_transaction_list('testapp').should == stub
|
66
|
+
end
|
67
|
+
|
68
|
+
it "lists transaction details" do
|
69
|
+
stub = {
|
70
|
+
:id => '123',
|
71
|
+
:name => 'app.increment',
|
72
|
+
:description => 'spawn new instance of app',
|
73
|
+
:state => 'started',
|
74
|
+
:status => nil}
|
75
|
+
stub_api_request(:get, "/apps/testapp/transactions/123").to_return(:body => stub.to_json)
|
76
|
+
@client.app_transaction_info('testapp', '123').should == stub
|
77
|
+
end
|
78
|
+
|
79
|
+
it "deploys lastest" do
|
80
|
+
stub = {:id => '1', :name => 'app.deploy', :description => 'deploy new code', :state => 'started', :status => nil}
|
81
|
+
stub_api_request(:post, "/apps/testapp/deploy").to_return(:body => stub.to_json)
|
82
|
+
@client.app_deploy_latest('testapp').code.should == 200
|
83
|
+
end
|
84
|
+
|
85
|
+
it "deploys to a specific branch and commit" do
|
86
|
+
stub = {:id => '1', :name => 'app.deploy', :description => 'deploy new code', :state => 'started', :status => nil}
|
87
|
+
stub_api_request(:post, "/apps/testapp/deploy").to_return(:body => stub.to_json)
|
88
|
+
@client.app_deploy('testapp', "master", "1abs3d432").code.should == 200
|
89
|
+
end
|
90
|
+
|
91
|
+
it "scales up" do
|
92
|
+
stub_api_request(:put, "/apps/testapp/scale-up").with(:body => {"quantity"=>"1"})
|
93
|
+
@client.app_scale_up('testapp').code.should == 200
|
94
|
+
end
|
95
|
+
|
96
|
+
it "scales down" do
|
97
|
+
stub_api_request(:put, "/apps/testapp/scale-down").with(:body => {"quantity"=>"3"})
|
98
|
+
@client.app_scale_down('testapp', 3).code.should == 200
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "database" do
|
104
|
+
|
105
|
+
it "can tell if a database exists or not" do
|
106
|
+
stub = {:error => "what are you doing? get outa here"}
|
107
|
+
stub_api_request(:get, "/apps/app/databases/db").to_return(status: 200,body: stub)
|
108
|
+
@client.database_exists?("app", "db").should == true
|
109
|
+
end
|
110
|
+
|
111
|
+
it "returns false if a database doesnt exist" do
|
112
|
+
stub = {:error => "what are you doing? get outa here"}
|
113
|
+
stub_api_request(:get, "/apps/app/databases/nodb").to_return(status: 404, body: stub)
|
114
|
+
@client.database_exists?("app", "nodb").should == false
|
115
|
+
end
|
116
|
+
|
117
|
+
it "lists databases for an application" do
|
118
|
+
stub = [
|
119
|
+
{:id => '1', :name => 'carrie', :type => 'mysql', :ram => 10 },
|
120
|
+
{:id => '2', :name => 'cherisse', :type => 'mongodb', :ram => 512}
|
121
|
+
]
|
122
|
+
stub_api_request(:get, "/apps/app/databases").to_return(body: stub.to_json)
|
123
|
+
@client.database_list("app").should == stub
|
124
|
+
end
|
125
|
+
|
126
|
+
it "creates a new database" do
|
127
|
+
stub_api_request(:post, "/apps/app/databases").to_return(status: 200)
|
128
|
+
@client.database_create("app").code.should == 200
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pagoda-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lyon
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-12 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &2152906460 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2152906460
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: webmock
|
27
|
+
requirement: &2152905640 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2152905640
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rest-client
|
38
|
+
requirement: &2152904680 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2152904680
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: json_pure
|
49
|
+
requirement: &2152903200 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2152903200
|
58
|
+
description: Api client used to talk to pagodabox.
|
59
|
+
email:
|
60
|
+
- lyon@pagodabox.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- Gemfile
|
67
|
+
- Rakefile
|
68
|
+
- lib/.DS_Store
|
69
|
+
- lib/pagoda-client.rb
|
70
|
+
- lib/pagoda-client/apis/app.rb
|
71
|
+
- lib/pagoda-client/apis/billing.rb
|
72
|
+
- lib/pagoda-client/apis/collaborator.rb
|
73
|
+
- lib/pagoda-client/apis/componant.rb
|
74
|
+
- lib/pagoda-client/apis/database.rb
|
75
|
+
- lib/pagoda-client/apis/email.rb
|
76
|
+
- lib/pagoda-client/apis/transaction.rb
|
77
|
+
- lib/pagoda-client/apis/user.rb
|
78
|
+
- lib/pagoda-client/client.rb
|
79
|
+
- pagoda-client.gemspec
|
80
|
+
- spec/client_spec.rb
|
81
|
+
homepage: http://www.pagodabox.com
|
82
|
+
licenses: []
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project: pagoda-client
|
101
|
+
rubygems_version: 1.8.10
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: Pagodabox API client
|
105
|
+
test_files:
|
106
|
+
- spec/client_spec.rb
|