Module: Nurego
- Defined in:
- lib/nurego.rb,
lib/nurego/auth.rb,
lib/nurego/bill.rb,
lib/nurego/json.rb,
lib/nurego/plan.rb,
lib/nurego/util.rb,
lib/nurego/feature.rb,
lib/nurego/version.rb,
lib/nurego/customer.rb,
lib/nurego/instance.rb,
lib/nurego/offering.rb,
lib/nurego/connector.rb,
lib/nurego/entitlement.rb,
lib/nurego/list_object.rb,
lib/nurego/api_resource.rb,
lib/nurego/organization.rb,
lib/nurego/registration.rb,
lib/nurego/nurego_object.rb,
lib/nurego/password_reset.rb,
lib/nurego/payment_method.rb,
lib/nurego/errors/api_error.rb,
lib/nurego/errors/card_error.rb,
lib/nurego/api_operations/list.rb,
lib/nurego/errors/nurego_error.rb,
lib/nurego/api_operations/create.rb,
lib/nurego/api_operations/delete.rb,
lib/nurego/api_operations/update.rb,
lib/nurego/errors/api_connection_error.rb,
lib/nurego/errors/authentication_error.rb,
lib/nurego/errors/user_not_found_error.rb,
lib/nurego/errors/invalid_request_error.rb
Defined Under Namespace
Modules: APIOperations, Auth, JSON, Util Classes: APIConnectionError, APIError, APIResource, AuthenticationError, Bill, CardError, Connector, Customer, Entitlement, Feature, Instance, InvalidRequestError, ListObject, NuregoError, NuregoObject, Offering, Organization, PasswordReset, PaymentMethod, Plan, Registration, UserNotFoundError
Constant Summary collapse
- VERSION =
'1.0.9'
Class Attribute Summary collapse
-
.api_base ⇒ Object
Returns the value of attribute api_base.
-
.api_key ⇒ Object
Returns the value of attribute api_key.
-
.api_version ⇒ Object
Returns the value of attribute api_version.
-
.logger ⇒ Object
Returns the value of attribute logger.
-
.verify_ssl_certs ⇒ Object
Returns the value of attribute verify_ssl_certs.
Class Method Summary collapse
Class Attribute Details
.api_base ⇒ Object
Returns the value of attribute api_base.
57 58 59 |
# File 'lib/nurego.rb', line 57 def api_base @api_base end |
.api_key ⇒ Object
Returns the value of attribute api_key.
57 58 59 |
# File 'lib/nurego.rb', line 57 def api_key @api_key end |
.api_version ⇒ Object
Returns the value of attribute api_version.
57 58 59 |
# File 'lib/nurego.rb', line 57 def api_version @api_version end |
.logger ⇒ Object
Returns the value of attribute logger.
57 58 59 |
# File 'lib/nurego.rb', line 57 def logger @logger end |
.verify_ssl_certs ⇒ Object
Returns the value of attribute verify_ssl_certs.
57 58 59 |
# File 'lib/nurego.rb', line 57 def verify_ssl_certs @verify_ssl_certs end |
Class Method Details
.api_url(url = '') ⇒ Object
60 61 62 |
# File 'lib/nurego.rb', line 60 def self.api_url(url='') @api_base + url end |
.request(method, url, api_key, params = {}, headers = {}) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/nurego.rb', line 64 def self.request(method, url, api_key, params={}, headers={}) unless api_key ||= @api_key raise AuthenticationError.new('No API key provided. ' + 'Set your API key using "Nurego.api_key = <API-KEY>". ' + 'You can generate API keys from the Nurego web interface. ' + 'See https://www.nurego.com/api for details, or email [email protected] ' + 'if you have any questions.') end if api_key =~ /\s/ raise AuthenticationError.new('Your API key is invalid, as it contains ' + 'whitespace. (HINT: You can double-check your API key from the ' + 'Nurego web interface. See https://www.nurego.com/api for details, or ' + 'email [email protected] if you have any questions.)') end request_opts = { :verify_ssl => false } if ssl_preflight_passed? request_opts.update(:verify_ssl => OpenSSL::SSL::VERIFY_PEER, :ssl_ca_file => @ssl_bundle_path) end params = Util.objects_to_ids(params) url = api_url(url) case method.to_s.downcase.to_sym when :get, :head, :delete # Make params into GET parameters url += "#{URI.parse(url).query ? '&' : '?'}#{uri_encode(params)}" if params && params.any? payload = nil else payload = uri_encode(params) end request_opts.update(:headers => request_headers(api_key).update(headers), :method => method, :open_timeout => 30, :payload => payload, :url => url, :timeout => 80) begin response = execute_request(request_opts) rescue SocketError => e handle_restclient_error(e) rescue NoMethodError => e # Work around RestClient bug if e. =~ /\WRequestFailed\W/ e = APIConnectionError.new('Unexpected HTTP response code') handle_restclient_error(e) else raise end rescue RestClient::ExceptionWithResponse => e if rcode = e.http_code and rbody = e.http_body handle_api_error(rcode, rbody) else handle_restclient_error(e) end rescue RestClient::Exception, Errno::ECONNREFUSED => e handle_restclient_error(e) end [parse(response), api_key] end |