lib/maestrano/api/operation/base.rb in maestrano-0.3.0 vs lib/maestrano/api/operation/base.rb in maestrano-0.4.0

- old
+ new

@@ -1,20 +1,20 @@ module Maestrano module API module Operation module Base # class << self - # attr_accessor :api_key, :api_base, :verify_ssl_certs, :api_version + # attr_accessor :api_token, :api_base, :verify_ssl_certs, :api_version # end def self.api_url(url='') Maestrano.param('api_host') + Maestrano.param('api_base') + url end # Perform remote request - def self.request(method, url, api_key, params={}, headers={}) - unless api_key ||= Maestrano.param('api_key') + def self.request(method, url, api_token, params={}, headers={}) + unless api_token ||= Maestrano.param('api_token') raise Maestrano::API::Error::AuthenticationError.new('No API key provided.') end request_opts = { :verify_ssl => false } @@ -35,11 +35,11 @@ payload = nil else payload = uri_encode(params) end - request_opts.update(:headers => request_headers(api_key).update(headers), + request_opts.update(:headers => request_headers(api_token).update(headers), :method => method, :open_timeout => 30, :payload => payload, :url => url, :timeout => 80) begin response = execute_request(request_opts) @@ -61,11 +61,11 @@ end rescue RestClient::Exception, Errno::ECONNREFUSED => e handle_restclient_error(e) end - [parse(response), api_key] + [parse(response), api_token] end private def self.ssl_preflight_passed? @@ -107,13 +107,13 @@ def self.uri_encode(params) Util.flatten_params(params). map { |k,v| "#{k}=#{Util.url_encode(v)}" }.join('&') end - def self.request_headers(api_key) + def self.request_headers(api_token) headers = { :user_agent => "Maestrano/v1 RubyBindings/#{Maestrano::VERSION}", - :authorization => "Basic #{Base64.encode64(api_key + ':')}", + :authorization => "Basic #{Base64.encode64(api_token)}", :content_type => 'application/x-www-form-urlencoded' } api_version = Maestrano.param('api_version') headers[:maestrano_version] = api_version if api_version \ No newline at end of file