levelup 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +32 -305
- data/Gemfile.lock +1 -1
- data/README.md +131 -38
- data/levelup.gemspec +1 -1
- data/lib/levelup.rb +4 -0
- data/lib/levelup/api.rb +1 -2
- data/lib/levelup/configuration.rb +1 -1
- data/lib/levelup/endpoints/access_tokens.rb +7 -10
- data/lib/levelup/endpoints/app_locations.rb +4 -6
- data/lib/levelup/endpoints/app_users.rb +1 -7
- data/lib/levelup/endpoints/credit_cards.rb +3 -4
- data/lib/levelup/endpoints/location_credit.rb +6 -8
- data/lib/levelup/endpoints/location_merchant_funded_credit.rb +23 -0
- data/lib/levelup/endpoints/location_orders.rb +8 -14
- data/lib/levelup/endpoints/merchant_funded_credits.rb +4 -6
- data/lib/levelup/endpoints/merchant_locations.rb +8 -13
- data/lib/levelup/endpoints/merchant_orders.rb +6 -8
- data/lib/levelup/endpoints/orders.rb +3 -3
- data/lib/levelup/endpoints/permissions_requests.rb +1 -2
- data/lib/levelup/endpoints/qr_codes.rb +3 -4
- data/lib/levelup/endpoints/specific_app.rb +1 -2
- data/lib/levelup/endpoints/specific_location.rb +13 -8
- data/lib/levelup/endpoints/specific_merchant.rb +4 -5
- data/lib/levelup/endpoints/specific_order.rb +4 -8
- data/lib/levelup/endpoints/specific_permissions_request.rb +3 -5
- data/lib/levelup/endpoints/user_addresses.rb +6 -7
- data/lib/levelup/endpoints/user_orders.rb +2 -3
- data/lib/levelup/endpoints/users.rb +5 -0
- data/lib/levelup/requests/authenticate_merchant.rb +1 -2
- data/lib/levelup/requests/create_address.rb +3 -4
- data/lib/levelup/requests/create_card.rb +2 -3
- data/lib/levelup/requests/create_order.rb +1 -2
- data/lib/levelup/requests/create_user.rb +4 -13
- data/lib/levelup/requests/get_location_credit.rb +1 -2
- data/lib/levelup/requests/get_location_merchant_funded_credit.rb +16 -0
- data/lib/levelup/requests/get_order.rb +1 -2
- data/lib/levelup/requests/give_merchant_credit.rb +1 -2
- data/lib/levelup/requests/list_addresses.rb +3 -4
- data/lib/levelup/requests/list_app_locations.rb +1 -2
- data/lib/levelup/requests/list_locations.rb +2 -3
- data/lib/levelup/requests/list_orders.rb +2 -3
- data/lib/levelup/requests/list_user_orders.rb +3 -4
- data/lib/levelup/requests/show_permissions_request.rb +1 -2
- data/lib/levelup/responses/success_paginated.rb +1 -2
- data/lib/levelup/templates/app_authenticated.rb +1 -3
- data/lib/levelup/templates/merchant_and_user_authenticated.rb +4 -9
- data/lib/levelup/templates/merchant_authenticated.rb +2 -5
- data/lib/levelup/utils/payment_calculator.rb +83 -0
- data/spec/endpoints/access_tokens_spec.rb +2 -4
- data/spec/endpoints/app_users_spec.rb +6 -22
- data/spec/endpoints/location_credit_spec.rb +1 -2
- data/spec/endpoints/location_merchant_funded_credit_spec.rb +12 -0
- data/spec/endpoints/location_orders_spec.rb +3 -4
- data/spec/endpoints/merchant_funded_credits_spec.rb +1 -2
- data/spec/endpoints/merchant_locations_spec.rb +4 -4
- data/spec/endpoints/qr_codes_spec.rb +1 -2
- data/spec/endpoints/specific_order_spec.rb +3 -4
- data/spec/endpoints/specific_permissions_request_spec.rb +1 -2
- data/spec/endpoints/user_addresses_spec.rb +1 -2
- data/spec/endpoints/user_orders_spec.rb +1 -2
- data/spec/endpoints/users_spec.rb +22 -0
- data/spec/{data_objects/requests → requests}/authenticate_app_spec.rb +0 -0
- data/spec/{data_objects/requests → requests}/authenticate_merchant_spec.rb +0 -0
- data/spec/{data_objects/requests → requests}/create_order_spec.rb +0 -0
- data/spec/{data_objects/requests → requests}/get_order_spec.rb +0 -0
- data/spec/{data_objects/requests → requests}/list_locations_spec.rb +0 -0
- data/spec/{data_objects/requests → requests}/list_orders_spec.rb +0 -0
- data/spec/{data_objects/requests → requests}/refund_order_spec.rb +0 -0
- data/spec/{data_objects/requests → requests}/request_permissions_spec.rb +1 -2
- data/spec/{data_objects/responses → responses}/error_spec.rb +0 -0
- data/spec/{data_objects/responses → responses}/response_spec.rb +0 -0
- data/spec/{data_objects/responses → responses}/success_paginated_spec.rb +1 -2
- data/spec/utils/payment_calculator/payment_calculator_spec.rb +164 -0
- metadata +36 -26
@@ -1,18 +1,16 @@
|
|
1
1
|
module Levelup
|
2
2
|
module Endpoints
|
3
|
-
# The endpoint holding all functions relating to managing merchant-funded
|
4
|
-
# credit.
|
3
|
+
# The endpoint holding all functions relating to managing merchant-funded credit.
|
5
4
|
class MerchantFundedCredits < Base
|
6
5
|
def give(give_credit_request)
|
7
|
-
|
8
|
-
|
9
|
-
request.send_to_api(:post, endpoint_path)
|
6
|
+
build_request(give_credit_request, Requests::GiveMerchantCredit).
|
7
|
+
send_to_api(:post, endpoint_path)
|
10
8
|
end
|
11
9
|
|
12
10
|
private
|
13
11
|
|
14
12
|
def path
|
15
|
-
|
13
|
+
'merchant_funded_credits'
|
16
14
|
end
|
17
15
|
end
|
18
16
|
end
|
@@ -1,28 +1,23 @@
|
|
1
1
|
module Levelup
|
2
2
|
module Endpoints
|
3
|
-
# The endpoint holding all functions relating to a single merchant's
|
4
|
-
#
|
5
|
-
# functional indefinitely.
|
3
|
+
# The endpoint holding all functions relating to a single merchant's locations. This is a v14
|
4
|
+
# endpoint and should not be expected to remain functional indefinitely.
|
6
5
|
class MerchantLocations < Base
|
7
6
|
def initialize(merchant_id)
|
8
7
|
@id = merchant_id
|
9
8
|
end
|
10
9
|
|
11
|
-
# Provides a list of locations controlled by this merchant. This list is
|
12
|
-
# not paginated.
|
10
|
+
# Provides a list of locations controlled by this merchant. This list is not paginated.
|
13
11
|
#
|
14
|
-
# [
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
request = Requests::ListLocations.new(
|
19
|
-
merchant_access_token: merchant_auth_token)
|
20
|
-
request.send_to_api(:get, endpoint_path(:v14))
|
12
|
+
# @param merchant_access_token [string] An access token for a user that manages this location.
|
13
|
+
def list(merchant_access_token)
|
14
|
+
Requests::ListLocations.new(merchant_access_token: merchant_access_token).
|
15
|
+
send_to_api(:get, endpoint_path(:v14))
|
21
16
|
end
|
22
17
|
|
23
18
|
private
|
24
19
|
|
25
|
-
|
20
|
+
attr_accessor :id
|
26
21
|
|
27
22
|
def path
|
28
23
|
"merchants/#{id}/locations"
|
@@ -1,24 +1,22 @@
|
|
1
1
|
module Levelup
|
2
2
|
module Endpoints
|
3
3
|
# The endpoint holding all functions relating to a single merchant's orders.
|
4
|
-
# This is a v14 endpoint and should not be expected to remain functional
|
5
|
-
# indefinitely.
|
4
|
+
# This is a v14 endpoint and should not be expected to remain functional indefinitely.
|
6
5
|
class MerchantOrders < Base
|
7
6
|
def initialize(merchant_id)
|
8
|
-
|
7
|
+
self.id = merchant_id
|
9
8
|
end
|
10
9
|
|
11
10
|
# Provides merchant-facing details about a specific order. For more
|
12
|
-
# information about the parameters, see
|
11
|
+
# information about the parameters, @see Requests::CreateOrderDetails.
|
13
12
|
def details(uuid, merchant_access_token)
|
14
|
-
|
15
|
-
|
16
|
-
request.send_to_api(:get, endpoint_path(:v14) + "/#{uuid}")
|
13
|
+
Requests::CreateOrderDetails.new(merchant_access_token: merchant_access_token).
|
14
|
+
send_to_api(:get, endpoint_path(:v14) + "/#{uuid}")
|
17
15
|
end
|
18
16
|
|
19
17
|
private
|
20
18
|
|
21
|
-
|
19
|
+
attr_accessor :id
|
22
20
|
|
23
21
|
def path
|
24
22
|
"merchants/#{id}/orders"
|
@@ -3,10 +3,10 @@ module Levelup
|
|
3
3
|
# The class holding all functions related to orders that do not specify a
|
4
4
|
# specific order. For single-order functions, see SpecificOrder.
|
5
5
|
class Orders < Base
|
6
|
-
# Creates an order. See
|
6
|
+
# Creates an order. See Requests::CreateOrder for more info about the parameters.
|
7
7
|
def create(order_request)
|
8
|
-
|
9
|
-
|
8
|
+
build_request(order_request, Requests::CreateOrder).
|
9
|
+
send_to_api(:post, endpoint_path)
|
10
10
|
end
|
11
11
|
|
12
12
|
private
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Levelup
|
2
2
|
module Endpoints
|
3
|
-
# The endpoint holding all functions related to managing permissions
|
4
|
-
# requests.
|
3
|
+
# The endpoint holding all functions related to managing permissions requests.
|
5
4
|
class PermissionsRequests < Base
|
6
5
|
def initialize(app_access_token)
|
7
6
|
self.app_access_token = app_access_token
|
@@ -8,11 +8,10 @@ module Levelup
|
|
8
8
|
self.tip_percent = options[:tip_percent] || 0
|
9
9
|
end
|
10
10
|
|
11
|
-
# Retrieves the specified user's QR code using parameters specified
|
12
|
-
# in the endpoint.
|
11
|
+
# Retrieves the specified user's QR code using parameters specified in the endpoint.
|
13
12
|
def get(user_access_token)
|
14
|
-
|
15
|
-
|
13
|
+
Requests::GetQrCode.new(user_access_token: user_access_token).
|
14
|
+
send_to_api(:get, endpoint_path)
|
16
15
|
end
|
17
16
|
|
18
17
|
private
|
@@ -1,25 +1,30 @@
|
|
1
1
|
module Levelup
|
2
2
|
module Endpoints
|
3
3
|
# The endpoint holding all functions relating to a specific location.
|
4
|
-
# This is a v14 endpoint and should not be expected to remain functional
|
5
|
-
# indefinitely.
|
4
|
+
# This is a v14 endpoint and should not be expected to remain functional indefinitely.
|
6
5
|
class SpecificLocation < Base
|
7
|
-
|
6
|
+
attr_accessor :id
|
8
7
|
|
9
8
|
def initialize(location_id)
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
def orders
|
14
|
-
LocationOrders.new(id)
|
9
|
+
self.id = location_id
|
15
10
|
end
|
16
11
|
|
17
12
|
def credit
|
18
13
|
LocationCredit.new(id)
|
19
14
|
end
|
20
15
|
|
16
|
+
def merchant_funded_credit
|
17
|
+
LocationMerchantFundedCredit.new(id)
|
18
|
+
end
|
19
|
+
|
20
|
+
def orders
|
21
|
+
LocationOrders.new(id)
|
22
|
+
end
|
23
|
+
|
21
24
|
private
|
22
25
|
|
26
|
+
attr_accessor :id
|
27
|
+
|
23
28
|
def path
|
24
29
|
"locations/#{id}"
|
25
30
|
end
|
@@ -1,13 +1,10 @@
|
|
1
1
|
module Levelup
|
2
2
|
module Endpoints
|
3
3
|
# The endpoint holding all functions relating to a single merchant. This is
|
4
|
-
# a v14 endpoint and should not be expected to remain functional
|
5
|
-
# indefinitely.
|
4
|
+
# a v14 endpoint and should not be expected to remain functional indefinitely.
|
6
5
|
class SpecificMerchant < Base
|
7
|
-
attr_reader :id
|
8
|
-
|
9
6
|
def initialize(merchant_id)
|
10
|
-
|
7
|
+
self.id = merchant_id
|
11
8
|
end
|
12
9
|
|
13
10
|
def locations
|
@@ -20,6 +17,8 @@ module Levelup
|
|
20
17
|
|
21
18
|
private
|
22
19
|
|
20
|
+
attr_accessor :id
|
21
|
+
|
23
22
|
def path
|
24
23
|
"merchants/#{id}"
|
25
24
|
end
|
@@ -7,14 +7,10 @@ module Levelup
|
|
7
7
|
end
|
8
8
|
|
9
9
|
# Refunds the order specified by this endpoint.
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def refund(merchant_auth_token)
|
15
|
-
request = Requests::RefundOrder.new(
|
16
|
-
merchant_access_token: merchant_auth_token)
|
17
|
-
request.send_to_api(:post, endpoint_path + '/refund')
|
10
|
+
# @param merchant_access_token [string] An access token for a user that manages this location.
|
11
|
+
def refund(merchant_access_token)
|
12
|
+
Requests::RefundOrder.new(merchant_access_token: merchant_access_token).
|
13
|
+
send_to_api(:post, endpoint_path + '/refund')
|
18
14
|
end
|
19
15
|
|
20
16
|
private
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Levelup
|
2
2
|
module Endpoints
|
3
|
-
# The endpoint holding all functions related to accessing a specified
|
4
|
-
# permissions request.
|
3
|
+
# The endpoint holding all functions related to accessing a specified permissions request.
|
5
4
|
class SpecificPermissionsRequest < Base
|
6
5
|
def initialize(request_id, app_access_token)
|
7
6
|
self.app_access_token = app_access_token
|
@@ -9,9 +8,8 @@ module Levelup
|
|
9
8
|
end
|
10
9
|
|
11
10
|
def show(app_token = nil)
|
12
|
-
|
13
|
-
|
14
|
-
request.send_to_api(:get, endpoint_path)
|
11
|
+
Requests::ShowPermissionsRequest.new(app_access_token: app_access_token || app_token).
|
12
|
+
send_to_api(:get, endpoint_path)
|
15
13
|
end
|
16
14
|
|
17
15
|
private
|
@@ -2,17 +2,16 @@ module Levelup
|
|
2
2
|
module Endpoints
|
3
3
|
# Endpoint holding all functions relating to user addresses.
|
4
4
|
class UserAddresses < Base
|
5
|
-
# Creates a specified user address. For more information on parameters,
|
6
|
-
#
|
5
|
+
# Creates a specified user address. For more information on parameters, see
|
6
|
+
# UserAddressRequest.
|
7
7
|
def create(user_address_request)
|
8
|
-
|
9
|
-
|
10
|
-
request.send_to_api(:post, endpoint_path)
|
8
|
+
build_request(user_address_request, Requests::CreateAddress).
|
9
|
+
send_to_api(:post, endpoint_path)
|
11
10
|
end
|
12
11
|
|
13
12
|
def list(user_access_token)
|
14
|
-
|
15
|
-
|
13
|
+
Requests::ListAddresses(user_access_token: user_access_token).
|
14
|
+
send_to_api(:get, endpoint_path)
|
16
15
|
end
|
17
16
|
|
18
17
|
private
|
@@ -3,9 +3,8 @@ module Levelup
|
|
3
3
|
# The endpoint holding all functions related to orders for a specified user.
|
4
4
|
class UserOrders < Base
|
5
5
|
def list(user_access_token)
|
6
|
-
|
7
|
-
|
8
|
-
request.send_to_api(:get, endpoint_path)
|
6
|
+
Requests::ListUserOrders.new(user_access_token: user_access_token).
|
7
|
+
send_to_api(:get, endpoint_path)
|
9
8
|
end
|
10
9
|
|
11
10
|
private
|
@@ -2,6 +2,11 @@ module Levelup
|
|
2
2
|
module Endpoints
|
3
3
|
# The endpoint serving as a bucket for all user-related functions.
|
4
4
|
class Users < Base
|
5
|
+
def get(user_access_token)
|
6
|
+
Requests::GetUser.new(user_access_token: user_access_token).
|
7
|
+
send_to_api(:get, endpoint_path)
|
8
|
+
end
|
9
|
+
|
5
10
|
def orders
|
6
11
|
UserOrders.new
|
7
12
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Levelup
|
2
2
|
module Requests
|
3
|
-
# Represents a request to generate a merchant access
|
4
|
-
# token.
|
3
|
+
# Represents a request to generate a merchant access token.
|
5
4
|
class AuthenticateMerchant < Base
|
6
5
|
# Your merchant's API key (accepts app API key as well)
|
7
6
|
attr_accessor :api_key
|
@@ -1,8 +1,7 @@
|
|
1
|
-
|
1
|
+
module Levelup
|
2
2
|
module Requests
|
3
|
-
# Represents a request to create an address for a
|
4
|
-
#
|
5
|
-
# and UserAuthenticated.
|
3
|
+
# Represents a request to create an address for a specific user.
|
4
|
+
# For information about its parameters, see UserAddressData and UserAuthenticated.
|
6
5
|
class CreateAddress < Base
|
7
6
|
include Templates::UserAddressData
|
8
7
|
include Templates::UserAuthenticated
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module Levelup
|
2
2
|
module Requests
|
3
|
-
# Represents a request to add the first credit card to a specified user
|
4
|
-
#
|
5
|
-
# permission.
|
3
|
+
# Represents a request to add the first credit card to a specified user account.
|
4
|
+
# User access token must have the create_first_credit_card permission.
|
6
5
|
class CreateCard < Base
|
7
6
|
include Templates::UserAuthenticated
|
8
7
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Levelup
|
2
2
|
module Requests
|
3
|
-
# Represents a request to create an order for the specified user at the
|
4
|
-
# specified merchant.
|
3
|
+
# Represents a request to create an order for the specified user at the specified merchant.
|
5
4
|
class CreateOrder < Base
|
6
5
|
include Templates::MerchantAndUserAuthenticated
|
7
6
|
# An array of Item objects (or hashes representing them) representing all
|
@@ -1,23 +1,14 @@
|
|
1
1
|
module Levelup
|
2
2
|
module Requests
|
3
|
-
# Represents a request to create a new user with the specified list of
|
4
|
-
# permissions.
|
3
|
+
# Represents a request to create a new user with the specified list of permissions.
|
5
4
|
class CreateUser < Base
|
6
5
|
include Templates::AppAuthenticated
|
7
|
-
# An array of Item objects (or hashes representing them) representing all
|
8
|
-
# items purchased by this order.
|
9
|
-
attr_accessor :email
|
10
|
-
attr_accessor :first_name
|
11
|
-
attr_accessor :last_name
|
12
6
|
attr_accessor :permission_keynames
|
7
|
+
attr_accessor :api_key
|
8
|
+
attr_accessor :user
|
13
9
|
|
14
10
|
def body
|
15
|
-
|
16
|
-
email: email,
|
17
|
-
first_name: first_name,
|
18
|
-
last_name: last_name
|
19
|
-
}
|
20
|
-
{ user: user_hash, permission_keynames: permission_keynames }
|
11
|
+
{ api_key: api_key, user: user, permission_keynames: permission_keynames }
|
21
12
|
end
|
22
13
|
|
23
14
|
def response_from_hash(hash)
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Levelup
|
2
2
|
module Requests
|
3
|
-
# Represents a request to access information about a
|
4
|
-
# specific order under a merchant.
|
3
|
+
# Represents a request to access information about a specific order under a merchant.
|
5
4
|
class GetLocationCredit < Base
|
6
5
|
include Templates::UserAuthenticated
|
7
6
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Levelup
|
2
|
+
module Requests
|
3
|
+
# Represents a request to access information about a specific order under a merchant.
|
4
|
+
class GetLocationMerchantFundedCredit < Base
|
5
|
+
include Templates::MerchantAuthenticated
|
6
|
+
|
7
|
+
def auth_type
|
8
|
+
:merchant_v14
|
9
|
+
end
|
10
|
+
|
11
|
+
def response_from_hash(hash)
|
12
|
+
Responses::Success.new hash['merchant_funded_credit']
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Levelup
|
2
2
|
module Requests
|
3
|
-
# Represents a request to access information about a
|
4
|
-
# specific order under a merchant.
|
3
|
+
# Represents a request to access information about a specific order under a merchant.
|
5
4
|
class GetOrder < Base
|
6
5
|
include Templates::MerchantAuthenticated
|
7
6
|
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module Levelup
|
2
2
|
module Requests
|
3
3
|
# Represents a request to grant merchant-funded credit to a user.
|
4
|
-
# Merchant access token must have the give_merchant_funded_credit
|
5
|
-
# permission.
|
4
|
+
# Merchant access token must have the give_merchant_funded_credit permission.
|
6
5
|
class GiveMerchantCredit < Base
|
7
6
|
include Templates::MerchantAuthenticated
|
8
7
|
attr_accessor :email, :value_amount
|
@@ -1,8 +1,7 @@
|
|
1
|
-
|
1
|
+
module Levelup
|
2
2
|
module Requests
|
3
|
-
# Represents a request to create an address for a
|
4
|
-
#
|
5
|
-
# and UserAuthenticated.
|
3
|
+
# Represents a request to create an address for a specific user.
|
4
|
+
# For information about its parameters, see UserAddressData and UserAuthenticated.
|
6
5
|
# User access token must have the manage_user_addresses permission.
|
7
6
|
class ListAddresses < Base
|
8
7
|
include Templates::UserAuthenticated
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Levelup
|
2
2
|
module Requests
|
3
|
-
# Represents a request to list all locations under
|
4
|
-
# a specified app. The list is paginated.
|
3
|
+
# Represents a request to list all locations under a specified app. The list is paginated.
|
5
4
|
class ListAppLocations < Base
|
6
5
|
def auth_type
|
7
6
|
:none
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module Levelup
|
2
2
|
module Requests
|
3
|
-
# Represents a request to list all locations under
|
4
|
-
#
|
5
|
-
# remain functional indefinitely.
|
3
|
+
# Represents a request to list all locations under a specified merchant.
|
4
|
+
# This is a v14 endpoint and should not be expected to remain functional indefinitely.
|
6
5
|
class ListLocations < Base
|
7
6
|
include Templates::MerchantAuthenticated
|
8
7
|
|