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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6caa3dd3252a4d5e97ccffa65a6cbdc82afb275d58591904ed4ca575e5254cf7
4
- data.tar.gz: 2e3881b8b63e63525dda7839b714740c70565282a3552e955b2e7c0295a74a17
3
+ metadata.gz: 2ac9b6665a6a4c67527e1852e3373dc9ed98b81b4cf9d0c5895b45d030f581d3
4
+ data.tar.gz: c8d7d01cdd86284c2cf7d7eadf66ed2cd4b8f41efa5ccc6c338281d4385254cc
5
5
  SHA512:
6
- metadata.gz: e6e61129aa111dea54a26a2ac0915fce6ea1217d3bfaed1afbd0e432297496081f1d046a4fef554515d1cb9e81a35571c792cf4d674ef97bc7aa44960275ab56
7
- data.tar.gz: b86eaa0cb92691704d289ac7785003937e77b3dec5679a5c986f9fc889f94a267633924bcbbb2406f5fe0b94ea537ec80c1c3fb863ff950a9c654644922aae4a
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.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.6.0)
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.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)
@@ -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.request :json
51
+ conn.headers = {
52
+ "Accept" => "application/vnd.api+json",
53
+ "Content-Type" => "application/vnd.api+json"
54
+ }
52
55
 
53
- conn.response :json, content_type: "application/vnd.api+json"
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["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
@@ -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.1.2"
5
5
  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.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: 2022-10-11 00:00:00.000000000 Z
11
+ date: 2023-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday