Acquia API gem
Ruby implementation of the Acquia Cloud API.
Installation
Add this line to your application’s Gemfile:
gem 'acquia-api'
And then execute:
$ bundle
Or install it yourself as:
$ gem install acquia-api
Example Usage
We’re going to assume we’re testing a production deploy of tag release-34
by deploying to the test
environment, since we’d want to do this before running through a similar process on prod
itself.
“ require ‘acapi’
Site/subscription will be auto-detected from credentials.
- client = AcquiaCloudApi::Client.new(
- username => ‘39513c57-364a-3d2f-4e6a-654d5a793535’,
- password => ‘Vah6ewCG0zn0IiQ8ylLyv8rRFZ2vZyAysOSguHkk1mfl9GQuEK3x’ )
client.add_domain ‘staging.example.com’, :test client.copy_files! :prod, :test
Collect response data from methods for later use.
responses = [] responses « client.copy_database! ‘my_database’, :prod, :test responses « client.deploy! ‘release-34’, :test
Output status of tasks for fun.
#
SAMPLE OUTPUT
code-push task status: done
db-migrate task status: done
responses.each do |res| puts “#res[queue] task status: #res[id]” end
Wait for db copy and deploy tasks to complete.
responses.each do |res| client.poll_task res[id] end
“
Auto-polling methods
If you would rather have certain methods automatically wait for their respective tasks to complete before moving on, paste this into the top of your code. (You’ll likely want to add more functions than :create_database
.)
“ require ‘acapi’
module AcquiaCloudApi class Client
[
:create_database!
].each do |method|
alias_method "original_#{method}".to_sym, method.to_sym
define_method method.to_sym do |*args|
response = self.send("original_#{method}".to_sym, *args)
task_id = response['id']
poll_task(task_id)
original_reponse = response
end
end
end end
Client#create_database will now wait for database creation task to complete.
client.create_database! ‘testing123’
“
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request