lemonsqueezy 1.0.0 → 1.1.0
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.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/Gemfile.lock +15 -7
- data/README.md +26 -5
- data/lib/lemon_squeezy/client.rb +15 -5
- data/lib/lemon_squeezy/collection.rb +17 -2
- data/lib/lemon_squeezy/configuration.rb +2 -1
- data/lib/lemon_squeezy/models/checkout.rb +1 -1
- data/lib/lemon_squeezy/models/customer.rb +1 -1
- data/lib/lemon_squeezy/models/discount.rb +1 -1
- data/lib/lemon_squeezy/models/discount_redemption.rb +1 -1
- data/lib/lemon_squeezy/models/file.rb +1 -1
- data/lib/lemon_squeezy/models/license_key.rb +1 -1
- data/lib/lemon_squeezy/models/license_key_instance.rb +1 -1
- data/lib/lemon_squeezy/models/order.rb +1 -1
- data/lib/lemon_squeezy/models/price.rb +1 -1
- data/lib/lemon_squeezy/models/product.rb +1 -1
- data/lib/lemon_squeezy/models/store.rb +2 -2
- data/lib/lemon_squeezy/models/subscription.rb +5 -3
- data/lib/lemon_squeezy/models/subscription_invoice.rb +1 -1
- data/lib/lemon_squeezy/models/subscription_item.rb +1 -1
- data/lib/lemon_squeezy/models/variant.rb +1 -1
- data/lib/lemon_squeezy/models/webhook.rb +1 -1
- data/lib/lemon_squeezy/version.rb +1 -1
- metadata +3 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd14c80c85077df0e50fb727cbdb98f0fb23da8905dda8f579404f76b78054d8
|
4
|
+
data.tar.gz: d962818e7851b0c67e51cb4b0cbae31f33012ed593110d4e456b704d05482283
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fe5de09cc0a63fe09322f35d4c77d0117dbb4288fcffb6a385f9abc12142a20af501585cee66c7c526984e48992db3714bbe059a12824f521a862558c93a90c
|
7
|
+
data.tar.gz: f7af44ccce6cb505180d573c2513a5973dc6eb9fa4dd91e637f103f7210fcb04d098f83e9ea6b4b7215796fac6be1001b1c688386849a44ff9fe4e34af563c2e
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,31 +1,39 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lemonsqueezy (1.
|
4
|
+
lemonsqueezy (1.1.0)
|
5
5
|
faraday (~> 2.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
+
base64 (0.2.0)
|
10
11
|
dotenv (2.8.1)
|
11
|
-
faraday (2.
|
12
|
-
faraday-net_http (>= 2.0, < 3.
|
13
|
-
|
14
|
-
|
12
|
+
faraday (2.12.2)
|
13
|
+
faraday-net_http (>= 2.0, < 3.5)
|
14
|
+
json
|
15
|
+
logger
|
16
|
+
faraday-net_http (3.4.0)
|
17
|
+
net-http (>= 0.5.0)
|
18
|
+
json (2.10.2)
|
19
|
+
logger (1.6.6)
|
15
20
|
minitest (5.20.0)
|
16
|
-
|
21
|
+
mutex_m (0.3.0)
|
22
|
+
net-http (0.6.0)
|
17
23
|
uri
|
18
24
|
rake (13.1.0)
|
19
|
-
uri (0.
|
25
|
+
uri (1.0.3)
|
20
26
|
vcr (6.2.0)
|
21
27
|
|
22
28
|
PLATFORMS
|
23
29
|
x86_64-linux
|
24
30
|
|
25
31
|
DEPENDENCIES
|
32
|
+
base64
|
26
33
|
dotenv
|
27
34
|
lemonsqueezy!
|
28
35
|
minitest (~> 5.0)
|
36
|
+
mutex_m
|
29
37
|
rake (~> 13.0)
|
30
38
|
vcr
|
31
39
|
|
data/README.md
CHANGED
@@ -19,6 +19,7 @@ Firstly you'll need to create an API Key on your [settings page](https://app.lem
|
|
19
19
|
```ruby
|
20
20
|
LemonSqueezy.configure do |config|
|
21
21
|
config.api_key = ENV["LEMON_SQUEEZY_API_KEY"]
|
22
|
+
config.default_page_size = 10 # Optional: Set default page size for paginated requests
|
22
23
|
end
|
23
24
|
```
|
24
25
|
|
@@ -159,7 +160,8 @@ LemonSqueezy::Subscription.cancel id: 123
|
|
159
160
|
LemonSqueezy::Subscription.uncancel id: 123
|
160
161
|
|
161
162
|
# Change the Plan for a Subscription
|
162
|
-
|
163
|
+
# invoice_immediately and disable_prorations are optional and false by default.
|
164
|
+
LemonSqueezy::Subscription.change_plan id: 123, plan_id: 111, variant_id: 111, invoice_immediately: false, disable_prorations: false
|
163
165
|
```
|
164
166
|
|
165
167
|
### Subscription Invoices
|
@@ -300,16 +302,16 @@ LemonSqueezy::File.retrieve id: 123
|
|
300
302
|
|
301
303
|
```ruby
|
302
304
|
# Retrieves a list of Checkouts
|
303
|
-
|
305
|
+
LemonSqueezy::Checkout.list
|
304
306
|
|
305
307
|
# Retrieves a list of Checkouts for a store
|
306
|
-
|
308
|
+
LemonSqueezy::Checkout.list store_id: 123
|
307
309
|
|
308
310
|
# Retrieves a list of Checkouts for a variant
|
309
|
-
|
311
|
+
LemonSqueezy::Checkout.list variant_id: 123
|
310
312
|
|
311
313
|
# Retrieves a Checkout
|
312
|
-
|
314
|
+
LemonSqueezy::Checkout.retrieve id: 123
|
313
315
|
|
314
316
|
# Creates a Checkout
|
315
317
|
# View docs for more info: https://docs.lemonsqueezy.com/api/checkouts#create-a-checkout
|
@@ -342,6 +344,25 @@ LemonSqueezy::Webhook.update id: 123, events: ["order_created", "subscription_cr
|
|
342
344
|
LemonSqueezy::Webhook.delete id: 123
|
343
345
|
```
|
344
346
|
|
347
|
+
### Pagination
|
348
|
+
|
349
|
+
All list methods support pagination. You can control pagination in two ways:
|
350
|
+
|
351
|
+
1. Using the default page size in configuration:
|
352
|
+
```ruby
|
353
|
+
LemonSqueezy.configure do |config|
|
354
|
+
config.default_page_size = 10 # This will be used for all list requests
|
355
|
+
end
|
356
|
+
```
|
357
|
+
|
358
|
+
2. Using pagination parameters in individual requests:
|
359
|
+
```ruby
|
360
|
+
# Get first page with 20 items
|
361
|
+
customers = LemonSqueezy::Customer.list(page: { size: 20, number: 1 })
|
362
|
+
|
363
|
+
# Get next page
|
364
|
+
next_page_customers = LemonSqueezy::Customer.list(page: { size: 20, number: 2 })
|
365
|
+
```
|
345
366
|
|
346
367
|
## Contributing
|
347
368
|
|
data/lib/lemon_squeezy/client.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module LemonSqueezy
|
2
2
|
class Client
|
3
|
-
|
4
3
|
class << self
|
5
|
-
|
4
|
+
|
6
5
|
def connection
|
7
6
|
@connection ||= Faraday.new("https://api.lemonsqueezy.com/v1") do |conn|
|
8
7
|
conn.request :authorization, :Bearer, LemonSqueezy.config.api_key
|
@@ -18,7 +17,7 @@ module LemonSqueezy
|
|
18
17
|
conn.response :json
|
19
18
|
end
|
20
19
|
end
|
21
|
-
|
20
|
+
|
22
21
|
def get_request(url, params: {}, headers: {})
|
23
22
|
handle_response connection.get(url, params, headers)
|
24
23
|
end
|
@@ -34,7 +33,7 @@ module LemonSqueezy
|
|
34
33
|
def delete_request(url, headers: {})
|
35
34
|
handle_response connection.delete(url, headers)
|
36
35
|
end
|
37
|
-
|
36
|
+
|
38
37
|
def handle_response(response)
|
39
38
|
case response.status
|
40
39
|
when 400
|
@@ -68,7 +67,18 @@ module LemonSqueezy
|
|
68
67
|
response
|
69
68
|
end
|
70
69
|
|
71
|
-
|
70
|
+
def build_list_request_params(params)
|
71
|
+
filter_params = params.reject { |k, _| k == :page }
|
72
|
+
pagination_params = params[:page] || {}
|
73
|
+
pagination_params[:size] = LemonSqueezy.config.default_page_size if pagination_params[:size].nil?
|
72
74
|
|
75
|
+
request_params = {}
|
76
|
+
request_params[:filter] = filter_params unless filter_params.empty?
|
77
|
+
request_params[:page] = pagination_params unless pagination_params.empty?
|
78
|
+
request_params
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
73
83
|
end
|
74
84
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module LemonSqueezy
|
2
2
|
class Collection
|
3
|
-
attr_reader :data, :total
|
3
|
+
attr_reader :data, :meta, :total
|
4
4
|
|
5
5
|
def self.from_response(response, type:, key: nil)
|
6
6
|
body = response.body
|
@@ -13,14 +13,29 @@ module LemonSqueezy
|
|
13
13
|
total = body["data"].count
|
14
14
|
end
|
15
15
|
|
16
|
+
# Extract pagination metadata if available
|
17
|
+
meta = body["meta"]
|
18
|
+
pagination = meta&.dig("page")
|
19
|
+
|
16
20
|
new(
|
17
21
|
data: data,
|
22
|
+
meta: {
|
23
|
+
page: {
|
24
|
+
total: pagination&.dig("total"),
|
25
|
+
current_page: pagination&.dig("currentPage"),
|
26
|
+
from: pagination&.dig("from"),
|
27
|
+
to: pagination&.dig("to"),
|
28
|
+
last_page: pagination&.dig("lastPage"),
|
29
|
+
per_page: pagination&.dig("perPage")
|
30
|
+
}
|
31
|
+
},
|
18
32
|
total: total
|
19
33
|
)
|
20
34
|
end
|
21
35
|
|
22
|
-
def initialize(data:, total:)
|
36
|
+
def initialize(data:, meta:, total:)
|
23
37
|
@data = data
|
38
|
+
@meta = meta
|
24
39
|
@total = total
|
25
40
|
end
|
26
41
|
end
|
@@ -4,7 +4,7 @@ module LemonSqueezy
|
|
4
4
|
class << self
|
5
5
|
|
6
6
|
def list(**params)
|
7
|
-
response = Client.get_request("checkouts", params:
|
7
|
+
response = Client.get_request("checkouts", params: Client.build_list_request_params(params))
|
8
8
|
Collection.from_response(response, type: Checkout)
|
9
9
|
end
|
10
10
|
|
@@ -4,7 +4,7 @@ module LemonSqueezy
|
|
4
4
|
class << self
|
5
5
|
|
6
6
|
def list(**params)
|
7
|
-
response = Client.get_request("customers", params:
|
7
|
+
response = Client.get_request("customers", params: Client.build_list_request_params(params))
|
8
8
|
Collection.from_response(response, type: Customer)
|
9
9
|
end
|
10
10
|
|
@@ -4,7 +4,7 @@ module LemonSqueezy
|
|
4
4
|
class << self
|
5
5
|
|
6
6
|
def list(**params)
|
7
|
-
response = Client.get_request("discounts", params:
|
7
|
+
response = Client.get_request("discounts", params: Client.build_list_request_params(params))
|
8
8
|
Collection.from_response(response, type: Discount)
|
9
9
|
end
|
10
10
|
|
@@ -4,7 +4,7 @@ module LemonSqueezy
|
|
4
4
|
class << self
|
5
5
|
|
6
6
|
def list(**params)
|
7
|
-
response = Client.get_request("discount-redemptions", params:
|
7
|
+
response = Client.get_request("discount-redemptions", params: Client.build_list_request_params(params))
|
8
8
|
Collection.from_response(response, type: DiscountRedemption)
|
9
9
|
end
|
10
10
|
|
@@ -4,7 +4,7 @@ module LemonSqueezy
|
|
4
4
|
class << self
|
5
5
|
|
6
6
|
def list(**params)
|
7
|
-
response = Client.get_request("files", params:
|
7
|
+
response = Client.get_request("files", params: Client.build_list_request_params(params))
|
8
8
|
Collection.from_response(response, type: File)
|
9
9
|
end
|
10
10
|
|
@@ -4,7 +4,7 @@ module LemonSqueezy
|
|
4
4
|
class << self
|
5
5
|
|
6
6
|
def list(**params)
|
7
|
-
response = Client.get_request("license-keys", params:
|
7
|
+
response = Client.get_request("license-keys", params: Client.build_list_request_params(params))
|
8
8
|
Collection.from_response(response, type: LicenseKey)
|
9
9
|
end
|
10
10
|
|
@@ -4,7 +4,7 @@ module LemonSqueezy
|
|
4
4
|
class << self
|
5
5
|
|
6
6
|
def list(**params)
|
7
|
-
response = Client.get_request("license-key-instances", params:
|
7
|
+
response = Client.get_request("license-key-instances", params: Client.build_list_request_params(params))
|
8
8
|
Collection.from_response(response, type: LicenseKeyInstance)
|
9
9
|
end
|
10
10
|
|
@@ -4,7 +4,7 @@ module LemonSqueezy
|
|
4
4
|
class << self
|
5
5
|
|
6
6
|
def list(**params)
|
7
|
-
response = Client.get_request("orders", params:
|
7
|
+
response = Client.get_request("orders", params: Client.build_list_request_params(params))
|
8
8
|
Collection.from_response(response, type: Order)
|
9
9
|
end
|
10
10
|
|
@@ -4,7 +4,7 @@ module LemonSqueezy
|
|
4
4
|
class << self
|
5
5
|
|
6
6
|
def list(**params)
|
7
|
-
response = Client.get_request("prices", params:
|
7
|
+
response = Client.get_request("prices", params: Client.build_list_request_params(params))
|
8
8
|
Collection.from_response(response, type: Price)
|
9
9
|
end
|
10
10
|
|
@@ -4,7 +4,7 @@ module LemonSqueezy
|
|
4
4
|
class << self
|
5
5
|
|
6
6
|
def list(**params)
|
7
|
-
response = Client.get_request("products", params:
|
7
|
+
response = Client.get_request("products", params: Client.build_list_request_params(params))
|
8
8
|
Collection.from_response(response, type: Product)
|
9
9
|
end
|
10
10
|
|
@@ -3,8 +3,8 @@ module LemonSqueezy
|
|
3
3
|
|
4
4
|
class << self
|
5
5
|
|
6
|
-
def list
|
7
|
-
response = Client.get_request("stores")
|
6
|
+
def list(**params)
|
7
|
+
response = Client.get_request("stores", params: Client.build_list_request_params(params))
|
8
8
|
Collection.from_response(response, type: Store)
|
9
9
|
end
|
10
10
|
|
@@ -4,7 +4,7 @@ module LemonSqueezy
|
|
4
4
|
class << self
|
5
5
|
|
6
6
|
def list(**params)
|
7
|
-
response = Client.get_request("subscriptions", params:
|
7
|
+
response = Client.get_request("subscriptions", params: Client.build_list_request_params(params))
|
8
8
|
Collection.from_response(response, type: Subscription)
|
9
9
|
end
|
10
10
|
|
@@ -77,14 +77,16 @@ module LemonSqueezy
|
|
77
77
|
Subscription.new(response.body["data"]) if response.success?
|
78
78
|
end
|
79
79
|
|
80
|
-
def change_plan(id:, plan_id:, variant_id:)
|
80
|
+
def change_plan(id:, plan_id:, variant_id:, invoice_immediately: false, disable_prorations: false)
|
81
81
|
body = {
|
82
82
|
data: {
|
83
83
|
type: "subscriptions",
|
84
84
|
id: id.to_s,
|
85
85
|
attributes: {
|
86
86
|
product_id: plan_id,
|
87
|
-
variant_id: variant_id
|
87
|
+
variant_id: variant_id,
|
88
|
+
invoice_immediately: invoice_immediately,
|
89
|
+
disable_prorations: disable_prorations
|
88
90
|
}
|
89
91
|
}
|
90
92
|
}
|
@@ -4,7 +4,7 @@ module LemonSqueezy
|
|
4
4
|
class << self
|
5
5
|
|
6
6
|
def list(**params)
|
7
|
-
response = Client.get_request("subscription-invoices", params:
|
7
|
+
response = Client.get_request("subscription-invoices", params: Client.build_list_request_params(params))
|
8
8
|
Collection.from_response(response, type: SubscriptionInvoice)
|
9
9
|
end
|
10
10
|
|
@@ -4,7 +4,7 @@ module LemonSqueezy
|
|
4
4
|
class << self
|
5
5
|
|
6
6
|
def list(**params)
|
7
|
-
response = Client.get_request("subscription-items", params:
|
7
|
+
response = Client.get_request("subscription-items", params: Client.build_list_request_params(params))
|
8
8
|
Collection.from_response(response, type: SubscriptionItem)
|
9
9
|
end
|
10
10
|
|
@@ -4,7 +4,7 @@ module LemonSqueezy
|
|
4
4
|
class << self
|
5
5
|
|
6
6
|
def list(**params)
|
7
|
-
response = Client.get_request("variants", params:
|
7
|
+
response = Client.get_request("variants", params: Client.build_list_request_params(params))
|
8
8
|
Collection.from_response(response, type: Variant)
|
9
9
|
end
|
10
10
|
|
@@ -4,7 +4,7 @@ module LemonSqueezy
|
|
4
4
|
class << self
|
5
5
|
|
6
6
|
def list(**params)
|
7
|
-
response = Client.get_request("webhooks", params:
|
7
|
+
response = Client.get_request("webhooks", params: Client.build_list_request_params(params))
|
8
8
|
Collection.from_response(response, type: Webhook)
|
9
9
|
end
|
10
10
|
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lemonsqueezy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dean Perry
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-03-26 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: faraday
|
@@ -24,7 +23,6 @@ dependencies:
|
|
24
23
|
- - "~>"
|
25
24
|
- !ruby/object:Gem::Version
|
26
25
|
version: '2.0'
|
27
|
-
description:
|
28
26
|
email:
|
29
27
|
- dean@deanpcmad.com
|
30
28
|
executables: []
|
@@ -71,7 +69,6 @@ licenses: []
|
|
71
69
|
metadata:
|
72
70
|
homepage_uri: https://github.com/deanpcmad/lemonsqueezy
|
73
71
|
source_code_uri: https://github.com/deanpcmad/lemonsqueezy
|
74
|
-
post_install_message:
|
75
72
|
rdoc_options: []
|
76
73
|
require_paths:
|
77
74
|
- lib
|
@@ -86,8 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
83
|
- !ruby/object:Gem::Version
|
87
84
|
version: '0'
|
88
85
|
requirements: []
|
89
|
-
rubygems_version: 3.
|
90
|
-
signing_key:
|
86
|
+
rubygems_version: 3.6.2
|
91
87
|
specification_version: 4
|
92
88
|
summary: Ruby library for interacting with the Lemon Squeezy API
|
93
89
|
test_files: []
|