lemonsqueezy 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6caa3dd3252a4d5e97ccffa65a6cbdc82afb275d58591904ed4ca575e5254cf7
4
- data.tar.gz: 2e3881b8b63e63525dda7839b714740c70565282a3552e955b2e7c0295a74a17
3
+ metadata.gz: 212848d967c94034b1431c5f0969024c24e682f5f7ffc25b8318e3d0fd95de39
4
+ data.tar.gz: 20e52e92dc7182cb909ece3311392207ab8f6e25ec5c8b7e2d1b9aac71ff6a55
5
5
  SHA512:
6
- metadata.gz: e6e61129aa111dea54a26a2ac0915fce6ea1217d3bfaed1afbd0e432297496081f1d046a4fef554515d1cb9e81a35571c792cf4d674ef97bc7aa44960275ab56
7
- data.tar.gz: b86eaa0cb92691704d289ac7785003937e77b3dec5679a5c986f9fc889f94a267633924bcbbb2406f5fe0b94ea537ec80c1c3fb863ff950a9c654644922aae4a
6
+ metadata.gz: ada432d9f5a82a7de4be6f60d1909d5119915cb53cfbd083555cbe86690e3616acbcbe8cdac5ac680a7c690dd3cedd91284295b7b66ff94f4aeafae4f8924295
7
+ data.tar.gz: a4398fc57cc7a0a71b5d6912dadc2f6335869f2014177445f5ebf30a28cca063edb75d31deb97a48b0032c48b71fbba6a99b7ef6d0f3b42f5be62af6bbcb04c8
data/Gemfile.lock CHANGED
@@ -1,17 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lemonsqueezy (0.1.1)
4
+ lemonsqueezy (0.2.0)
5
5
  faraday (~> 2.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  dotenv (2.7.6)
11
- faraday (2.6.0)
11
+ faraday (2.7.4)
12
12
  faraday-net_http (>= 2.0, < 3.1)
13
13
  ruby2_keywords (>= 0.0.4)
14
- faraday-net_http (3.0.1)
14
+ faraday-net_http (3.0.2)
15
15
  minitest (5.15.0)
16
16
  rake (13.0.6)
17
17
  ruby2_keywords (0.0.5)
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # LemonSqueezy
2
2
 
3
+ **This Library is a work in progress**
4
+
3
5
  This is a Ruby library for interacting with the Lemon Squeezy API.
4
6
 
5
7
  ## Installation
@@ -14,8 +16,7 @@ gem "lemonsqueezy"
14
16
 
15
17
  ### Set Access Token
16
18
 
17
- Firstly you'll need to create an API Access Token on your
18
- [settings page](https://app.lemonsqueezy.com/settings/api)
19
+ Firstly you'll need to create an API Access Token on your [settings page](https://app.lemonsqueezy.com/settings/api).
19
20
 
20
21
  ```ruby
21
22
  @client = LemonSqueezy::Client.new(access_token: "")
@@ -28,9 +29,182 @@ Firstly you'll need to create an API Access Token on your
28
29
  @client.stores.list
29
30
 
30
31
  # Retrieves a Store
31
- @client.stores.get(id: "123")
32
+ @client.stores.get id: "123"
33
+ ```
34
+
35
+ ### Products
36
+
37
+ ```ruby
38
+ # Retrieves a list of Products
39
+ @client.products.list
40
+
41
+ # Retrieves a list of Products for a specified Store
42
+ @client.products.list store_id: 123
43
+
44
+ # Retrieves a Product
45
+ @client.products.get id: "123"
46
+ ```
47
+
48
+ ### Product Variants
49
+
50
+ ```ruby
51
+ # Retrieves a list of Variants
52
+ @client.variants.list
53
+
54
+ # Retrieves a list of Variants for a Product
55
+ @client.variants.list product_id: 123
56
+
57
+ # Retrieves a Variant
58
+ @client.variants.get id: "123"
59
+ ```
60
+
61
+ ### Orders
62
+
63
+ ```ruby
64
+ # Retrieves a list of Orders
65
+ @client.orders.list
66
+
67
+ # Retrieves a list of Orders for a specified store
68
+ @client.orders.list product_id: 123
69
+
70
+ # Retrieves a list of Orders for an email address
71
+ @client.orders.list email: "hello@test.com"
72
+
73
+ # Retrieves an Order
74
+ @client.orders.get id: "123"
75
+
76
+ # Retrieves the items on an Order
77
+ @client.orders.get order_items: "123"
78
+ ```
79
+
80
+ ### Subscriptions
81
+
82
+ ```ruby
83
+ # Retrieves a list of Subscriptions
84
+ @client.subscriptions.list
85
+
86
+ # Retrieves a list of Subscriptions for a store
87
+ @client.subscriptions.list store_id: 123
88
+
89
+ # Retrieves a list of Subscriptions for an Order
90
+ @client.subscriptions.list order_id: 123
91
+
92
+ # Retrieves a list of Subscriptions for a product
93
+ @client.subscriptions.list product_id: 123
94
+
95
+ # Retrieves a Subscription
96
+ @client.subscriptions.get id: 123
97
+
98
+ # Pauses a Subscription
99
+ # Kind should be void or free
100
+ # resumes_at can be nil or an ISO-8601 formatted date-time string indicating
101
+ # when the subscription will continue collecting payments.
102
+ @client.subscriptions.pause id: 123, kind: "void", resumes_at: nil
103
+
104
+ # Un-Pause a Subscription
105
+ @client.subscriptions.unpause id: 123
106
+
107
+ # Cancel a Subscription
108
+ @client.subscriptions.cancel id: 123
109
+
110
+ # Un-Cancel a Subscription
111
+ @client.subscriptions.uncancel id: 123
112
+
113
+ # Change the Plan for a Subscription
114
+ @client.subscriptions.change_plan id: 123, plan_id: 111, variant_id: 111
115
+ ```
116
+
117
+ ### Discounts
118
+
119
+ ```ruby
120
+ # Retrieves a list of Discounts
121
+ @client.discounts.list
122
+
123
+ # Retrieves a list of Discounts for a store
124
+ @client.discounts.list store_id: 123
125
+
126
+ # Retrieves a Discount
127
+ @client.discounts.get id: "123"
128
+ ```
129
+
130
+ ### License Keys
131
+
132
+ ```ruby
133
+ # Retrieves a list of License Keys
134
+ @client.license_keys.list
135
+
136
+ # Retrieves a list of License Keys for a store
137
+ @client.license_keys.list store_id: 123
138
+
139
+ # Retrieves a list of License Keys for an order
140
+ @client.license_keys.list order_id: 123
141
+
142
+ # Retrieves a Discount
143
+ @client.license_keys.get id: "123"
32
144
  ```
33
145
 
146
+ ### Files
147
+
148
+ ```ruby
149
+ # Retrieves a list of Files
150
+ @client.files.list
151
+
152
+ # Retrieves a File
153
+ @client.files.get id: "123"
154
+ ```
155
+
156
+ ### Customers
157
+
158
+ ```ruby
159
+ # Retrieves a list of Customers
160
+ @client.customers.list
161
+
162
+ # Retrieves a list of Customers for a store
163
+ @client.customers.list store_id: 123
164
+
165
+ # Retrieves a list of Customers that contain the supplied email
166
+ @client.customers.list email: "test@hello.com"
167
+
168
+ # Retrieves a Customer
169
+ @client.customers.get id: "123"
170
+ ```
171
+
172
+ ### License Key Instances
173
+
174
+ ```ruby
175
+ # Retrieves a list of License Key Instances
176
+ @client.license_key_instances.list
177
+
178
+ # Retrieves a list of License Key Instances for a license key
179
+ @client.license_key_instances.list license_key_id: 123
180
+
181
+ # Retrieves a License Key Instance
182
+ @client.license_key_instances.get id: "123"
183
+ ```
184
+
185
+ ### Checkouts
186
+
187
+ ```ruby
188
+ # Retrieves a list of Checkouts
189
+ @client.checkouts.list
190
+
191
+ # Retrieves a list of Checkouts for a store
192
+ @client.checkouts.list store_id: 123
193
+
194
+ # Retrieves a list of Checkouts for a variant
195
+ @client.checkouts.list variant_id: 123
196
+
197
+ # Retrieves a Checkout
198
+ @client.checkouts.get id: "123"
199
+
200
+ # Creates a Checkout
201
+ # View docs for more info: https://docs.lemonsqueezy.com/api/checkouts#create-a-checkout
202
+ # store_id and variant_id are required
203
+ # Any other parameters are send as "attributes" to the API
204
+ @client.checkouts.create store_id: 123, variant_id: 321, custom_price: 500, product_options: {name: "a test name"}
205
+ ```
206
+
207
+
34
208
  ## Contributing
35
209
 
36
210
  Bug reports and pull requests are welcome on GitHub at https://github.com/deanpcmad/lemonsqueezy.
@@ -44,13 +44,29 @@ module LemonSqueezy
44
44
  FilesResource.new(self)
45
45
  end
46
46
 
47
+ def customers
48
+ CustomersResource.new(self)
49
+ end
50
+
51
+ def license_key_instances
52
+ LicenseKeyInstancesResource.new(self)
53
+ end
54
+
55
+ def checkouts
56
+ CheckoutsResource.new(self)
57
+ end
58
+
47
59
  def connection
48
60
  @connection ||= Faraday.new(BASE_URL) do |conn|
49
61
  conn.request :authorization, :Bearer, access_token
50
62
 
51
- conn.request :json
63
+ conn.headers = {
64
+ "Accept" => "application/vnd.api+json",
65
+ "Content-Type" => "application/vnd.api+json"
66
+ }
52
67
 
53
- conn.response :json, content_type: "application/vnd.api+json"
68
+ conn.request :json
69
+ conn.response :json
54
70
 
55
71
  conn.adapter adapter, @stubs
56
72
  end
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,12 @@
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
@@ -31,7 +31,7 @@ module LemonSqueezy
31
31
  def handle_response(response)
32
32
  case response.status
33
33
  when 400
34
- raise Error, "Error 400: Your request was malformed. '#{response.body["message"]}'"
34
+ raise Error, "Error 400: Your request was malformed. '#{response.body["errors"][0]["detail"]}'"
35
35
  when 401
36
36
  raise Error, "Error 401: You did not supply valid authentication credentials. '#{response.body["error"]}'"
37
37
  when 403
@@ -0,0 +1,42 @@
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
@@ -0,0 +1,15 @@
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
@@ -0,0 +1,15 @@
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
@@ -11,5 +11,82 @@ module LemonSqueezy
11
11
  Subscription.new(response.body["data"]) if response.success?
12
12
  end
13
13
 
14
+ # Kind: void or free
15
+ def pause(id:, kind:, resumes_at: nil)
16
+ body = {
17
+ data: {
18
+ type: "subscriptions",
19
+ id: id.to_s,
20
+ attributes: {
21
+ pause: {mode: kind, resumes_at: resumes_at}
22
+ }
23
+ }
24
+ }
25
+
26
+ response = patch_request("subscriptions/#{id}", body: body.to_json)
27
+ Subscription.new(response.body["data"]) if response.success?
28
+ end
29
+
30
+ def unpause(id:)
31
+ body = {
32
+ data: {
33
+ type: "subscriptions",
34
+ id: id.to_s,
35
+ attributes: {
36
+ pause: nil
37
+ }
38
+ }
39
+ }
40
+
41
+ response = patch_request("subscriptions/#{id}", body: body.to_json)
42
+ Subscription.new(response.body["data"]) if response.success?
43
+ end
44
+
45
+ def cancel(id:)
46
+ body = {
47
+ data: {
48
+ type: "subscriptions",
49
+ id: id.to_s,
50
+ attributes: {
51
+ cancelled: true
52
+ }
53
+ }
54
+ }
55
+
56
+ response = patch_request("subscriptions/#{id}", body: body.to_json)
57
+ Subscription.new(response.body["data"]) if response.success?
58
+ end
59
+
60
+ def uncancel(id:)
61
+ body = {
62
+ data: {
63
+ type: "subscriptions",
64
+ id: id.to_s,
65
+ attributes: {
66
+ cancelled: false
67
+ }
68
+ }
69
+ }
70
+
71
+ response = patch_request("subscriptions/#{id}", body: body.to_json)
72
+ Subscription.new(response.body["data"]) if response.success?
73
+ end
74
+
75
+ def change_plan(id:, plan_id:, variant_id:)
76
+ body = {
77
+ data: {
78
+ type: "subscriptions",
79
+ id: id.to_s,
80
+ attributes: {
81
+ product_id: plan_id,
82
+ variant_id: variant_id
83
+ }
84
+ }
85
+ }
86
+
87
+ response = patch_request("subscriptions/#{id}", body: body.to_json)
88
+ Subscription.new(response.body["data"]) if response.success?
89
+ end
90
+
14
91
  end
15
92
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LemonSqueezy
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/lemon_squeezy.rb CHANGED
@@ -19,7 +19,10 @@ module LemonSqueezy
19
19
  autoload :SubscriptionsResource, "lemon_squeezy/resources/subscriptions"
20
20
  autoload :DiscountsResource, "lemon_squeezy/resources/discounts"
21
21
  autoload :LicenseKeysResource, "lemon_squeezy/resources/license_keys"
22
+ autoload :LicenseKeyInstancesResource, "lemon_squeezy/resources/license_key_instances"
22
23
  autoload :FilesResource, "lemon_squeezy/resources/files"
24
+ autoload :CustomersResource, "lemon_squeezy/resources/customers"
25
+ autoload :CheckoutsResource, "lemon_squeezy/resources/checkouts"
23
26
 
24
27
  autoload :Store, "lemon_squeezy/objects/store"
25
28
  autoload :Product, "lemon_squeezy/objects/product"
@@ -29,6 +32,9 @@ module LemonSqueezy
29
32
  autoload :Subscription, "lemon_squeezy/objects/subscription"
30
33
  autoload :Discount, "lemon_squeezy/objects/discount"
31
34
  autoload :LicenseKey, "lemon_squeezy/objects/license_key"
35
+ autoload :LicenseKeyInstance, "lemon_squeezy/objects/license_key_instance"
32
36
  autoload :File, "lemon_squeezy/objects/file"
37
+ autoload :Customer, "lemon_squeezy/objects/customer"
38
+ autoload :Checkout, "lemon_squeezy/objects/checkout"
33
39
 
34
40
  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.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Perry
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-11 00:00:00.000000000 Z
11
+ date: 2023-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -44,17 +44,24 @@ files:
44
44
  - lib/lemon_squeezy/collection.rb
45
45
  - lib/lemon_squeezy/error.rb
46
46
  - lib/lemon_squeezy/object.rb
47
+ - lib/lemon_squeezy/objects/checkout.rb
48
+ - lib/lemon_squeezy/objects/customer.rb
47
49
  - lib/lemon_squeezy/objects/discount.rb
48
50
  - lib/lemon_squeezy/objects/file.rb
49
51
  - lib/lemon_squeezy/objects/license_key.rb
52
+ - lib/lemon_squeezy/objects/license_key_instance.rb
50
53
  - lib/lemon_squeezy/objects/order.rb
51
54
  - lib/lemon_squeezy/objects/order_item.rb
52
55
  - lib/lemon_squeezy/objects/product.rb
53
56
  - lib/lemon_squeezy/objects/store.rb
54
57
  - lib/lemon_squeezy/objects/subscription.rb
58
+ - lib/lemon_squeezy/objects/variant.rb
55
59
  - lib/lemon_squeezy/resource.rb
60
+ - lib/lemon_squeezy/resources/checkouts.rb
61
+ - lib/lemon_squeezy/resources/customers.rb
56
62
  - lib/lemon_squeezy/resources/discounts.rb
57
63
  - lib/lemon_squeezy/resources/files.rb
64
+ - lib/lemon_squeezy/resources/license_key_instances.rb
58
65
  - lib/lemon_squeezy/resources/license_keys.rb
59
66
  - lib/lemon_squeezy/resources/orders.rb
60
67
  - lib/lemon_squeezy/resources/products.rb
@@ -83,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
90
  - !ruby/object:Gem::Version
84
91
  version: '0'
85
92
  requirements: []
86
- rubygems_version: 3.3.7
93
+ rubygems_version: 3.4.5
87
94
  signing_key:
88
95
  specification_version: 4
89
96
  summary: Ruby library for interacting with the Lemon Squeezy API