Module: Mango
- Defined in:
- lib/mango.rb,
lib/mango/resources.rb,
lib/mango/operations.rb
Defined Under Namespace
Modules: Operations Classes: Cards, Charges, Coupons, Customers, Error, Installments, Promotions, Queue, Refunds, Resource
Class Attribute Summary collapse
-
.api_base ⇒ Object
Returns the value of attribute api_base.
-
.api_key ⇒ Object
Returns the value of attribute api_key.
Class Method Summary collapse
Class Attribute Details
.api_base ⇒ Object
Returns the value of attribute api_base.
25 26 27 |
# File 'lib/mango.rb', line 25 def api_base @api_base end |
.api_key ⇒ Object
Returns the value of attribute api_key.
25 26 27 |
# File 'lib/mango.rb', line 25 def api_key @api_key end |
Class Method Details
.request(method, url, api_key = nil, params = {}, headers = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mango.rb', line 28 def self.request(method, url, api_key=nil, params={}, headers={}) method = method.to_sym url = @api_base + url unless api_key ||= @api_key raise Error.new('No API key provided') end payload = JSON.generate(params) if method == :post || method == :patch params = nil unless method == :get headers = { :params => params, :content_type => 'application/json' }.merge(headers) = { :headers => headers, :user => api_key, :method => method, :url => url, :payload => payload } begin response = execute_request() return {} if response.code == 204 and method == :delete JSON.parse(response.body, :symbolize_names => true) rescue RestClient::Exception => e handle_errors e end end |