addons-client 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/addons-client/cli.rb +6 -0
- data/lib/addons-client/client.rb +24 -6
- data/lib/addons-client/response.rb +5 -1
- data/lib/addons-client/version.rb +1 -1
- data/test/list_test.rb +42 -0
- metadata +12 -10
data/lib/addons-client/cli.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'bigdecimal'
|
1
2
|
module Addons::CLI
|
2
3
|
extend self
|
3
4
|
|
@@ -9,6 +10,11 @@ module Addons::CLI
|
|
9
10
|
def run_command!
|
10
11
|
command = Settings.rest.first
|
11
12
|
case command
|
13
|
+
when /list/i
|
14
|
+
response = client.list(Settings.rest[1..-1].join(" "))
|
15
|
+
response.data.each do |addon_plan|
|
16
|
+
puts "#{addon_plan["name"]} $%0.2f/#{addon_plan["price_unit"]}" % (BigDecimal.new(addon_plan["price_cents"].to_s) / 100)
|
17
|
+
end
|
12
18
|
when /deprovision/i
|
13
19
|
resource_id = Settings.rest[1]
|
14
20
|
raise Addons::UserError, "Must supply resource id" unless resource_id
|
data/lib/addons-client/client.rb
CHANGED
@@ -8,7 +8,20 @@ module Addons
|
|
8
8
|
@api_url = validate_api_url!
|
9
9
|
end
|
10
10
|
|
11
|
+
def self.list(search = nil)
|
12
|
+
wrap_request do
|
13
|
+
if mocked?
|
14
|
+
mocked_list(params)
|
15
|
+
else
|
16
|
+
payload = { :accept => :json }
|
17
|
+
payload[:params] = { :search => search } unless search.nil? || search == ""
|
18
|
+
resource["/addons"].get payload
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
11
23
|
def self.provision!(slug, opts = {})
|
24
|
+
validate_authenticated_api_url!
|
12
25
|
wrap_request do
|
13
26
|
addon_name, plan = slug.split(':')
|
14
27
|
raise UserError, "No add-on name given" unless addon_name
|
@@ -36,22 +49,24 @@ module Addons
|
|
36
49
|
config = config.to_json unless config.is_a? String
|
37
50
|
payload.merge! :config => config
|
38
51
|
end
|
39
|
-
resource.post payload, :accept => :json
|
52
|
+
resource["/resources"].post payload, :accept => :json
|
40
53
|
end
|
41
54
|
end
|
42
55
|
end
|
43
56
|
|
44
57
|
def self.deprovision!(resource_id)
|
58
|
+
validate_authenticated_api_url!
|
45
59
|
wrap_request do
|
46
60
|
if mocked?
|
47
61
|
mocked_deprovision(resource_id)
|
48
62
|
else
|
49
|
-
resource["/#{resource_id}"].delete :accept => :json
|
63
|
+
resource["/resources/#{resource_id}"].delete :accept => :json
|
50
64
|
end
|
51
65
|
end
|
52
66
|
end
|
53
67
|
|
54
68
|
def self.plan_change!(resource_id, plan)
|
69
|
+
validate_authenticated_api_url!
|
55
70
|
wrap_request do
|
56
71
|
if mocked?
|
57
72
|
mocked_plan_change(resource_id, plan)
|
@@ -59,7 +74,7 @@ module Addons
|
|
59
74
|
payload = {
|
60
75
|
:plan => plan,
|
61
76
|
}
|
62
|
-
resource["/#{resource_id}"].put payload, :accept => :json
|
77
|
+
resource["/resources/#{resource_id}"].put payload, :accept => :json
|
63
78
|
end
|
64
79
|
end
|
65
80
|
end
|
@@ -76,16 +91,19 @@ module Addons
|
|
76
91
|
raise UserError, "Add-on not found: check addon spelling and plan name"
|
77
92
|
end
|
78
93
|
|
94
|
+
def self.validate_authenticated_api_url!
|
95
|
+
raise UserError, "No username given" unless api_url.user
|
96
|
+
raise UserError, "No password given" unless api_url.password
|
97
|
+
end
|
98
|
+
|
79
99
|
def self.validate_api_url!
|
80
100
|
api_url = nil
|
81
101
|
raise UserError, "ADDONS_API_URL must be set" unless ENV['ADDONS_API_URL']
|
82
102
|
begin
|
83
|
-
api_url = URI.join(ENV['ADDONS_API_URL'], '/api/1
|
103
|
+
api_url = URI.join(ENV['ADDONS_API_URL'], '/api/1')
|
84
104
|
rescue URI::InvalidURIError
|
85
105
|
raise UserError, "ADDONS_API_URL is an invalid url"
|
86
106
|
end
|
87
|
-
raise UserError, "No username given" unless api_url.user
|
88
|
-
raise UserError, "No password given" unless api_url.password
|
89
107
|
api_url
|
90
108
|
end
|
91
109
|
end
|
@@ -15,6 +15,10 @@ module Addons
|
|
15
15
|
@data.to_s
|
16
16
|
end
|
17
17
|
|
18
|
+
def data
|
19
|
+
@data
|
20
|
+
end
|
21
|
+
|
18
22
|
def method_missing(name, *args, &blk)
|
19
23
|
if @data.keys.include? name
|
20
24
|
@data[name]
|
@@ -22,7 +26,7 @@ module Addons
|
|
22
26
|
@data[name.to_s]
|
23
27
|
else
|
24
28
|
super
|
25
|
-
end
|
29
|
+
end
|
26
30
|
end
|
27
31
|
end
|
28
32
|
end
|
data/test/list_test.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/test_helper"
|
2
|
+
|
3
|
+
class ListTest < Addons::Client::TestCase
|
4
|
+
def setup
|
5
|
+
ENV["ADDONS_API_URL"] = 'https://addons.heroku.com'
|
6
|
+
stub_request(:get, %r{#{target_url}}).to_return(:body => [
|
7
|
+
{"id" => "https://addons.heroku.com/addons/cloudcounter:basic","url" => "https://addons.heroku.com/addons/cloudcounter:basic","name" => "cloudcounter:basic","description" => "The basic counter of clouds","beta" => false,"state" => "public","price_cents" => 0,"price_unit" => "month"},
|
8
|
+
{"id" => "https://addons.heroku.com/addons/cloudcounter:pro","url" => "https://addons.heroku.com/addons/cloudcounter:pro","name" => "cloudcounter:pro","description" => "The counter of clouds for professionals","beta" => false,"state" => "public","price_cents" => 1500,"price_unit" => "month"}].
|
9
|
+
to_json)
|
10
|
+
stub(Addons::CLI).puts
|
11
|
+
end
|
12
|
+
|
13
|
+
def target_url
|
14
|
+
URI.join(ENV["ADDONS_API_URL"], '/api/1/addons').to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_cmd_line_lists_addons
|
18
|
+
addons_client! "list"
|
19
|
+
assert_requested(:get, target_url)
|
20
|
+
assert_received(Addons::CLI) do |cli|
|
21
|
+
cli.puts "cloudcounter:basic $0.00/month"
|
22
|
+
#cli.puts "cloudcounter:pro $15.00/month"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_cmd_line_passes_arguments
|
27
|
+
addons_client! "list cloud thing"
|
28
|
+
assert_requested(:get, target_url + "?search=cloud+thing")
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_lists_from_ruby
|
32
|
+
Addons::Client.list
|
33
|
+
assert_requested(:get, target_url)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_passes_args_from_ruby
|
37
|
+
Addons::Client.list "cloud thing"
|
38
|
+
assert_requested(:get, target_url + "?search=cloud+thing")
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: addons-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-08-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest-client
|
17
|
-
requirement: &
|
17
|
+
requirement: &70213275701300 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70213275701300
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: configliere
|
28
|
-
requirement: &
|
28
|
+
requirement: &70213275696460 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70213275696460
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: json
|
39
|
-
requirement: &
|
39
|
+
requirement: &70213275695480 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70213275695480
|
48
48
|
description: Addons Platform API client
|
49
49
|
email:
|
50
50
|
- csquared@gmail.com
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/addons-client/version.rb
|
72
72
|
- test/client_test.rb
|
73
73
|
- test/deprovision_test.rb
|
74
|
+
- test/list_test.rb
|
74
75
|
- test/plan_change_test.rb
|
75
76
|
- test/provision_test.rb
|
76
77
|
- test/response_test.rb
|
@@ -89,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
90
|
version: '0'
|
90
91
|
segments:
|
91
92
|
- 0
|
92
|
-
hash: -
|
93
|
+
hash: -1801222150168737241
|
93
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
95
|
none: false
|
95
96
|
requirements:
|
@@ -98,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
99
|
version: '0'
|
99
100
|
segments:
|
100
101
|
- 0
|
101
|
-
hash: -
|
102
|
+
hash: -1801222150168737241
|
102
103
|
requirements: []
|
103
104
|
rubyforge_project:
|
104
105
|
rubygems_version: 1.8.15
|
@@ -108,6 +109,7 @@ summary: Allows platfomrs to provision, deprovision, and change plans for add-on
|
|
108
109
|
test_files:
|
109
110
|
- test/client_test.rb
|
110
111
|
- test/deprovision_test.rb
|
112
|
+
- test/list_test.rb
|
111
113
|
- test/plan_change_test.rb
|
112
114
|
- test/provision_test.rb
|
113
115
|
- test/response_test.rb
|