Class: Levelup::Requests::Base
- Inherits:
-
Templates::DataParcel
- Object
- Templates::DataParcel
- Levelup::Requests::Base
- Defined in:
- lib/levelup/requests/base.rb
Overview
The class containing the base functionality of all requests.
Direct Known Subclasses
AuthenticateApp, AuthenticateMerchant, CreateAddress, CreateCard, CreateOrder, CreateUser, GetLocationCredit, GetLocationMerchantFundedCredit, GetOrder, GetQrCode, GetUser, GiveMerchantCredit, ListAddresses, ListAppLocations, ListLocations, ListOrders, ListUserOrders, RefundOrder, RequestPermissions, ShowPermissionsRequest
Constant Summary collapse
- ALLOWED_REQUEST_METHODS =
[:delete, :get, :post, :put]
Class Method Summary collapse
-
.instance_variables_excluded_from_hash ⇒ Object
default values to exclude from request hashes (header values).
Instance Method Summary collapse
-
#auth_type ⇒ Object
One of :none, :merchant, :app, :merchant_and_user.
-
#body ⇒ Object
Returns the body of the request to send as a hash.
-
#headers ⇒ Object
Contains any additional headers passed in a request to the API.
- #response_from_hash ⇒ Object
-
#send_to_api(method, endpoint) ⇒ Object
Calls send_via_httparty, returning either an error response or the response as generated by this request’s response_from_hash function.
Methods inherited from Templates::DataParcel
Constructor Details
This class inherits a constructor from Levelup::Templates::DataParcel
Class Method Details
.instance_variables_excluded_from_hash ⇒ Object
default values to exclude from request hashes (header values)
34 35 36 37 |
# File 'lib/levelup/requests/base.rb', line 34 def self.instance_variables_excluded_from_hash @excluded ||= super.concat([:app_access_token, :merchant_access_token, :user_access_token]) end |
Instance Method Details
#auth_type ⇒ Object
One of :none, :merchant, :app, :merchant_and_user
8 9 10 |
# File 'lib/levelup/requests/base.rb', line 8 def auth_type raise NotImplementedError, 'Auth type not defined for request.' end |
#body ⇒ Object
Returns the body of the request to send as a hash. By default, sends a hash of all assigned instance variables in the object.
14 15 16 |
# File 'lib/levelup/requests/base.rb', line 14 def body to_hash end |
#headers ⇒ Object
Contains any additional headers passed in a request to the API. Builds the headers for a request out of a request object. Extending classes wishing to add additional headers should build their headers hash and return my_headers.merge(super)
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/levelup/requests/base.rb', line 22 def headers headers = DEFAULT_HEADERS.dup auth = auth_header_value if auth headers['Authorization'] = auth end headers end |
#response_from_hash ⇒ Object
39 40 41 |
# File 'lib/levelup/requests/base.rb', line 39 def response_from_hash raise NotImplementedError, 'Response generator not defined.' end |
#send_to_api(method, endpoint) ⇒ Object
Calls send_via_httparty, returning either an error response or the response as generated by this request’s response_from_hash function. This function can be overridden to control how a request builds its response.
47 48 49 50 51 |
# File 'lib/levelup/requests/base.rb', line 47 def send_to_api(method, endpoint) send_via_httparty(method, endpoint) do |response| response_from_hash(response.parsed_response) end end |