Sha256: 7903514ff5722311d6f54662f8459624770ebe6ca80e6cca5fafd55a942ab429
Contents?: true
Size: 1.67 KB
Versions: 10
Compression:
Stored size: 1.67 KB
Contents
module Acquia class Cloud class Api API_VERSION = 'v1' BASE_URL = 'https://cloudapi.acquia.com' def initialize(args = {}) @acquia = Faraday.new(:url => 'https://cloudapi.acquia.com') do |client| client.request :url_encoded client.adapter Faraday.default_adapter # Log request and response to STDOUT. # client.use Faraday::Response::Logger # Raise errors on HTTP error codes. client.use Faraday::Response::RaiseError end if args[:credentials].nil? if ENV['ACQUIA_CLOUD_CREDENTIALS'].nil? raise 'Unable to detect your credentials. Please populate ACQUIA_CLOUD_CREDENTIALS with your username and API key.' end args[:credentials] = ENV['ACQUIA_CLOUD_CREDENTIALS'] end credentials = args[:credentials].split(':', 2) if credentials.length < 2 raise 'You must specify both username and API key in credentials.' end @acquia.basic_auth *credentials end def get(url = nil, params = nil, headers = nil, &block) request :get, url, params, headers, &block end def post(url = nil, body = nil, headers = nil, &block) request :post, url, body.nil? ? body : body.to_json, headers, &block end def delete(url = nil, params = nil, headers = nil, &block) request :delete, url, params, headers, &block end protected def request(method, url = nil, arg2 = nil, headers = nil, &block) response = @acquia.method(method).call "/#{API_VERSION}#{url}.json", arg2, headers, &block JSON.load(response.body) end end end end
Version data entries
10 entries across 10 versions & 1 rubygems