lemonsqueezy 0.2.2 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.env.example +2 -1
  3. data/Gemfile +2 -1
  4. data/Gemfile.lock +13 -9
  5. data/README.md +194 -68
  6. data/bin/console +3 -1
  7. data/lib/lemon_squeezy/client.rb +57 -63
  8. data/lib/lemon_squeezy/configuration.rb +12 -0
  9. data/lib/lemon_squeezy/models/checkout.rb +46 -0
  10. data/lib/lemon_squeezy/models/customer.rb +52 -0
  11. data/lib/lemon_squeezy/models/discount.rb +47 -0
  12. data/lib/lemon_squeezy/models/discount_redemption.rb +19 -0
  13. data/lib/lemon_squeezy/models/file.rb +19 -0
  14. data/lib/lemon_squeezy/models/license.rb +24 -0
  15. data/lib/lemon_squeezy/models/license_key.rb +32 -0
  16. data/lib/lemon_squeezy/models/license_key_instance.rb +19 -0
  17. data/lib/lemon_squeezy/models/order.rb +24 -0
  18. data/lib/lemon_squeezy/models/price.rb +19 -0
  19. data/lib/lemon_squeezy/models/product.rb +19 -0
  20. data/lib/lemon_squeezy/models/store.rb +19 -0
  21. data/lib/lemon_squeezy/models/subscription.rb +101 -0
  22. data/lib/lemon_squeezy/models/subscription_invoice.rb +19 -0
  23. data/lib/lemon_squeezy/models/subscription_item.rb +38 -0
  24. data/lib/lemon_squeezy/models/subscription_usage.rb +4 -0
  25. data/lib/lemon_squeezy/models/user.rb +14 -0
  26. data/lib/lemon_squeezy/models/variant.rb +19 -0
  27. data/lib/lemon_squeezy/models/webhook.rb +58 -0
  28. data/lib/lemon_squeezy/object.rb +15 -1
  29. data/lib/lemon_squeezy/version.rb +1 -1
  30. data/lib/lemon_squeezy.rb +34 -29
  31. metadata +23 -29
  32. data/lib/lemon_squeezy/objects/checkout.rb +0 -12
  33. data/lib/lemon_squeezy/objects/customer.rb +0 -12
  34. data/lib/lemon_squeezy/objects/discount.rb +0 -12
  35. data/lib/lemon_squeezy/objects/file.rb +0 -12
  36. data/lib/lemon_squeezy/objects/license_key.rb +0 -12
  37. data/lib/lemon_squeezy/objects/license_key_instance.rb +0 -12
  38. data/lib/lemon_squeezy/objects/order.rb +0 -12
  39. data/lib/lemon_squeezy/objects/order_item.rb +0 -12
  40. data/lib/lemon_squeezy/objects/product.rb +0 -12
  41. data/lib/lemon_squeezy/objects/store.rb +0 -12
  42. data/lib/lemon_squeezy/objects/subscription.rb +0 -12
  43. data/lib/lemon_squeezy/objects/subscription_invoice.rb +0 -12
  44. data/lib/lemon_squeezy/objects/variant.rb +0 -12
  45. data/lib/lemon_squeezy/resource.rb +0 -60
  46. data/lib/lemon_squeezy/resources/checkouts.rb +0 -42
  47. data/lib/lemon_squeezy/resources/customers.rb +0 -15
  48. data/lib/lemon_squeezy/resources/discounts.rb +0 -15
  49. data/lib/lemon_squeezy/resources/files.rb +0 -15
  50. data/lib/lemon_squeezy/resources/license_key_instances.rb +0 -15
  51. data/lib/lemon_squeezy/resources/license_keys.rb +0 -15
  52. data/lib/lemon_squeezy/resources/orders.rb +0 -20
  53. data/lib/lemon_squeezy/resources/products.rb +0 -15
  54. data/lib/lemon_squeezy/resources/stores.rb +0 -15
  55. data/lib/lemon_squeezy/resources/subscription_invoices.rb +0 -15
  56. data/lib/lemon_squeezy/resources/subscriptions.rb +0 -92
  57. data/lib/lemon_squeezy/resources/variants.rb +0 -15
data/lib/lemon_squeezy.rb CHANGED
@@ -5,38 +5,43 @@ require "faraday"
5
5
  require_relative "lemon_squeezy/version"
6
6
 
7
7
  module LemonSqueezy
8
-
8
+
9
+ autoload :Configuration, "lemon_squeezy/configuration"
9
10
  autoload :Client, "lemon_squeezy/client"
10
11
  autoload :Collection, "lemon_squeezy/collection"
11
12
  autoload :Error, "lemon_squeezy/error"
12
- autoload :Resource, "lemon_squeezy/resource"
13
13
  autoload :Object, "lemon_squeezy/object"
14
14
 
15
- autoload :StoresResource, "lemon_squeezy/resources/stores"
16
- autoload :ProductsResource, "lemon_squeezy/resources/products"
17
- autoload :VariantsResource, "lemon_squeezy/resources/variants"
18
- autoload :OrdersResource, "lemon_squeezy/resources/orders"
19
- autoload :SubscriptionsResource, "lemon_squeezy/resources/subscriptions"
20
- autoload :SubscriptionInvoicesResource, "lemon_squeezy/resources/subscription_invoices"
21
- autoload :DiscountsResource, "lemon_squeezy/resources/discounts"
22
- autoload :LicenseKeysResource, "lemon_squeezy/resources/license_keys"
23
- autoload :LicenseKeyInstancesResource, "lemon_squeezy/resources/license_key_instances"
24
- autoload :FilesResource, "lemon_squeezy/resources/files"
25
- autoload :CustomersResource, "lemon_squeezy/resources/customers"
26
- autoload :CheckoutsResource, "lemon_squeezy/resources/checkouts"
27
-
28
- autoload :Store, "lemon_squeezy/objects/store"
29
- autoload :Product, "lemon_squeezy/objects/product"
30
- autoload :Variant, "lemon_squeezy/objects/variant"
31
- autoload :Order, "lemon_squeezy/objects/order"
32
- autoload :OrderItem, "lemon_squeezy/objects/order_item"
33
- autoload :Subscription, "lemon_squeezy/objects/subscription"
34
- autoload :SubscriptionInvoice, "lemon_squeezy/objects/subscription_invoice"
35
- autoload :Discount, "lemon_squeezy/objects/discount"
36
- autoload :LicenseKey, "lemon_squeezy/objects/license_key"
37
- autoload :LicenseKeyInstance, "lemon_squeezy/objects/license_key_instance"
38
- autoload :File, "lemon_squeezy/objects/file"
39
- autoload :Customer, "lemon_squeezy/objects/customer"
40
- autoload :Checkout, "lemon_squeezy/objects/checkout"
41
-
15
+ class << self
16
+ attr_writer :config
17
+ end
18
+
19
+ def self.configure
20
+ yield(config) if block_given?
21
+ end
22
+
23
+ def self.config
24
+ @config ||= Configuration.new
25
+ end
26
+
27
+ autoload :User, "lemon_squeezy/models/user"
28
+ autoload :Store, "lemon_squeezy/models/store"
29
+ autoload :Product, "lemon_squeezy/models/product"
30
+ autoload :Variant, "lemon_squeezy/models/variant"
31
+ autoload :Order, "lemon_squeezy/models/order"
32
+ autoload :Subscription, "lemon_squeezy/models/subscription"
33
+ autoload :SubscriptionInvoice, "lemon_squeezy/models/subscription_invoice"
34
+ autoload :SubscriptionItem, "lemon_squeezy/models/subscription_item"
35
+ autoload :SubscriptionUsage, "lemon_squeezy/models/subscription_usage"
36
+ autoload :Discount, "lemon_squeezy/models/discount"
37
+ autoload :DiscountRedemption, "lemon_squeezy/models/discount_redemption"
38
+ autoload :License, "lemon_squeezy/models/license"
39
+ autoload :LicenseKey, "lemon_squeezy/models/license_key"
40
+ autoload :LicenseKeyInstance, "lemon_squeezy/models/license_key_instance"
41
+ autoload :File, "lemon_squeezy/models/file"
42
+ autoload :Customer, "lemon_squeezy/models/customer"
43
+ autoload :Checkout, "lemon_squeezy/models/checkout"
44
+ autoload :Price, "lemon_squeezy/models/price"
45
+ autoload :Webhook, "lemon_squeezy/models/webhook"
46
+
42
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lemonsqueezy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Perry
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-25 00:00:00.000000000 Z
11
+ date: 2024-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -42,34 +42,28 @@ files:
42
42
  - lib/lemon_squeezy.rb
43
43
  - lib/lemon_squeezy/client.rb
44
44
  - lib/lemon_squeezy/collection.rb
45
+ - lib/lemon_squeezy/configuration.rb
45
46
  - lib/lemon_squeezy/error.rb
47
+ - lib/lemon_squeezy/models/checkout.rb
48
+ - lib/lemon_squeezy/models/customer.rb
49
+ - lib/lemon_squeezy/models/discount.rb
50
+ - lib/lemon_squeezy/models/discount_redemption.rb
51
+ - lib/lemon_squeezy/models/file.rb
52
+ - lib/lemon_squeezy/models/license.rb
53
+ - lib/lemon_squeezy/models/license_key.rb
54
+ - lib/lemon_squeezy/models/license_key_instance.rb
55
+ - lib/lemon_squeezy/models/order.rb
56
+ - lib/lemon_squeezy/models/price.rb
57
+ - lib/lemon_squeezy/models/product.rb
58
+ - lib/lemon_squeezy/models/store.rb
59
+ - lib/lemon_squeezy/models/subscription.rb
60
+ - lib/lemon_squeezy/models/subscription_invoice.rb
61
+ - lib/lemon_squeezy/models/subscription_item.rb
62
+ - lib/lemon_squeezy/models/subscription_usage.rb
63
+ - lib/lemon_squeezy/models/user.rb
64
+ - lib/lemon_squeezy/models/variant.rb
65
+ - lib/lemon_squeezy/models/webhook.rb
46
66
  - lib/lemon_squeezy/object.rb
47
- - lib/lemon_squeezy/objects/checkout.rb
48
- - lib/lemon_squeezy/objects/customer.rb
49
- - lib/lemon_squeezy/objects/discount.rb
50
- - lib/lemon_squeezy/objects/file.rb
51
- - lib/lemon_squeezy/objects/license_key.rb
52
- - lib/lemon_squeezy/objects/license_key_instance.rb
53
- - lib/lemon_squeezy/objects/order.rb
54
- - lib/lemon_squeezy/objects/order_item.rb
55
- - lib/lemon_squeezy/objects/product.rb
56
- - lib/lemon_squeezy/objects/store.rb
57
- - lib/lemon_squeezy/objects/subscription.rb
58
- - lib/lemon_squeezy/objects/subscription_invoice.rb
59
- - lib/lemon_squeezy/objects/variant.rb
60
- - lib/lemon_squeezy/resource.rb
61
- - lib/lemon_squeezy/resources/checkouts.rb
62
- - lib/lemon_squeezy/resources/customers.rb
63
- - lib/lemon_squeezy/resources/discounts.rb
64
- - lib/lemon_squeezy/resources/files.rb
65
- - lib/lemon_squeezy/resources/license_key_instances.rb
66
- - lib/lemon_squeezy/resources/license_keys.rb
67
- - lib/lemon_squeezy/resources/orders.rb
68
- - lib/lemon_squeezy/resources/products.rb
69
- - lib/lemon_squeezy/resources/stores.rb
70
- - lib/lemon_squeezy/resources/subscription_invoices.rb
71
- - lib/lemon_squeezy/resources/subscriptions.rb
72
- - lib/lemon_squeezy/resources/variants.rb
73
67
  - lib/lemon_squeezy/version.rb
74
68
  - lib/lemonsqueezy.rb
75
69
  homepage: https://github.com/deanpcmad/lemonsqueezy
@@ -92,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
86
  - !ruby/object:Gem::Version
93
87
  version: '0'
94
88
  requirements: []
95
- rubygems_version: 3.3.7
89
+ rubygems_version: 3.4.22
96
90
  signing_key:
97
91
  specification_version: 4
98
92
  summary: Ruby library for interacting with the Lemon Squeezy API
@@ -1,12 +0,0 @@
1
- module LemonSqueezy
2
- class Checkout < Object
3
-
4
- def initialize(options = {})
5
- options.delete "relationships"
6
- options.delete "links"
7
-
8
- super options
9
- end
10
-
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- module LemonSqueezy
2
- class Customer < Object
3
-
4
- def initialize(options = {})
5
- options.delete "relationships"
6
- options.delete "links"
7
-
8
- super options
9
- end
10
-
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- module LemonSqueezy
2
- class Discount < Object
3
-
4
- def initialize(options = {})
5
- options.delete "relationships"
6
- options.delete "links"
7
-
8
- super options
9
- end
10
-
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- module LemonSqueezy
2
- class File < Object
3
-
4
- def initialize(options = {})
5
- options.delete "relationships"
6
- options.delete "links"
7
-
8
- super options
9
- end
10
-
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- module LemonSqueezy
2
- class LicenseKey < Object
3
-
4
- def initialize(options = {})
5
- options.delete "relationships"
6
- options.delete "links"
7
-
8
- super options
9
- end
10
-
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- module LemonSqueezy
2
- class LicenseKeyInstance < Object
3
-
4
- def initialize(options = {})
5
- options.delete "relationships"
6
- options.delete "links"
7
-
8
- super options
9
- end
10
-
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- module LemonSqueezy
2
- class Order < Object
3
-
4
- def initialize(options = {})
5
- options.delete "relationships"
6
- options.delete "links"
7
-
8
- super options
9
- end
10
-
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- module LemonSqueezy
2
- class OrderItem < Object
3
-
4
- def initialize(options = {})
5
- options.delete "relationships"
6
- options.delete "links"
7
-
8
- super options
9
- end
10
-
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- module LemonSqueezy
2
- class Product < Object
3
-
4
- def initialize(options = {})
5
- options.delete "relationships"
6
- options.delete "links"
7
-
8
- super options
9
- end
10
-
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- module LemonSqueezy
2
- class Store < Object
3
-
4
- def initialize(options = {})
5
- options.delete "relationships"
6
- options.delete "links"
7
-
8
- super options
9
- end
10
-
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- module LemonSqueezy
2
- class Subscription < Object
3
-
4
- def initialize(options = {})
5
- options.delete "relationships"
6
- options.delete "links"
7
-
8
- super options
9
- end
10
-
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- module LemonSqueezy
2
- class SubscriptionInvoice < Object
3
-
4
- def initialize(options = {})
5
- options.delete "relationships"
6
- options.delete "links"
7
-
8
- super options
9
- end
10
-
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- module LemonSqueezy
2
- class Variant < Object
3
-
4
- def initialize(options = {})
5
- options.delete "relationships"
6
- options.delete "links"
7
-
8
- super options
9
- end
10
-
11
- end
12
- end
@@ -1,60 +0,0 @@
1
- module LemonSqueezy
2
- class Resource
3
- attr_reader :client
4
-
5
- def initialize(client)
6
- @client = client
7
- end
8
-
9
- private
10
-
11
- def get_request(url, params: {}, headers: {})
12
- handle_response client.connection.get(url, params, headers)
13
- end
14
-
15
- def post_request(url, body: {}, headers: {})
16
- handle_response client.connection.post(url, body, headers)
17
- end
18
-
19
- def patch_request(url, body:, headers: {})
20
- handle_response client.connection.patch(url, body, headers)
21
- end
22
-
23
- def put_request(url, body:, headers: {})
24
- handle_response client.connection.put(url, body, headers)
25
- end
26
-
27
- def delete_request(url, params: {}, headers: {})
28
- handle_response client.connection.delete(url, params, headers)
29
- end
30
-
31
- def handle_response(response)
32
- case response.status
33
- when 400
34
- raise Error, "Error 400: Your request was malformed. '#{response.body["errors"][0]["detail"]}'"
35
- when 401
36
- raise Error, "Error 401: You did not supply valid authentication credentials. '#{response.body["error"]}'"
37
- when 403
38
- raise Error, "Error 403: You are not allowed to perform that action. '#{response.body["error"]}'"
39
- when 404
40
- raise Error, "Error 404: No results were found for your request. '#{response.body["error"]}'"
41
- when 409
42
- raise Error, "Error 409: Your request was a conflict. '#{response.body["message"]}'"
43
- when 429
44
- raise Error, "Error 429: Your request exceeded the API rate limit. '#{response.body["error"]}'"
45
- when 500
46
- raise Error, "Error 500: We were unable to perform the request due to server-side problems. '#{response.body["error"]}'"
47
- when 503
48
- raise Error, "Error 503: You have been rate limited for sending more than 20 requests per second. '#{response.body["error"]}'"
49
- when 501
50
- raise Error, "Error 501: This resource has not been implemented. '#{response.body["error"]}'"
51
- end
52
-
53
- if response.body && response.body["error"]
54
- raise Error, "Error #{response.body["error"]["code"]} - #{response.body["error"]["message"]}"
55
- end
56
-
57
- response
58
- end
59
- end
60
- end
@@ -1,42 +0,0 @@
1
- module LemonSqueezy
2
- class CheckoutsResource < Resource
3
-
4
- def list(**params)
5
- response = get_request("checkouts", params: params)
6
- Collection.from_response(response, type: Customer)
7
- end
8
-
9
- def get(id:)
10
- response = get_request("checkouts/#{id}")
11
- Customer.new(response.body["data"]) if response.success?
12
- end
13
-
14
- def create(store_id:, variant_id:, **attrs)
15
- data = {}
16
-
17
- data["type"] = "checkouts"
18
-
19
- data["relationships"] = {
20
- store: {
21
- data: {
22
- type: "stores",
23
- id: store_id.to_s
24
- }
25
- },
26
- variant: {
27
- data: {
28
- type: "variants",
29
- id: variant_id.to_s
30
- }
31
- }
32
- }
33
-
34
- data["attributes"] = attrs
35
-
36
- response = post_request("checkouts", body: {data: data}.to_json)
37
-
38
- Checkout.new(response.body["data"]) if response.success?
39
- end
40
-
41
- end
42
- end
@@ -1,15 +0,0 @@
1
- module LemonSqueezy
2
- class CustomersResource < Resource
3
-
4
- def list(**params)
5
- response = get_request("customers", params: params)
6
- Collection.from_response(response, type: Customer)
7
- end
8
-
9
- def get(id:)
10
- response = get_request("customers/#{id}")
11
- Customer.new(response.body["data"]) if response.success?
12
- end
13
-
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- module LemonSqueezy
2
- class DiscountsResource < Resource
3
-
4
- def list(**params)
5
- response = get_request("discounts", params: params)
6
- Collection.from_response(response, type: Discount)
7
- end
8
-
9
- def get(id:)
10
- response = get_request("discounts/#{id}")
11
- Discount.new(response.body["data"]) if response.success?
12
- end
13
-
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- module LemonSqueezy
2
- class FilesResource < Resource
3
-
4
- def list(**params)
5
- response = get_request("files", params: params)
6
- Collection.from_response(response, type: File)
7
- end
8
-
9
- def get(id:)
10
- response = get_request("files/#{id}")
11
- File.new(response.body["data"]) if response.success?
12
- end
13
-
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- module LemonSqueezy
2
- class LicenseKeyInstancesResource < Resource
3
-
4
- def list(**params)
5
- response = get_request("license-key-instances", params: params)
6
- Collection.from_response(response, type: LicenseKeyInstance)
7
- end
8
-
9
- def get(id:)
10
- response = get_request("license-key-instances/#{id}")
11
- LicenseKeyInstance.new(response.body["data"]) if response.success?
12
- end
13
-
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- module LemonSqueezy
2
- class LicenseKeysResource < Resource
3
-
4
- def list(**params)
5
- response = get_request("license-keys", params: params)
6
- Collection.from_response(response, type: LicenseKey)
7
- end
8
-
9
- def get(id:)
10
- response = get_request("license-keys/#{id}")
11
- LicenseKey.new(response.body["data"]) if response.success?
12
- end
13
-
14
- end
15
- end
@@ -1,20 +0,0 @@
1
- module LemonSqueezy
2
- class OrdersResource < Resource
3
-
4
- def list(**params)
5
- response = get_request("orders", params: params)
6
- Collection.from_response(response, type: Order)
7
- end
8
-
9
- def get(id:)
10
- response = get_request("orders/#{id}")
11
- Order.new(response.body["data"]) if response.success?
12
- end
13
-
14
- def order_items(id:)
15
- response = get_request("order-items", params: {order_id: id})
16
- Collection.from_response(response, type: OrderItem)
17
- end
18
-
19
- end
20
- end
@@ -1,15 +0,0 @@
1
- module LemonSqueezy
2
- class ProductsResource < Resource
3
-
4
- def list(**params)
5
- response = get_request("products", params: params)
6
- Collection.from_response(response, type: Product)
7
- end
8
-
9
- def get(id:)
10
- response = get_request("products/#{id}")
11
- Product.new(response.body["data"]) if response.success?
12
- end
13
-
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- module LemonSqueezy
2
- class StoresResource < Resource
3
-
4
- def list
5
- response = get_request("stores")
6
- Collection.from_response(response, type: Store)
7
- end
8
-
9
- def get(id:)
10
- response = get_request("stores/#{id}")
11
- Store.new(response.body["data"]) if response.success?
12
- end
13
-
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- module LemonSqueezy
2
- class SubscriptionInvoicesResource < Resource
3
-
4
- def list(**params)
5
- response = get_request("subscription-invoices", params: params)
6
- Collection.from_response(response, type: SubscriptionInvoice)
7
- end
8
-
9
- def get(id:)
10
- response = get_request("subscription-invoices/#{id}")
11
- SubscriptionInvoice.new(response.body["data"]) if response.success?
12
- end
13
-
14
- end
15
- end