lemonsqueezy 0.1.0 → 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: 159648c0a2258cb867fc0b4119e816aceccb4584fd45fc690e91b3db2f760865
4
- data.tar.gz: d56a260c987b0039d7a8c6376d8686d1cdb32128b0039f61787644eaa34e9707
3
+ metadata.gz: 2ac9b6665a6a4c67527e1852e3373dc9ed98b81b4cf9d0c5895b45d030f581d3
4
+ data.tar.gz: c8d7d01cdd86284c2cf7d7eadf66ed2cd4b8f41efa5ccc6c338281d4385254cc
5
5
  SHA512:
6
- metadata.gz: 3c8b6936badab690f9e73cf97777074ef32724382135de8699258f9ca87ba3cc5a6f8fef0b385f86645436967ba329ab388d8e9128ad5ec7451073f4187283de
7
- data.tar.gz: 829dd9b1560c6d6a7bb534332ccb4af2ae3c0333e06c4bbed0aee8666bc5139480064c4a8358c5703c385a3e2747cf7085e47f529880d91730dfa7518dce63d0
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.0)
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.5.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.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)
@@ -16,13 +16,45 @@ module LemonSqueezy
16
16
  StoresResource.new(self)
17
17
  end
18
18
 
19
+ def products
20
+ ProductsResource.new(self)
21
+ end
22
+
23
+ def variants
24
+ VariantsResource.new(self)
25
+ end
26
+
27
+ def orders
28
+ OrdersResource.new(self)
29
+ end
30
+
31
+ def subscriptions
32
+ SubscriptionsResource.new(self)
33
+ end
34
+
35
+ def discounts
36
+ DiscountsResource.new(self)
37
+ end
38
+
39
+ def license_keys
40
+ LicenseKeysResource.new(self)
41
+ end
42
+
43
+ def files
44
+ FilesResource.new(self)
45
+ end
46
+
19
47
  def connection
20
48
  @connection ||= Faraday.new(BASE_URL) do |conn|
21
49
  conn.request :authorization, :Bearer, access_token
22
50
 
23
- conn.request :json
51
+ conn.headers = {
52
+ "Accept" => "application/vnd.api+json",
53
+ "Content-Type" => "application/vnd.api+json"
54
+ }
24
55
 
25
- conn.response :json, content_type: "application/vnd.api+json"
56
+ conn.request :json
57
+ conn.response :json
26
58
 
27
59
  conn.adapter adapter, @stubs
28
60
  end
@@ -0,0 +1,12 @@
1
+ module LemonSqueezy
2
+ class Discount < 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 File < 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 LicenseKey < 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 Order < 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 OrderItem < 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 Product < 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 Subscription < 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,15 @@
1
+ module LemonSqueezy
2
+ class DiscountsResource < Resource
3
+
4
+ def list(**params)
5
+ response = get_request("discounts", params: params)
6
+ Collection.from_response(response, type: Discount)
7
+ end
8
+
9
+ def get(id:)
10
+ response = get_request("discounts/#{id}")
11
+ Discount.new(response.body["data"]) if response.success?
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module LemonSqueezy
2
+ class FilesResource < Resource
3
+
4
+ def list(**params)
5
+ response = get_request("files", params: params)
6
+ Collection.from_response(response, type: File)
7
+ end
8
+
9
+ def get(id:)
10
+ response = get_request("files/#{id}")
11
+ File.new(response.body["data"]) if response.success?
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module LemonSqueezy
2
+ class LicenseKeysResource < Resource
3
+
4
+ def list(**params)
5
+ response = get_request("license-keys", params: params)
6
+ Collection.from_response(response, type: LicenseKey)
7
+ end
8
+
9
+ def get(id:)
10
+ response = get_request("license-keys/#{id}")
11
+ LicenseKey.new(response.body["data"]) if response.success?
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ module LemonSqueezy
2
+ class OrdersResource < Resource
3
+
4
+ def list(**params)
5
+ response = get_request("orders", params: params)
6
+ Collection.from_response(response, type: Order)
7
+ end
8
+
9
+ def get(id:)
10
+ response = get_request("orders/#{id}")
11
+ Order.new(response.body["data"]) if response.success?
12
+ end
13
+
14
+ def order_items(id:)
15
+ response = get_request("order-items", params: {order_id: id})
16
+ Collection.from_response(response, type: OrderItem)
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ module LemonSqueezy
2
+ class ProductsResource < Resource
3
+
4
+ def list(**params)
5
+ response = get_request("products", params: params)
6
+ Collection.from_response(response, type: Product)
7
+ end
8
+
9
+ def get(id:)
10
+ response = get_request("products/#{id}")
11
+ Product.new(response.body["data"]) if response.success?
12
+ end
13
+
14
+ end
15
+ end
@@ -3,7 +3,6 @@ module LemonSqueezy
3
3
 
4
4
  def list
5
5
  response = get_request("stores")
6
- # response.body["data"]
7
6
  Collection.from_response(response, type: Store)
8
7
  end
9
8
 
@@ -0,0 +1,92 @@
1
+ module LemonSqueezy
2
+ class SubscriptionsResource < Resource
3
+
4
+ def list(**params)
5
+ response = get_request("subscriptions", params: params)
6
+ Collection.from_response(response, type: Subscription)
7
+ end
8
+
9
+ def get(id:)
10
+ response = get_request("subscriptions/#{id}")
11
+ Subscription.new(response.body["data"]) if response.success?
12
+ end
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
+
91
+ end
92
+ end
@@ -0,0 +1,15 @@
1
+ module LemonSqueezy
2
+ class VariantsResource < Resource
3
+
4
+ def list(**params)
5
+ response = get_request("variants", params: params)
6
+ Collection.from_response(response, type: Variant)
7
+ end
8
+
9
+ def get(id:)
10
+ response = get_request("variants/#{id}")
11
+ Variant.new(response.body["data"]) if response.success?
12
+ end
13
+
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LemonSqueezy
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/lemon_squeezy.rb CHANGED
@@ -13,7 +13,22 @@ module LemonSqueezy
13
13
  autoload :Object, "lemon_squeezy/object"
14
14
 
15
15
  autoload :StoresResource, "lemon_squeezy/resources/stores"
16
+ autoload :ProductsResource, "lemon_squeezy/resources/products"
17
+ autoload :VariantsResource, "lemon_squeezy/resources/variants"
18
+ autoload :OrdersResource, "lemon_squeezy/resources/orders"
19
+ autoload :SubscriptionsResource, "lemon_squeezy/resources/subscriptions"
20
+ autoload :DiscountsResource, "lemon_squeezy/resources/discounts"
21
+ autoload :LicenseKeysResource, "lemon_squeezy/resources/license_keys"
22
+ autoload :FilesResource, "lemon_squeezy/resources/files"
16
23
 
17
24
  autoload :Store, "lemon_squeezy/objects/store"
25
+ autoload :Product, "lemon_squeezy/objects/product"
26
+ autoload :Variant, "lemon_squeezy/objects/variant"
27
+ autoload :Order, "lemon_squeezy/objects/order"
28
+ autoload :OrderItem, "lemon_squeezy/objects/order_item"
29
+ autoload :Subscription, "lemon_squeezy/objects/subscription"
30
+ autoload :Discount, "lemon_squeezy/objects/discount"
31
+ autoload :LicenseKey, "lemon_squeezy/objects/license_key"
32
+ autoload :File, "lemon_squeezy/objects/file"
18
33
 
19
34
  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.0
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-02 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
@@ -44,9 +44,23 @@ 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/discount.rb
48
+ - lib/lemon_squeezy/objects/file.rb
49
+ - lib/lemon_squeezy/objects/license_key.rb
50
+ - lib/lemon_squeezy/objects/order.rb
51
+ - lib/lemon_squeezy/objects/order_item.rb
52
+ - lib/lemon_squeezy/objects/product.rb
47
53
  - lib/lemon_squeezy/objects/store.rb
54
+ - lib/lemon_squeezy/objects/subscription.rb
48
55
  - lib/lemon_squeezy/resource.rb
56
+ - lib/lemon_squeezy/resources/discounts.rb
57
+ - lib/lemon_squeezy/resources/files.rb
58
+ - lib/lemon_squeezy/resources/license_keys.rb
59
+ - lib/lemon_squeezy/resources/orders.rb
60
+ - lib/lemon_squeezy/resources/products.rb
49
61
  - lib/lemon_squeezy/resources/stores.rb
62
+ - lib/lemon_squeezy/resources/subscriptions.rb
63
+ - lib/lemon_squeezy/resources/variants.rb
50
64
  - lib/lemon_squeezy/version.rb
51
65
  - lib/lemonsqueezy.rb
52
66
  homepage: https://github.com/deanpcmad/lemonsqueezy