lemonsqueezy 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/lib/lemon_squeezy/client.rb +6 -2
- data/lib/lemon_squeezy/resource.rb +1 -1
- data/lib/lemon_squeezy/resources/subscriptions.rb +77 -0
- data/lib/lemon_squeezy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ac9b6665a6a4c67527e1852e3373dc9ed98b81b4cf9d0c5895b45d030f581d3
|
4
|
+
data.tar.gz: c8d7d01cdd86284c2cf7d7eadf66ed2cd4b8f41efa5ccc6c338281d4385254cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b5150c7ec8b7cd4a32236895a2e9e74100e3dac3fb2f9edc3fc57df0c30df5c32c59589f95d0cab3d0e44164307e99c9bf6264b8942bbce15d71233a03c07f3
|
7
|
+
data.tar.gz: c7ecc80114437ec3355a5709604fede1e1b43f6209a200749936e7a3a742a616530389959ac5fb95f125589652b797cb7ac7f45f5fa3b36931b6d9fea34ae16d
|
data/Gemfile.lock
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lemonsqueezy (0.1.
|
4
|
+
lemonsqueezy (0.1.2)
|
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.
|
11
|
+
faraday (2.7.2)
|
12
12
|
faraday-net_http (>= 2.0, < 3.1)
|
13
13
|
ruby2_keywords (>= 0.0.4)
|
14
|
-
faraday-net_http (3.0.
|
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/lib/lemon_squeezy/client.rb
CHANGED
@@ -48,9 +48,13 @@ module LemonSqueezy
|
|
48
48
|
@connection ||= Faraday.new(BASE_URL) do |conn|
|
49
49
|
conn.request :authorization, :Bearer, access_token
|
50
50
|
|
51
|
-
conn.
|
51
|
+
conn.headers = {
|
52
|
+
"Accept" => "application/vnd.api+json",
|
53
|
+
"Content-Type" => "application/vnd.api+json"
|
54
|
+
}
|
52
55
|
|
53
|
-
conn.
|
56
|
+
conn.request :json
|
57
|
+
conn.response :json
|
54
58
|
|
55
59
|
conn.adapter adapter, @stubs
|
56
60
|
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["
|
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
|
@@ -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
|
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.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dean Perry
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|