lemonsqueezy 0.1.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +177 -3
- data/lib/lemon_squeezy/client.rb +14 -1
- data/lib/lemon_squeezy/objects/checkout.rb +12 -0
- data/lib/lemon_squeezy/objects/customer.rb +12 -0
- data/lib/lemon_squeezy/objects/license_key_instance.rb +12 -0
- data/lib/lemon_squeezy/objects/variant.rb +12 -0
- data/lib/lemon_squeezy/resources/checkouts.rb +42 -0
- data/lib/lemon_squeezy/resources/customers.rb +15 -0
- data/lib/lemon_squeezy/resources/license_key_instances.rb +15 -0
- data/lib/lemon_squeezy/version.rb +1 -1
- data/lib/lemon_squeezy.rb +6 -0
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca29faa717ccfdc417a761a105fa39b1a3ee8ca7d61f03b1ac9b83f1f2a0785a
|
4
|
+
data.tar.gz: 1480cfb125ae58d1295bdb0aca4603ca8440309314079b23b96dd79fd6162623
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26e001c1de7c812783602d68d821999e874cbf46301810883e953773f4b4418103b8beede64158fd3e521cea0eb9d0101bc8339657211389daa913f3b7d93337
|
7
|
+
data.tar.gz: 00faf6c801928c90bcbbf6e6c21c35960a1f323d50b8494d789c0adead95ef1434e533458436f13fa7dfa5c1cdf7bb74efa52a1cfbc9c4d60dfc94ae60421e6a
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lemonsqueezy (0.1
|
4
|
+
lemonsqueezy (0.2.1)
|
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.7.
|
11
|
+
faraday (2.7.4)
|
12
12
|
faraday-net_http (>= 2.0, < 3.1)
|
13
13
|
ruby2_keywords (>= 0.0.4)
|
14
14
|
faraday-net_http (3.0.2)
|
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
|
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.
|
data/lib/lemon_squeezy/client.rb
CHANGED
@@ -44,13 +44,26 @@ 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
63
|
conn.headers = {
|
64
|
+
"User-Agent" => "lemonsqueezy/v#{VERSION} (github.com/deanpcmad/lemonsqueezy)",
|
52
65
|
"Accept" => "application/vnd.api+json",
|
53
|
-
"Content-Type" => "application/vnd.api+json"
|
66
|
+
"Content-Type" => "application/vnd.api+json",
|
54
67
|
}
|
55
68
|
|
56
69
|
conn.request :json
|
@@ -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
|
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
|
4
|
+
version: 0.2.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-
|
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.
|
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
|