Permalink
Browse files

Implement plan_change.

  • Loading branch information...
1 parent 726752f commit 34d6db82b8108c2b00ec19333d60bcba962133f5 Glenn Gillen committed Feb 22, 2012
Showing with 28 additions and 0 deletions.
  1. +8 −0 lib/addons-client/cli.rb
  2. +20 −0 lib/addons-client/client.rb
View
@@ -21,6 +21,14 @@ def run_command!
:consumer_id => Settings[:consumer_id])
puts "Provisioned #{slug}"
puts response
+ when /plan_change/i
+ resource_id = Settings.rest[1]
+ slug = Settings.rest[2]
+ raise UserError, "Must supply add-on:plan as second argument" unless slug
+ response = client.plan_change!(resource_id, slug,
+ :options => Settings[:options], :consumer_id => Settings[:consumer_id])
+ puts "Plan Changed to #{slug}"
+ puts response
else
if command
puts "#{command} is not a valid command"
@@ -38,6 +38,26 @@ def deprovision!(resource_id)
end
end
+ def plan_change!(resource_id, slug, opts = {})
+ wrap_request do
+ addon_name, plan = slug.split(':')
+ raise UserError, "No add-on name given" unless addon_name
+ raise UserError, "No plan name given" unless plan
+
+ if self.class.mocked?
+ mocked_plan_change(addon_name)
+ else
+ payload = {
+ addon: addon_name,
+ plan: plan,
+ consumer_id: opts[:consumer_id] || DEFAULT_CONSUMER_ID
+ }
+ payload.merge! :options => opts[:options] if opts[:options]
+ resource["/#{resource_id}"].put payload, :accept => :json
+ end
+ end
+ end
+
def resource
RestClient::Resource.new(@api_url.to_s)
end

0 comments on commit 34d6db8

Please sign in to comment.