Giter Club home page Giter Club logo

acquia-api's Introduction

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: #{client.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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

acquia-api's People

Contributors

sdboyer avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.