peasy 0.2.0 → 0.4.0

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: 2b58794b72afbfa61ea1fcc6f12a294a5a1dcbbfd150c837bbb37b9fda6be0e4
4
- data.tar.gz: ef94499dd0dc891bdb91fc984dc6c434c0ba02827438b8335d22cf6197f9e510
3
+ metadata.gz: dc1e1e56d157077d7ee435cd09f3501087d43c0b51eade766be0755cd662e77c
4
+ data.tar.gz: e92ee6d439e646629a6f1dff2f66bbebc572dc2776d3d1d50142fb695c8d74f8
5
5
  SHA512:
6
- metadata.gz: 8b776ce0ee0f8827c4434bc12f31b4cd8d9b3e3e79431e0325c788af7e0c21bd7fbb98ee9e7bd717e4e78dcbd49a08de9ef78bd9a3f3949b0eb0872cc8f303a5
7
- data.tar.gz: cc37ee5214382c6fcdf117090bfdd95bb228349c9c7edda6d3eb45f1e93c6ba76c65987e44db3d46bf3138b664d3606e053f9fb3618f9d133ee5991a078ead84
6
+ metadata.gz: 2ce2ade1aff2aafdbae6abe41c05c2f914a996986d1847f2ab144c61e816187daab39bb29a676613e391a1e24963645d914594a6e6ac377d02fc07993e31e240
7
+ data.tar.gz: b29bceec3517c61ac39e3a720369a4ba6c31b5a5c4faf7a59ba74ad1360e6b471d99f07e20b47a4c950327995c05d95c36846619a461766afd80f98b354eed9a
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,12 +25,21 @@ 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.
30
40
 
31
41
  ```
32
- Peasy::Subscription.find(API_KEY, SUBSCRIPTION_ID)
42
+ Peasy::Subscription.find(SUBSCRIPTION_ID)
33
43
  ```
34
44
 
35
45
  ### Cancel Subscription
@@ -37,7 +47,7 @@ Peasy::Subscription.find(API_KEY, SUBSCRIPTION_ID)
37
47
  As above, if you know the subscription ID from LemonSqueezy, you can instruct the API to cancel the relevant subscription.
38
48
 
39
49
  ```
40
- Peasy::Subscription.cancel(API_KEY, SUBSCRIPTION_ID)
50
+ Peasy::Subscription.cancel(SUBSCRIPTION_ID)
41
51
  ```
42
52
 
43
53
  ## To Do
@@ -0,0 +1,5 @@
1
+ module Peasy
2
+ class Configuration
3
+ attr_accessor :key
4
+ end
5
+ end
@@ -1,9 +1,14 @@
1
1
  module Peasy
2
+
3
+ class Configuration
4
+ attr_accessor :key
5
+ end
6
+
2
7
  class Subscription
3
- def self.find(key, id)
8
+ def self.find(id)
4
9
  require 'net/http'
5
10
 
6
- uri = URI.parse("https://api.lemonsqueezy.com/v1/subscriptions/#{id}")
11
+ uri = URI.parse("https://api.lemonsqueezy.com/v1/subscriptions/#{id}?include=order")
7
12
 
8
13
  http = Net::HTTP.new(uri.host, uri.port)
9
14
  http.use_ssl = true if uri.instance_of? URI::HTTPS
@@ -11,14 +16,22 @@ 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.cancel(key, id)
26
+ def self.change_payment_method(id)
27
+ self.find(id)['data']['attributes']['urls']['update_payment_method']
28
+ end
29
+
30
+ def self.renewal_date(id)
31
+ self.find(id)['data']['attributes']['renews_at']
32
+ end
33
+
34
+ def self.cancel(id)
22
35
  require 'net/http'
23
36
 
24
37
  uri = URI.parse("https://api.lemonsqueezy.com/v1/subscriptions/#{id}")
@@ -29,12 +42,12 @@ module Peasy
29
42
  request = Net::HTTP::Patch.new(uri.request_uri)
30
43
  request['Content-Type'] = 'application/vnd.api+json'
31
44
  request['Accept'] = 'application/vnd.api+json'
32
- request['Authorization'] = "Bearer #{key}"
45
+ request['Authorization'] = "Bearer #{Peasy.configuration.key}"
33
46
  request.body = {data: {type: "subscriptions", id: "#{id}", attributes: {cancelled: true}}}.to_json
34
47
 
35
48
  response = http.request(request)
36
49
  response = JSON.parse(response.body)
37
-
50
+
38
51
  end
39
52
  end
40
53
  end
data/lib/peasy/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Peasy
4
- VERSION = "0.2.0"
4
+ VERSION = "0.4.0"
5
5
  end
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
- # Your code goes here...
9
+ def self.configuration
10
+ @configuration ||= Configuration.new
11
+ end
12
+ def self.configure(&block)
13
+ yield(configuration)
14
+ end
10
15
  end
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.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Farnworth
@@ -28,9 +28,9 @@ 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.1.0.gem
34
34
  - peasy.gemspec
35
35
  homepage: https://github.com/stevefarnworth/peasy
36
36
  licenses:
data/peasy-0.1.0.gem DELETED
Binary file