class Levelup::Api

This is the base class that handles all requests made to the LevelUp API.

Attributes

api_key[RW]

App API key to automatically generate an app access token

app_access_token[W]

Token to access app-authenticated endpoints

secret[RW]

App secret to automatically generate an app access token

Public Class Methods

new(options = {}) click to toggle source

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

access_tokens() click to toggle source

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
app_authenticated?() click to toggle source

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
apps(app_id = nil) click to toggle source

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
credit_cards() click to toggle source
# File lib/levelup/api.rb, line 45
def credit_cards
  Endpoints::CreditCards.new
end
locations(location_id) click to toggle source

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
merchant_funded_credits() click to toggle source
# File lib/levelup/api.rb, line 61
def merchant_funded_credits
  Endpoints::MerchantFundedCredits.new
end
merchants(merchant_id) click to toggle source

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
orders(order_uuid = nil) click to toggle source

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
qr_codes() click to toggle source
# File lib/levelup/api.rb, line 76
def qr_codes
  Endpoints::QrCodes.new
end
user_addresses() click to toggle source

Generates an interface the user_addresses endpoint.

# File lib/levelup/api.rb, line 81
def user_addresses
  Endpoints::UserAddresses.new
end
users() click to toggle source
# File lib/levelup/api.rb, line 85
def users
  Endpoints::Users.new
end

Private Instance Methods

app_access_token() click to toggle source
# 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