lemonsqueezy 1.0.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53f2c6ca5274eba19d0bff2b7d05b439f4ffaad8fe2061537d35eafea9930337
4
- data.tar.gz: 0d41faa2caed4e7f142a64df9196ff3c28f66d17f773108329d5876d2d299b85
3
+ metadata.gz: dd14c80c85077df0e50fb727cbdb98f0fb23da8905dda8f579404f76b78054d8
4
+ data.tar.gz: d962818e7851b0c67e51cb4b0cbae31f33012ed593110d4e456b704d05482283
5
5
  SHA512:
6
- metadata.gz: a8c0b303b09b54fb089eb5bc6d4dbe62fc162dc9bc6052860fc4f0b5ec61eb82cbb9fc9ba8c3e566e7251583a60ebeb52b6579fd366facf938745c74c3981555
7
- data.tar.gz: '016958edb001b1e7b42c67280184a14cbfd29e455fd15fb0586766f3b8cfd8d52330c940f2d0e4551dd88ea23a32b6bdb96ad87a86b12b39e6ef00d5ec724e22'
6
+ metadata.gz: 0fe5de09cc0a63fe09322f35d4c77d0117dbb4288fcffb6a385f9abc12142a20af501585cee66c7c526984e48992db3714bbe059a12824f521a862558c93a90c
7
+ data.tar.gz: f7af44ccce6cb505180d573c2513a5973dc6eb9fa4dd91e637f103f7210fcb04d098f83e9ea6b4b7215796fac6be1001b1c688386849a44ff9fe4e34af563c2e
data/Gemfile CHANGED
@@ -10,3 +10,7 @@ gem "rake", "~> 13.0"
10
10
  gem "minitest", "~> 5.0"
11
11
  gem "dotenv"
12
12
  gem "vcr"
13
+
14
+ # Ruby 3.4
15
+ gem "mutex_m"
16
+ gem "base64"
data/Gemfile.lock CHANGED
@@ -1,31 +1,39 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lemonsqueezy (1.0.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.9.0)
12
- faraday-net_http (>= 2.0, < 3.2)
13
- faraday-net_http (3.1.0)
14
- net-http
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
- net-http (0.4.1)
21
+ mutex_m (0.3.0)
22
+ net-http (0.6.0)
17
23
  uri
18
24
  rake (13.1.0)
19
- uri (0.13.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
 
@@ -301,16 +302,16 @@ LemonSqueezy::File.retrieve id: 123
301
302
 
302
303
  ```ruby
303
304
  # Retrieves a list of Checkouts
304
- LemonSqeezy::Checkout.list
305
+ LemonSqueezy::Checkout.list
305
306
 
306
307
  # Retrieves a list of Checkouts for a store
307
- LemonSqeezy::Checkout.list store_id: 123
308
+ LemonSqueezy::Checkout.list store_id: 123
308
309
 
309
310
  # Retrieves a list of Checkouts for a variant
310
- LemonSqeezy::Checkout.list variant_id: 123
311
+ LemonSqueezy::Checkout.list variant_id: 123
311
312
 
312
313
  # Retrieves a Checkout
313
- LemonSqeezy::Checkout.retrieve id: 123
314
+ LemonSqueezy::Checkout.retrieve id: 123
314
315
 
315
316
  # Creates a Checkout
316
317
  # View docs for more info: https://docs.lemonsqueezy.com/api/checkouts#create-a-checkout
@@ -343,6 +344,25 @@ LemonSqueezy::Webhook.update id: 123, events: ["order_created", "subscription_cr
343
344
  LemonSqueezy::Webhook.delete id: 123
344
345
  ```
345
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
+ ```
346
366
 
347
367
  ## Contributing
348
368
 
@@ -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
- end
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
@@ -3,9 +3,10 @@
3
3
  module LemonSqueezy
4
4
  class Configuration
5
5
 
6
- attr_accessor :api_key
6
+ attr_accessor :api_key, :default_page_size
7
7
 
8
8
  def initialize
9
+ @default_page_size = 10
9
10
  end
10
11
 
11
12
  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: {filter: 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: {filter: 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: {filter: 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: {filter: 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: {filter: 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: {filter: 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: {filter: 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: {filter: 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: {filter: 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: {filter: 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: {filter: 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
 
@@ -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: {filter: 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: {filter: 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: {filter: 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: {filter: 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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LemonSqueezy
4
- VERSION = "1.0.1"
4
+ VERSION = "1.1.0"
5
5
  end
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.0.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: 2024-01-27 00:00:00.000000000 Z
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.4.22
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: []