Class: Levelup::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/levelup/api.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_access_token: nil, api_key: nil, secret: nil) ⇒ Api

Accepts any combination of the listed parameters, though api_key and secret work in tandem.



18
19
20
21
22
# File 'lib/levelup/api.rb', line 18

def initialize(app_access_token: nil, api_key: nil, secret: nil)
  self.app_access_token = app_access_token
  self.api_key = api_key
  self.secret = secret
end

Instance Attribute Details

#api_key=(value) ⇒ Object

App API key to automatically generate an app access token



12
13
14
# File 'lib/levelup/api.rb', line 12

def api_key=(value)
  @api_key = value
end

#app_access_token=(value) ⇒ Object

Token to access app-authenticated endpoints



10
11
12
# File 'lib/levelup/api.rb', line 10

def app_access_token=(value)
  @app_access_token = value
end

#secret=(value) ⇒ Object

App secret to automatically generate an app access token



14
15
16
# File 'lib/levelup/api.rb', line 14

def secret=(value)
  @secret = value
end

Instance Method Details

#access_tokensObject

Generates an interface for the access_tokens endpoint.



25
26
27
28
29
30
# File 'lib/levelup/api.rb', line 25

def access_tokens
  Endpoints::AccessTokens.new(
    api_key: api_key,
    secret: secret
  )
end

#app_authenticated?Boolean

Verifies if an access token is present for app-authenticated endpoints

Returns:

  • (Boolean)


38
39
40
# File 'lib/levelup/api.rb', line 38

def app_authenticated?
  !@app_access_token.nil?
end

#appsObject

Generates an interface for the apps endpoint.



33
34
35
# File 'lib/levelup/api.rb', line 33

def apps
  Endpoints::Apps.new(app_access_token)
end

#credit_cardsObject



42
43
44
# File 'lib/levelup/api.rb', line 42

def credit_cards
  Endpoints::CreditCards.new
end

#locations(location_id) ⇒ Object

Generates the interface for the locations endpoint for a specific location ID.



48
49
50
# File 'lib/levelup/api.rb', line 48

def locations(location_id)
  Endpoints::SpecificLocation.new(location_id)
end

#merchant_funded_creditsObject



58
59
60
# File 'lib/levelup/api.rb', line 58

def merchant_funded_credits
  Endpoints::MerchantFundedCredits.new
end

#merchants(merchant_id) ⇒ Object

Generates an interface for the merchants endpoint for a specific merchant ID.



54
55
56
# File 'lib/levelup/api.rb', line 54

def merchants(merchant_id)
  Endpoints::SpecificMerchant.new(merchant_id)
end

#orders(order_uuid = nil) ⇒ Object

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.



65
66
67
68
69
70
71
# File 'lib/levelup/api.rb', line 65

def orders(order_uuid = nil)
  if order_uuid
    Endpoints::SpecificOrder.new(order_uuid)
  else
    Endpoints::Orders.new
  end
end

#qr_codesObject



73
74
75
# File 'lib/levelup/api.rb', line 73

def qr_codes
  Endpoints::QrCodes.new
end

#user_addressesObject

Generates an interface the user_addresses endpoint.



78
79
80
# File 'lib/levelup/api.rb', line 78

def user_addresses
  Endpoints::UserAddresses.new
end

#usersObject



82
83
84
# File 'lib/levelup/api.rb', line 82

def users
  Endpoints::Users.new
end