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)


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

def app_authenticated?
  !@app_access_token.nil?
end

#apps(app_id = nil) ⇒ Object

Generates an interface for the apps endpoint.



33
34
35
36
37
38
39
# File 'lib/levelup/api.rb', line 33

def apps(app_id = nil)
  if app_id
    Endpoints::SpecificApp.new(app_id)
  else
    Endpoints::Apps.new(app_access_token)
  end
end

#credit_cardsObject



46
47
48
# File 'lib/levelup/api.rb', line 46

def credit_cards
  Endpoints::CreditCards.new
end

#locations(location_id) ⇒ Object

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



52
53
54
# File 'lib/levelup/api.rb', line 52

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

#merchant_funded_creditsObject



62
63
64
# File 'lib/levelup/api.rb', line 62

def merchant_funded_credits
  Endpoints::MerchantFundedCredits.new
end

#merchants(merchant_id) ⇒ Object

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



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

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.



69
70
71
72
73
74
75
# File 'lib/levelup/api.rb', line 69

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

#qr_codesObject



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

def qr_codes
  Endpoints::QrCodes.new
end

#user_addressesObject

Generates an interface the user_addresses endpoint.



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

def user_addresses
  Endpoints::UserAddresses.new
end

#usersObject



86
87
88
# File 'lib/levelup/api.rb', line 86

def users
  Endpoints::Users.new
end