Module: Redd::Client::OAuth2::Authorization
- Included in:
- Redd::Client::OAuth2
- Defined in:
- lib/redd/client/oauth2/authorization.rb
Instance Method Summary collapse
- #auth_url(scope = ["identity"], duration = "temporary", state = "x") ⇒ Object
- #refresh_access_token(access = nil, set_access = true) ⇒ Object
- #request_access_token(code, set_access = true) ⇒ Object
Instance Method Details
#auth_url(scope = ["identity"], duration = "temporary", state = "x") ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/redd/client/oauth2/authorization.rb', line 7 def auth_url(scope = ["identity"], duration = "temporary", state = "x") path = "https://ssl.reddit.com/api/v1/authorize" query = { client_id: @client_id, redirect_uri: @redirect_uri, response_type: "code", state: state, scope: scope.join(","), duration: duration } string_query = query.map { |key, value| "#{key}=#{value}" }.join("&") "#{path}?#{string_query}" end |
#refresh_access_token(access = nil, set_access = true) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/redd/client/oauth2/authorization.rb', line 32 def refresh_access_token(access = nil, set_access = true) refresh_token = extract_attribute(access, :refresh_token) response = auth_connection.post "/api/v1/access_token", grant_type: "refresh_token", refresh_token: refresh_token case access when Redd::OAuth2Access access.refresh(response.body) when ::String new_access = Redd::OAuth2Access.new(response.body) @access = new_access if set_access new_access end end |
#request_access_token(code, set_access = true) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/redd/client/oauth2/authorization.rb', line 22 def request_access_token(code, set_access = true) response = auth_connection.post "/api/v1/access_token", grant_type: "authorization_code", code: code, redirect_uri: @redirect_uri access = Redd::OAuth2Access.new(response.body) @access = access if set_access access end |