peasy 0.1.0 → 0.2.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: 3a9b69951d0814fb7608a77fee8bae0cd9949355459cb1b0eeabffc1eeba58bb
4
- data.tar.gz: 2bf6ce4951bc1e2664a4c608104fa3c1c4c37b9e69ab78a1aa49f5433508245f
3
+ metadata.gz: 2b58794b72afbfa61ea1fcc6f12a294a5a1dcbbfd150c837bbb37b9fda6be0e4
4
+ data.tar.gz: ef94499dd0dc891bdb91fc984dc6c434c0ba02827438b8335d22cf6197f9e510
5
5
  SHA512:
6
- metadata.gz: 30f1f8a38b633d139367c14ac3484079136d0cffa313f4816b4013ea6560a0158c10f4cc9d6864faa29071acc17cfc8c40af2986a1fd6e605e2205f770342878
7
- data.tar.gz: 8abb797d706b00d5f8668fcd989eb0d4b80e87dee4271b8bf16b479b7377c8999a9d2f898ca2480a02f4ba63db055a9402b53b2743e5c39d8d50d50196d75979
6
+ metadata.gz: 8b776ce0ee0f8827c4434bc12f31b4cd8d9b3e3e79431e0325c788af7e0c21bd7fbb98ee9e7bd717e4e78dcbd49a08de9ef78bd9a3f3949b0eb0872cc8f303a5
7
+ data.tar.gz: cc37ee5214382c6fcdf117090bfdd95bb228349c9c7edda6d3eb45f1e93c6ba76c65987e44db3d46bf3138b664d3606e053f9fb3618f9d133ee5991a078ead84
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Peasy
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/peasy`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ An Easy Peasy way to use LemonSqueezy.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ This gem lets you use the LemonSqueezy API to manage subscriptions from your application.
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,17 +22,27 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ This is super basic, and there are currently no tests. Probably don't use in production unless you know what the code does.
26
26
 
27
- ## Development
27
+ ### Get Subscription
28
28
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+ 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
30
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31
+ ```
32
+ Peasy::Subscription.find(API_KEY, SUBSCRIPTION_ID)
33
+ ```
34
+
35
+ ### Cancel Subscription
36
+
37
+ As above, if you know the subscription ID from LemonSqueezy, you can instruct the API to cancel the relevant subscription.
38
+
39
+ ```
40
+ Peasy::Subscription.cancel(API_KEY, SUBSCRIPTION_ID)
41
+ ```
32
42
 
33
- ## Contributing
43
+ ## To Do
34
44
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/peasy.
45
+ 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
46
 
37
47
  ## License
38
48
 
@@ -14,7 +14,27 @@ module Peasy
14
14
  request['Authorization'] = "Bearer #{key}"
15
15
 
16
16
  response = http.request(request)
17
+ response = JSON.parse(response.body)
17
18
 
18
19
  end
20
+
21
+ def self.cancel(key, id)
22
+ require 'net/http'
23
+
24
+ uri = URI.parse("https://api.lemonsqueezy.com/v1/subscriptions/#{id}")
25
+
26
+ http = Net::HTTP.new(uri.host, uri.port)
27
+ http.use_ssl = true if uri.instance_of? URI::HTTPS
28
+
29
+ request = Net::HTTP::Patch.new(uri.request_uri)
30
+ request['Content-Type'] = 'application/vnd.api+json'
31
+ request['Accept'] = 'application/vnd.api+json'
32
+ request['Authorization'] = "Bearer #{key}"
33
+ request.body = {data: {type: "subscriptions", id: "#{id}", attributes: {cancelled: true}}}.to_json
34
+
35
+ response = http.request(request)
36
+ response = JSON.parse(response.body)
37
+
38
+ end
19
39
  end
20
40
  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.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/peasy-0.1.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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Farnworth
@@ -30,6 +30,7 @@ files:
30
30
  - lib/peasy.rb
31
31
  - lib/peasy/subscription.rb
32
32
  - lib/peasy/version.rb
33
+ - peasy-0.1.0.gem
33
34
  - peasy.gemspec
34
35
  homepage: https://github.com/stevefarnworth/peasy
35
36
  licenses: