patreon 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +36 -0
- data/lib/patreon/api.rb +28 -0
- data/lib/patreon/oauth.rb +3 -0
- data/patreon.gemspec +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66814c53f7b8f73796f894899354ca35139cd6ff
|
4
|
+
data.tar.gz: cb2c1ccd75769b0f2e7fdce7facad8141910346f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7e9fc6e8d9c63e1d8f98abac0bd31a8c43b2c6459e4c1fac24c659759793bda064bbb6fe02b87b2b8d8949de9bd91460075aed3404ff0a8fdd28c97820ab7b4
|
7
|
+
data.tar.gz: 31a5e025feb858f5a4aa507e16dc12745c4596ba35be067cd186b47043beb90194b724185735cb487ab27555201223bceb3521feeea8612cee16a52b43cbd173
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# patreon-ruby
|
2
|
+
Interact with the Patreon API via OAuth
|
3
|
+
|
4
|
+
Step 1. Get your client_id and client_secret
|
5
|
+
---
|
6
|
+
Visit the [OAuth Documentation Page](patreon.com/oauth2/documentation)
|
7
|
+
while logged in as a Patreon creator to register your client.
|
8
|
+
|
9
|
+
This will provide you with a `client_id` and a `client_secret`.
|
10
|
+
|
11
|
+
Step 2. Use this library
|
12
|
+
---
|
13
|
+
e.g., in a Rails route
|
14
|
+
```ruby
|
15
|
+
require 'patreon'
|
16
|
+
|
17
|
+
class OAuthController < ApplicationController
|
18
|
+
def redirect
|
19
|
+
oauth_client = Patreon::OAuth.new(client_id, client_secret)
|
20
|
+
tokens = oauth_client.get_tokens(params[:code], redirect_uri)
|
21
|
+
access_token = tokens['access_token']
|
22
|
+
|
23
|
+
api_client = Patreon::API.new(access_token)
|
24
|
+
user_response = api_client.fetch_user()
|
25
|
+
@user = user_response['data']
|
26
|
+
included = user_response['included']
|
27
|
+
if included
|
28
|
+
@pledge = included.find {|obj| obj['type'] == 'pledge' && obj['relationships']['creator']['data']['id'] == creator_id}
|
29
|
+
@campaign = included.find {|obj| obj['type'] == 'campaign' && obj['relationships']['creator']['data']['id'] == creator_id}
|
30
|
+
else
|
31
|
+
@pledge = nil
|
32
|
+
@campaign = nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
```
|
data/lib/patreon/api.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Patreon
|
5
|
+
class API
|
6
|
+
def initialize(access_token)
|
7
|
+
@access_token = access_token
|
8
|
+
end
|
9
|
+
|
10
|
+
def fetch_user
|
11
|
+
get_json('current_user')
|
12
|
+
end
|
13
|
+
|
14
|
+
def fetch_campaign_and_patrons(access_token)
|
15
|
+
get_json('current_user/campaign')
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def get_json(suffix)
|
21
|
+
url = URI.parse("https://api.patreon.com/oauth2/api/#{suffix}")
|
22
|
+
req = Net::HTTP::Get.new(url.to_s)
|
23
|
+
req['Authorization'] = "Bearer #{@access_token}"
|
24
|
+
res = Net::HTTP.start(url.host, url.port, :use_ssl => true) {|http| http.request(req)}
|
25
|
+
JSON.parse(res.body)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/patreon/oauth.rb
CHANGED
data/patreon.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "patreon"
|
7
|
-
gem.version = "0.0.
|
7
|
+
gem.version = "0.0.3"
|
8
8
|
gem.authors = ["David Kettler"]
|
9
9
|
gem.email = ["david@patreon.com"]
|
10
10
|
gem.description = "Interact with the Patreon API via OAuth"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: patreon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Kettler
|
@@ -18,7 +18,9 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- ".gitignore"
|
21
|
+
- README.md
|
21
22
|
- lib/patreon.rb
|
23
|
+
- lib/patreon/api.rb
|
22
24
|
- lib/patreon/oauth.rb
|
23
25
|
- patreon.gemspec
|
24
26
|
homepage: https://github.com/Patreon/patreon-ruby
|