class Levelup::Api
This is the base class that handles all requests made to the LevelUp API.
Attributes
App API key to automatically generate an app access token
Token to access app-authenticated endpoints
App secret to automatically generate an app access token
Public Class Methods
Accepts any combination of the listed parameters, though api_key
and secret
work in tandem.
# File lib/levelup/api.rb, line 17 def initialize(options = {}) self.app_access_token = options[:app_access_token] self.api_key = options[:api_key] self.secret = options[:secret] end
Public Instance Methods
Generates an interface for the access_tokens
endpoint.
# File lib/levelup/api.rb, line 24 def access_tokens Endpoints::AccessTokens.new( api_key: api_key, secret: secret ) end
Verifies if an access token is present for app-authenticated endpoints
# File lib/levelup/api.rb, line 41 def app_authenticated? !@app_access_token.nil? end
Generates an interface for the apps
endpoint.
# File lib/levelup/api.rb, line 32 def apps(app_id = nil) if app_id Endpoints::SpecificApp.new(app_id) else Endpoints::Apps.new(app_access_token) end end
# File lib/levelup/api.rb, line 45 def credit_cards Endpoints::CreditCards.new end
Generates the interface for the locations
endpoint for a specific location ID.
# File lib/levelup/api.rb, line 51 def locations(location_id) Endpoints::SpecificLocation.new(location_id) end
# File lib/levelup/api.rb, line 61 def merchant_funded_credits Endpoints::MerchantFundedCredits.new end
Generates an interface for the merchants
endpoint for a specific merchant ID.
# File lib/levelup/api.rb, line 57 def merchants(merchant_id) Endpoints::SpecificMerchant.new(merchant_id) end
Generates the interface for the orders
endpoint. Supply an order UUID if you would like to access endpoints for a specific order, otherwise, supply no parameters.
# File lib/levelup/api.rb, line 68 def orders(order_uuid = nil) if order_uuid Endpoints::SpecificOrder.new(order_uuid) else Endpoints::Orders.new end end
# File lib/levelup/api.rb, line 76 def qr_codes Endpoints::QrCodes.new end
Generates an interface the user_addresses
endpoint.
# File lib/levelup/api.rb, line 81 def user_addresses Endpoints::UserAddresses.new end
# File lib/levelup/api.rb, line 85 def users Endpoints::Users.new end
Private Instance Methods
# File lib/levelup/api.rb, line 93 def app_access_token unless app_authenticated? auto_auth = access_tokens.create_for_app if auto_auth.success? @app_access_token = auto_auth.token end end @app_access_token end