Class: Levelup::Api

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

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Api

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



17
18
19
20
21
# 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

Instance Attribute Details

#api_key=(value) ⇒ Object

App API key to automatically generate an app access token



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

def api_key=(value)
  @api_key = value
end

#app_access_token=(value) ⇒ Object

Token to access app-authenticated endpoints



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

def app_access_token=(value)
  @app_access_token = value
end

#secret=(value) ⇒ Object

App secret to automatically generate an app access token



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

def secret=(value)
  @secret = value
end

Instance Method Details

#access_tokensObject

Generates an interface for the access_tokens endpoint.



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

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)


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

def app_authenticated?
  !@app_access_token.nil?
end

#apps(app_id = nil) ⇒ Object

Generates an interface for the apps endpoint.



32
33
34
35
36
37
38
# 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_cardsObject



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

def credit_cards
  Endpoints::CreditCards.new
end

#locations(location_id) ⇒ Object

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



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

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

#merchant_funded_creditsObject



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

def merchant_funded_credits
  Endpoints::MerchantFundedCredits.new
end

#merchants(merchant_id) ⇒ Object

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



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

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.



68
69
70
71
72
73
74
# 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_codesObject



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

def qr_codes
  Endpoints::QrCodes.new
end

#user_addressesObject

Generates an interface the user_addresses endpoint.



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

def user_addresses
  Endpoints::UserAddresses.new
end

#usersObject



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

def users
  Endpoints::Users.new
end