peasy 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -8
- data/lib/peasy/configuration.rb +5 -0
- data/lib/peasy/subscription.rb +31 -2
- data/lib/peasy/version.rb +1 -1
- data/lib/peasy.rb +7 -2
- data/peasy-0.2.0.gem +0 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50497c8baa8e234e8b5720ccdffd583cf7a9947efdb84d55358dc0a2bfeeedd2
|
4
|
+
data.tar.gz: 931ecbb25fcb358d0e7784dabf75a752b0501a5839ecf70fce5256841519cdda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8b95e344c4b1508a4ab4ba99625159896c49622d9394beea6b5c8973ca0798e6c74aab80aebe949ae9bad786e788be5055bd061c7731910a2aa8237161dd00e
|
7
|
+
data.tar.gz: dbec525bd69d16b78fcd2624bac6f91749b973e8236db5a34cd28b913d6c52b33e77c8cb6d65e90b1095175d3cfd77ada5872fd5d1076de0aaea163dde799c75
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# Peasy
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/peasy.svg)](https://badge.fury.io/rb/peasy)
|
2
3
|
|
3
|
-
|
4
|
+
An Easy Peasy way to use LemonSqueezy.
|
4
5
|
|
5
|
-
|
6
|
+
This gem lets you use the LemonSqueezy API to manage subscriptions from your application.
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -22,17 +23,36 @@ Or install it yourself as:
|
|
22
23
|
|
23
24
|
## Usage
|
24
25
|
|
25
|
-
|
26
|
+
This is super basic, and there are currently no tests. Probably don't use in production unless you know what the code does.
|
26
27
|
|
27
|
-
|
28
|
+
### Create Initializer
|
29
|
+
Add a `peasy.rb` file to your initializers folder, defining your API key. The LemonSqueezy API keys don't always play nice with Rails credentials, so you might need to split if over several lines in your credentials and then gsub the linebreaks.
|
28
30
|
|
29
|
-
|
31
|
+
```
|
32
|
+
Peasy.configure do |config|
|
33
|
+
config.key = Rails.application.credentials.lemonsqueezy_api_key
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
### Get Subscription
|
30
38
|
|
31
|
-
|
39
|
+
If you know the subscription ID from LemonSqueezy (likely you've saved it already to your application's database), you can query the API to get the response.
|
40
|
+
|
41
|
+
```
|
42
|
+
Peasy::Subscription.find(API_KEY, SUBSCRIPTION_ID)
|
43
|
+
```
|
44
|
+
|
45
|
+
### Cancel Subscription
|
46
|
+
|
47
|
+
As above, if you know the subscription ID from LemonSqueezy, you can instruct the API to cancel the relevant subscription.
|
48
|
+
|
49
|
+
```
|
50
|
+
Peasy::Subscription.cancel(API_KEY, SUBSCRIPTION_ID)
|
51
|
+
```
|
32
52
|
|
33
|
-
##
|
53
|
+
## To Do
|
34
54
|
|
35
|
-
|
55
|
+
There's a lot of endpoints left to map here, and there's also going to be some refactoring to do and tests to write
|
36
56
|
|
37
57
|
## License
|
38
58
|
|
data/lib/peasy/subscription.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
module Peasy
|
2
|
+
|
3
|
+
class Configuration
|
4
|
+
attr_accessor :key
|
5
|
+
end
|
6
|
+
|
2
7
|
class Subscription
|
3
|
-
def self.find(
|
8
|
+
def self.find(id)
|
4
9
|
require 'net/http'
|
5
10
|
|
6
11
|
uri = URI.parse("https://api.lemonsqueezy.com/v1/subscriptions/#{id}")
|
@@ -11,10 +16,34 @@ module Peasy
|
|
11
16
|
request = Net::HTTP::Get.new(uri.request_uri)
|
12
17
|
request['Content-Type'] = 'application/vnd.api+json'
|
13
18
|
request['Accept'] = 'application/vnd.api+json'
|
14
|
-
request['Authorization'] = "Bearer #{key}"
|
19
|
+
request['Authorization'] = "Bearer #{Peasy.configuration.key}"
|
15
20
|
|
16
21
|
response = http.request(request)
|
22
|
+
response = JSON.parse(response.body)
|
17
23
|
|
18
24
|
end
|
25
|
+
|
26
|
+
def self.change_payment_method(id)
|
27
|
+
self.find(id)['data']['attributes']['urls']['update_payment_method']
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.cancel(id)
|
31
|
+
require 'net/http'
|
32
|
+
|
33
|
+
uri = URI.parse("https://api.lemonsqueezy.com/v1/subscriptions/#{id}")
|
34
|
+
|
35
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
36
|
+
http.use_ssl = true if uri.instance_of? URI::HTTPS
|
37
|
+
|
38
|
+
request = Net::HTTP::Patch.new(uri.request_uri)
|
39
|
+
request['Content-Type'] = 'application/vnd.api+json'
|
40
|
+
request['Accept'] = 'application/vnd.api+json'
|
41
|
+
request['Authorization'] = "Bearer #{Peasy.configuration.key}"
|
42
|
+
request.body = {data: {type: "subscriptions", id: "#{id}", attributes: {cancelled: true}}}.to_json
|
43
|
+
|
44
|
+
response = http.request(request)
|
45
|
+
response = JSON.parse(response.body)
|
46
|
+
|
47
|
+
end
|
19
48
|
end
|
20
49
|
end
|
data/lib/peasy/version.rb
CHANGED
data/lib/peasy.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "peasy/version"
|
4
|
-
|
4
|
+
require_relative "peasy/configuration"
|
5
5
|
require_relative 'peasy/subscription'
|
6
6
|
|
7
7
|
module Peasy
|
8
8
|
class Error < StandardError; end
|
9
|
-
|
9
|
+
def self.configuration
|
10
|
+
@configuration ||= Configuration.new
|
11
|
+
end
|
12
|
+
def self.configure(&block)
|
13
|
+
yield(configuration)
|
14
|
+
end
|
10
15
|
end
|
data/peasy-0.2.0.gem
ADDED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peasy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Farnworth
|
@@ -28,8 +28,10 @@ files:
|
|
28
28
|
- bin/console
|
29
29
|
- bin/setup
|
30
30
|
- lib/peasy.rb
|
31
|
+
- lib/peasy/configuration.rb
|
31
32
|
- lib/peasy/subscription.rb
|
32
33
|
- lib/peasy/version.rb
|
34
|
+
- peasy-0.2.0.gem
|
33
35
|
- peasy.gemspec
|
34
36
|
homepage: https://github.com/stevefarnworth/peasy
|
35
37
|
licenses:
|