peasy 0.2.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 +10 -0
- data/lib/peasy/configuration.rb +5 -0
- data/lib/peasy/subscription.rb +14 -5
- data/lib/peasy/version.rb +1 -1
- data/lib/peasy.rb +7 -2
- data/peasy-0.2.0.gem +0 -0
- metadata +3 -2
- data/peasy-0.1.0.gem +0 -0
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,4 +1,5 @@
|
|
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
|
|
@@ -24,6 +25,15 @@ Or install it yourself as:
|
|
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
|
|
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.
|
30
|
+
|
31
|
+
```
|
32
|
+
Peasy.configure do |config|
|
33
|
+
config.key = Rails.application.credentials.lemonsqueezy_api_key
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
27
37
|
### Get Subscription
|
28
38
|
|
29
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.
|
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,14 +16,18 @@ 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)
|
17
22
|
response = JSON.parse(response.body)
|
18
23
|
|
19
24
|
end
|
20
25
|
|
21
|
-
def self.
|
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)
|
22
31
|
require 'net/http'
|
23
32
|
|
24
33
|
uri = URI.parse("https://api.lemonsqueezy.com/v1/subscriptions/#{id}")
|
@@ -29,12 +38,12 @@ module Peasy
|
|
29
38
|
request = Net::HTTP::Patch.new(uri.request_uri)
|
30
39
|
request['Content-Type'] = 'application/vnd.api+json'
|
31
40
|
request['Accept'] = 'application/vnd.api+json'
|
32
|
-
request['Authorization'] = "Bearer #{key}"
|
41
|
+
request['Authorization'] = "Bearer #{Peasy.configuration.key}"
|
33
42
|
request.body = {data: {type: "subscriptions", id: "#{id}", attributes: {cancelled: true}}}.to_json
|
34
43
|
|
35
44
|
response = http.request(request)
|
36
45
|
response = JSON.parse(response.body)
|
37
|
-
|
46
|
+
|
38
47
|
end
|
39
48
|
end
|
40
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,9 +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
|
33
|
-
- peasy-0.
|
34
|
+
- peasy-0.2.0.gem
|
34
35
|
- peasy.gemspec
|
35
36
|
homepage: https://github.com/stevefarnworth/peasy
|
36
37
|
licenses:
|
data/peasy-0.1.0.gem
DELETED
Binary file
|