lib/maestrano/api/operation/base.rb in maestrano-0.11.0 vs lib/maestrano/api/operation/base.rb in maestrano-0.12.0

- old
+ new

@@ -1,29 +1,27 @@ module Maestrano module API module Operation module Base - # class << self - # attr_accessor :api_token, :api_base, :verify_ssl_certs, :api_version - # end - + include Preset + def self.api_url(url='') - Maestrano.param('api.host') + Maestrano.param('api.base') + url + Maestrano[self.preset].param('api.host') + Maestrano[self.preset].param('api.base') + url end # Perform remote request def self.request(method, url, api_token, params={}, headers={}) - unless api_token ||= Maestrano.param('api_token') + unless api_token ||= Maestrano[self.preset].param('api_token') raise Maestrano::API::Error::AuthenticationError.new('No API key provided.') end request_opts = { :verify_ssl => false } if self.ssl_preflight_passed? request_opts.update( verify_ssl: OpenSSL::SSL::VERIFY_PEER, - ssl_ca_file: Maestrano.param('ssl_bundle_path') + ssl_ca_file: Maestrano[self.preset].param('ssl_bundle_path') ) end params = Util.objects_to_ids(params) url = api_url(url) @@ -67,17 +65,17 @@ end private def self.ssl_preflight_passed? - if !Maestrano.param('api.verify_ssl_certs') + if !Maestrano[self.preset].param('api.verify_ssl_certs') #$stderr.puts "WARNING: Running without SSL cert verification. " + # "Execute 'Maestrano.configure { |config| config.verify_ssl_certs = true' } to enable verification." return false - elsif !Util.file_readable(Maestrano.param('ssl_bundle_path')) + elsif !Util.file_readable(Maestrano[self.preset].param('ssl_bundle_path')) $stderr.puts "WARNING: Running without SSL cert verification " + - "because #{Maestrano.param('ssl_bundle_path')} isn't readable" + "because #{Maestrano[self.preset].param('ssl_bundle_path')} isn't readable" return false end return true @@ -85,13 +83,13 @@ def self.user_agent @uname ||= get_uname { - :bindings_version => Maestrano.param('api.version'), - :lang => Maestrano.param('api.lang'), - :lang_version => Maestrano.param('api.lang_version'), + :bindings_version => Maestrano[self.preset].param('api.version'), + :lang => Maestrano[self.preset].param('api.lang'), + :lang_version => Maestrano[self.preset].param('api.lang_version'), :platform => RUBY_PLATFORM, :publisher => 'maestrano', :uname => @uname } @@ -108,15 +106,15 @@ map { |k,v| "#{k}=#{Util.url_encode(v)}" }.join('&') end def self.request_headers(api_token) headers = { - :user_agent => "Maestrano/v1 RubyBindings/#{Maestrano.param('api.version')}", + :user_agent => "Maestrano/v1 RubyBindings/#{Maestrano[self.preset].param('api.version')}", :authorization => "Basic #{Base64.strict_encode64(api_token)}", :content_type => 'application/x-www-form-urlencoded' } - api_version = Maestrano.param('api_version') + api_version = Maestrano[self.preset].param('api_version') headers[:maestrano_version] = api_version if api_version begin headers.update(:x_maestrano_client_user_agent => JSON.generate(user_agent)) rescue => e \ No newline at end of file