class Patreon::OAuth
Public Class Methods
new(client_id, client_secret)
click to toggle source
# File lib/patreon/oauth.rb, line 3 def initialize(client_id, client_secret) @client_id = client_id @client_secret = client_secret end
Public Instance Methods
get_tokens(code, redirect_uri)
click to toggle source
# File lib/patreon/oauth.rb, line 8 def get_tokens(code, redirect_uri) update_token({ "grant_type" => "authorization_code", "code" => code, "client_id" => @client_id, "client_secret" => @client_secret, "redirect_uri" => redirect_uri }) end
refresh_token(refresh_token, redirect_uri)
click to toggle source
# File lib/patreon/oauth.rb, line 18 def refresh_token(refresh_token, redirect_uri) update_token({ "grant_type" => "refresh_token", "refresh_token" => refresh_token, "client_id" => @client_id, "client_secret" => @client_secret }) end
Private Instance Methods
update_token(params)
click to toggle source
# File lib/patreon/oauth.rb, line 29 def update_token(params) url = URI.parse('https://www.patreon.com/api/oauth2/token') url.query = URI.encode_www_form(params) req = Net::HTTP::Post.new(url.to_s) req['User-Agent'] = Utils::Client.user_agent_string res = Net::HTTP.start(url.host, url.port, :use_ssl => true) {|http| http.request(req)} JSON.parse(res.body) end