levelup 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +36 -0
  3. data/.rubocop.yml +427 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +58 -0
  6. data/LICENSE +21 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +113 -0
  9. data/Rakefile +1 -0
  10. data/levelup.gemspec +32 -0
  11. data/lib/levelup.rb +55 -0
  12. data/lib/levelup/api.rb +102 -0
  13. data/lib/levelup/configuration.rb +23 -0
  14. data/lib/levelup/endpoints/access_tokens.rb +40 -0
  15. data/lib/levelup/endpoints/app_users.rb +30 -0
  16. data/lib/levelup/endpoints/apps.rb +30 -0
  17. data/lib/levelup/endpoints/base.rb +25 -0
  18. data/lib/levelup/endpoints/credit_cards.rb +26 -0
  19. data/lib/levelup/endpoints/location_orders.rb +32 -0
  20. data/lib/levelup/endpoints/merchant_funded_credits.rb +19 -0
  21. data/lib/levelup/endpoints/merchant_locations.rb +32 -0
  22. data/lib/levelup/endpoints/merchant_orders.rb +28 -0
  23. data/lib/levelup/endpoints/orders.rb +19 -0
  24. data/lib/levelup/endpoints/permissions_requests.rb +28 -0
  25. data/lib/levelup/endpoints/qr_codes.rb +28 -0
  26. data/lib/levelup/endpoints/specific_location.rb +24 -0
  27. data/lib/levelup/endpoints/specific_merchant.rb +28 -0
  28. data/lib/levelup/endpoints/specific_order.rb +28 -0
  29. data/lib/levelup/endpoints/specific_permissions_request.rb +26 -0
  30. data/lib/levelup/endpoints/user_addresses.rb +25 -0
  31. data/lib/levelup/endpoints/user_orders.rb +18 -0
  32. data/lib/levelup/endpoints/users.rb +16 -0
  33. data/lib/levelup/errors/invalid_request.rb +8 -0
  34. data/lib/levelup/errors/unauthenticated.rb +8 -0
  35. data/lib/levelup/requests/authenticate_app.rb +19 -0
  36. data/lib/levelup/requests/authenticate_merchant.rb +26 -0
  37. data/lib/levelup/requests/base.rb +87 -0
  38. data/lib/levelup/requests/create_address.rb +19 -0
  39. data/lib/levelup/requests/create_card.rb +21 -0
  40. data/lib/levelup/requests/create_order.rb +33 -0
  41. data/lib/levelup/requests/create_user.rb +34 -0
  42. data/lib/levelup/requests/get_order.rb +17 -0
  43. data/lib/levelup/requests/get_qr_code.rb +16 -0
  44. data/lib/levelup/requests/get_user.rb +17 -0
  45. data/lib/levelup/requests/give_merchant_credit.rb +23 -0
  46. data/lib/levelup/requests/list_addresses.rb +20 -0
  47. data/lib/levelup/requests/list_locations.rb +24 -0
  48. data/lib/levelup/requests/list_orders.rb +23 -0
  49. data/lib/levelup/requests/list_user_orders.rb +20 -0
  50. data/lib/levelup/requests/refund_order.rb +21 -0
  51. data/lib/levelup/requests/request_permissions.rb +27 -0
  52. data/lib/levelup/requests/show_permissions_request.rb +21 -0
  53. data/lib/levelup/responses/error.rb +36 -0
  54. data/lib/levelup/responses/success.rb +11 -0
  55. data/lib/levelup/templates/data_parcel.rb +41 -0
  56. data/lib/levelup/templates/merchant_and_user_authenticated.rb +21 -0
  57. data/lib/levelup/templates/merchant_authenticated.rb +19 -0
  58. data/lib/levelup/templates/user_address_data.rb +20 -0
  59. data/lib/levelup/templates/user_authenticated.rb +17 -0
  60. data/spec/data_objects/requests/authenticate_app_spec.rb +13 -0
  61. data/spec/data_objects/requests/authenticate_merchant_spec.rb +14 -0
  62. data/spec/data_objects/requests/create_order_spec.rb +14 -0
  63. data/spec/data_objects/requests/get_order_spec.rb +13 -0
  64. data/spec/data_objects/requests/list_locations_spec.rb +13 -0
  65. data/spec/data_objects/requests/list_orders_spec.rb +13 -0
  66. data/spec/data_objects/requests/refund_order_spec.rb +19 -0
  67. data/spec/data_objects/requests/request_permissions_spec.rb +21 -0
  68. data/spec/data_objects/responses/error_spec.rb +67 -0
  69. data/spec/data_objects/responses/response_spec.rb +13 -0
  70. data/spec/endpoints/access_tokens_spec.rb +81 -0
  71. data/spec/endpoints/app_users_spec.rb +43 -0
  72. data/spec/endpoints/location_orders_spec.rb +34 -0
  73. data/spec/endpoints/merchant_funded_credits_spec.rb +16 -0
  74. data/spec/endpoints/merchant_locations_spec.rb +35 -0
  75. data/spec/endpoints/orders_spec.rb +37 -0
  76. data/spec/endpoints/permissions_requests_spec.rb +22 -0
  77. data/spec/endpoints/qr_codes_spec.rb +12 -0
  78. data/spec/endpoints/specific_order_spec.rb +33 -0
  79. data/spec/endpoints/specific_permissions_request_spec.rb +24 -0
  80. data/spec/endpoints/user_addresses_spec.rb +41 -0
  81. data/spec/endpoints/user_orders_spec.rb +12 -0
  82. data/spec/fixtures/keys.yml.example +15 -0
  83. data/spec/spec_helper.rb +28 -0
  84. data/spec/support/vcr_filter_sensitive_data.rb +53 -0
  85. metadata +281 -0
@@ -0,0 +1,30 @@
1
+ module Levelup
2
+ module Endpoints
3
+ # The endpoint holding all functions related to managing users under the
4
+ # current app.
5
+ class AppUsers < Base
6
+ def initialize(app_access_token)
7
+ @app_access_token = app_access_token
8
+ end
9
+
10
+ def create(create_user_request)
11
+ request = build_request(create_user_request, Requests::CreateUser)
12
+ request.app_access_token ||= app_access_token
13
+ request.send_to_api(:post, endpoint_path)
14
+ end
15
+
16
+ def get(user_access_token)
17
+ request = Requests::GetUser.new(user_access_token: user_access_token)
18
+ request.send_to_api(:get, endpoint_path)
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :app_access_token
24
+
25
+ def path
26
+ 'apps/users'
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ module Levelup
2
+ module Endpoints
3
+ # The endpoint serving as a bucket for all app-related functions.
4
+ class Apps < Base
5
+ def initialize(app_access_token)
6
+ @app_access_token = app_access_token
7
+ end
8
+
9
+ def permissions_requests(request_id = nil)
10
+ if request_id
11
+ SpecificPermissionsRequest.new(request_id, app_access_token)
12
+ else
13
+ PermissionsRequests.new(app_access_token)
14
+ end
15
+ end
16
+
17
+ def users
18
+ AppUsers.new(app_access_token)
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :app_access_token
24
+
25
+ def path
26
+ 'apps'
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,25 @@
1
+ module Levelup
2
+ module Endpoints
3
+ # The class describing the behavior required of all endpoints.
4
+ class Base
5
+ private
6
+
7
+ # Constructs the specified class out of the supplied hash. If the first
8
+ # parameter is not a hash, simply returns it.
9
+ def build_request(request, building_class)
10
+ request.is_a?(Hash) ? building_class.new(request) : request
11
+ end
12
+
13
+ # Builds a path to this endpoint dynamically.
14
+ def endpoint_path(version = Configuration::DEFAULT_API_VERSION)
15
+ Configuration.api_url(version) + "/#{path}"
16
+ end
17
+
18
+ # Determines the name of this endpoint for purposes of building a URL.
19
+ def path
20
+ raise NotImplementedError,
21
+ 'Attempted to access endpoint with undefined path.'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ module Levelup
2
+ module Endpoints
3
+ # The endpoint holding all functions related to managing users' credit
4
+ # cards.
5
+ class CreditCards < Base
6
+ def initialize(api_key: nil, secret: nil)
7
+ @api_key = api_key
8
+ @secret = secret
9
+ end
10
+
11
+ # Adds a credit card to a user's account. Requires a user access token
12
+ # with create_first_credit_card permission.
13
+ # This request will fail unless the user account has no credit card on it.
14
+ def create(credit_card_request)
15
+ request = build_request(credit_card_request, Requests::CreateCard)
16
+ request.send_to_api(:get, endpoint_path)
17
+ end
18
+
19
+ private
20
+
21
+ def path
22
+ 'credit_cards'
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ module Levelup
2
+ module Endpoints
3
+ # The endpoint holding all functions relating to orders for a specific
4
+ # location.
5
+ # This is a v14 endpoint and should not be expected to remain functional
6
+ # indefinitely.
7
+ class LocationOrders < Base
8
+ def initialize(location_id)
9
+ @id = location_id
10
+ end
11
+
12
+ # Gets a list of orders made at this location. This list is paginated.
13
+ #
14
+ # [merchant_auth_token]
15
+ # An access token for the merchant that owns this
16
+ # location.
17
+ def list(merchant_auth_token)
18
+ request = Requests::ListOrders.new(
19
+ merchant_access_token: merchant_auth_token)
20
+ request.send_to_api(:get, endpoint_path(:v14))
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :id
26
+
27
+ def path
28
+ "locations/#{id}/orders"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ module Levelup
2
+ module Endpoints
3
+ # The endpoint holding all functions relating to managing merchant-funded
4
+ # credit.
5
+ class MerchantFundedCredits < Base
6
+ def give(give_credit_request)
7
+ request = build_request(give_credit_request,
8
+ Requests::GiveMerchantCredit)
9
+ request.send_to_api(:post, endpoint_path)
10
+ end
11
+
12
+ private
13
+
14
+ def path
15
+ "merchant_funded_credits"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ module Levelup
2
+ module Endpoints
3
+ # The endpoint holding all functions relating to a single merchant's
4
+ # locations. This is a v14 endpoint and should not be expected to remain
5
+ # functional indefinitely.
6
+ class MerchantLocations < Base
7
+ def initialize(merchant_id)
8
+ @id = merchant_id
9
+ end
10
+
11
+ # Provides a list of locations controlled by this merchant. This list is
12
+ # not paginated.
13
+ #
14
+ # [merchant_auth_token]
15
+ # An authorization token with permission to view
16
+ # this merchant.
17
+ def list(merchant_auth_token)
18
+ request = Requests::ListLocations.new(
19
+ merchant_access_token: merchant_auth_token)
20
+ request.send_to_api(:get, endpoint_path(:v14))
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :id
26
+
27
+ def path
28
+ "merchants/#{id}/locations"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,28 @@
1
+ module Levelup
2
+ module Endpoints
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.
6
+ class MerchantOrders < Base
7
+ def initialize(merchant_id)
8
+ @id = merchant_id
9
+ end
10
+
11
+ # Provides merchant-facing details about a specific order. For more
12
+ # information about the parameters, see OrderDetailsRequest.
13
+ def details(uuid, merchant_access_token)
14
+ request = Requests::CreateOrderDetails.new(
15
+ merchant_access_token: merchant_access_token)
16
+ request.send_to_api(:get, endpoint_path(:v14) + "/#{uuid}")
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :id
22
+
23
+ def path
24
+ "merchants/#{id}/orders"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ module Levelup
2
+ module Endpoints
3
+ # The class holding all functions related to orders that do not specify a
4
+ # specific order. For single-order functions, see SpecificOrder.
5
+ class Orders < Base
6
+ # Creates an order. See OrderRequest for more info about the parameters.
7
+ def create(order_request)
8
+ request = build_request(order_request, Requests::CreateOrder)
9
+ request.send_to_api(:post, endpoint_path)
10
+ end
11
+
12
+ private
13
+
14
+ def path
15
+ 'orders'
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ module Levelup
2
+ module Endpoints
3
+ # The endpoint holding all functions related to managing permissions
4
+ # requests.
5
+ class PermissionsRequests < Base
6
+ def initialize(app_access_token)
7
+ @app_access_token = app_access_token
8
+ end
9
+
10
+ # Requests a set of permissions from the specified user.
11
+ # See RequestPermissionsRequest for more detail about parameters.
12
+ def create(user_permissions_request)
13
+ request = build_request(user_permissions_request,
14
+ Requests::RequestPermissions)
15
+ request.app_access_token ||= app_access_token
16
+ request.send_to_api(:post, endpoint_path)
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :app_access_token
22
+
23
+ def path
24
+ 'apps/permissions_requests'
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ module Levelup
2
+ module Endpoints
3
+ # The endpoint holding all functions related to managing users' QR codes.
4
+ class QrCodes < Base
5
+ def initialize(color: 0, tip_amount: 0, tip_percent: 0)
6
+ self.color = color
7
+ self.tip_amount = tip_amount
8
+ self.tip_percent = tip_percent
9
+ end
10
+
11
+ # Retrieves the specified user's QR code using parameters specified
12
+ # in the endpoint.
13
+ def get(user_access_token)
14
+ request = Requests::GetQrCode.new(user_access_token: user_access_token)
15
+ request.send_to_api(:get, endpoint_path)
16
+ end
17
+
18
+ private
19
+
20
+ attr_accessor :color, :tip_amount, :tip_percent
21
+
22
+ def path
23
+ "qr_codes?preferences[color]=#{color}&preferences[tip_amount]="\
24
+ "#{tip_amount}&preferences[tip_percent]=#{tip_percent}"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ module Levelup
2
+ module Endpoints
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.
6
+ class SpecificLocation < Base
7
+ attr_reader :id
8
+
9
+ def initialize(location_id)
10
+ @id = location_id
11
+ end
12
+
13
+ def orders
14
+ LocationOrders.new(id)
15
+ end
16
+
17
+ private
18
+
19
+ def path
20
+ "locations/#{id}"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ module Levelup
2
+ module Endpoints
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.
6
+ class SpecificMerchant < Base
7
+ attr_reader :id
8
+
9
+ def initialize(merchant_id)
10
+ @id = merchant_id
11
+ end
12
+
13
+ def locations
14
+ MerchantLocations.new(id)
15
+ end
16
+
17
+ def orders
18
+ MerchantOrders.new(id)
19
+ end
20
+
21
+ private
22
+
23
+ def path
24
+ "merchants/#{id}"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ module Levelup
2
+ module Endpoints
3
+ # Endpoint holding all functions relating to a specified order.
4
+ class SpecificOrder < Base
5
+ attr_reader :uuid
6
+ def initialize(order_uuid)
7
+ @uuid = order_uuid
8
+ end
9
+
10
+ # Refunds the order specified by this endpoint.
11
+ #
12
+ # [merchant_auth_token]
13
+ # A merchant access token with permissions to
14
+ # refund orders made at the location where this order was placed.
15
+ def refund(merchant_auth_token)
16
+ request = Requests::RefundOrder.new(
17
+ merchant_access_token: merchant_auth_token)
18
+ request.send_to_api(:post, endpoint_path + '/refund')
19
+ end
20
+
21
+ private
22
+
23
+ def path
24
+ "orders/#{uuid}"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ module Levelup
2
+ module Endpoints
3
+ # The endpoint holding all functions related to accessing a specified
4
+ # permissions request.
5
+ class SpecificPermissionsRequest < Base
6
+ def initialize(request_id, app_access_token)
7
+ self.app_access_token = app_access_token
8
+ self.request_id = request_id
9
+ end
10
+
11
+ def show
12
+ request = Requests::ShowPermissionsRequest.
13
+ new(app_access_token: app_access_token)
14
+ request.send_to_api(:get, endpoint_path)
15
+ end
16
+
17
+ private
18
+
19
+ attr_accessor :request_id, :app_access_token
20
+
21
+ def path
22
+ "apps/permissions_requests/#{request_id}"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ module Levelup
2
+ module Endpoints
3
+ # Endpoint holding all functions relating to user addresses.
4
+ class UserAddresses < Base
5
+ # Creates a specified user address. For more information on parameters,
6
+ # see UserAddressRequest.
7
+ def create(user_address_request)
8
+ request = build_request(user_address_request,
9
+ Requests::CreateAddress)
10
+ request.send_to_api(:post, endpoint_path)
11
+ end
12
+
13
+ def list(user_access_token)
14
+ request = Requests::ListAddresses(user_access_token: user_access_token)
15
+ request.send_to_api(:get, endpoint_path)
16
+ end
17
+
18
+ private
19
+
20
+ def path
21
+ 'user_addresses'
22
+ end
23
+ end
24
+ end
25
+ end