Module: Paid
- Defined in:
- lib/paid.rb,
lib/paid/util.rb,
lib/paid/alias.rb,
lib/paid/event.rb,
lib/paid/account.rb,
lib/paid/invoice.rb,
lib/paid/version.rb,
lib/paid/customer.rb,
lib/paid/list_object.rb,
lib/paid/paid_object.rb,
lib/paid/transaction.rb,
lib/paid/api_resource.rb,
lib/paid/errors/api_error.rb,
lib/paid/errors/paid_error.rb,
lib/paid/api_operations/list.rb,
lib/paid/api_operations/create.rb,
lib/paid/api_operations/delete.rb,
lib/paid/api_operations/update.rb,
lib/paid/certificate_blacklist.rb,
lib/paid/singleton_api_resource.rb,
lib/paid/errors/api_connection_error.rb,
lib/paid/errors/authentication_error.rb,
lib/paid/errors/invalid_request_error.rb
Defined Under Namespace
Modules: APIOperations, CertificateBlacklist, Util Classes: APIConnectionError, APIError, APIResource, Account, Alias, AuthenticationError, Customer, Event, InvalidRequestError, Invoice, ListObject, PaidError, PaidObject, SingletonAPIResource, Transaction
Constant Summary collapse
- DEFAULT_CA_BUNDLE_PATH =
File.dirname(__FILE__) + '/data/ca-certificates.crt'
- VERSION =
"0.0.4"
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.
-
.verify_ssl_certs ⇒ Object
Returns the value of attribute verify_ssl_certs.
Class Method Summary collapse
- .api_url(url = '', api_base_url = nil) ⇒ Object
- .request(method, url, api_key, params = {}, headers = {}, api_base_url = nil) ⇒ Object
Class Attribute Details
.api_base ⇒ Object
Returns the value of attribute api_base.
49 50 51 |
# File 'lib/paid.rb', line 49 def api_base @api_base end |
.api_key ⇒ Object
Returns the value of attribute api_key.
49 50 51 |
# File 'lib/paid.rb', line 49 def api_key @api_key end |
.api_version ⇒ Object
Returns the value of attribute api_version.
49 50 51 |
# File 'lib/paid.rb', line 49 def api_version @api_version end |
.verify_ssl_certs ⇒ Object
Returns the value of attribute verify_ssl_certs.
49 50 51 |
# File 'lib/paid.rb', line 49 def verify_ssl_certs @verify_ssl_certs end |
Class Method Details
.api_url(url = '', api_base_url = nil) ⇒ Object
52 53 54 |
# File 'lib/paid.rb', line 52 def self.api_url(url='', api_base_url=nil) (api_base_url || @api_base) + url end |
.request(method, url, api_key, params = {}, headers = {}, api_base_url = nil) ⇒ Object
56 57 58 59 60 61 62 63 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 126 127 128 129 130 131 |
# File 'lib/paid.rb', line 56 def self.request(method, url, api_key, params={}, headers={}, api_base_url=nil) api_base_url = api_base_url || @api_base unless api_key ||= @api_key raise AuthenticationError.new('No API key provided. ' + 'Set your API key using "Paid.api_key = <API-KEY>". ' + 'You can generate API keys from the Paid web interface. ' + 'See https://paidapi.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 ' + 'Paid web interface. See https://paidapi.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 if @verify_ssl_certs and !@CERTIFICATE_VERIFIED @CERTIFICATE_VERIFIED = CertificateBlacklist.check_ssl_cert(api_base_url, @ssl_bundle_path) end params = Util.objects_to_ids(params) url = api_url(url, api_base_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 if headers[:content_type] && headers[:content_type] == "multipart/form-data" payload = params else payload = uri_encode(params) end 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, api_base_url) rescue NoMethodError => e # Work around RestClient bug if e. =~ /\WRequestFailed\W/ e = APIConnectionError.new('Unexpected HTTP response code') handle_restclient_error(e, api_base_url) 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, api_base_url) end rescue RestClient::Exception, Errno::ECONNREFUSED => e handle_restclient_error(e, api_base_url) rescue Exception => e end [parse(response), api_key] end |