Class: Redd::Clients::Installed
- Defined in:
- lib/redd/clients/installed.rb
Overview
The client for installed apps that can’t keep a secret. It might even work with Rubymotion (fingers crossed).
Constant Summary
Constants included from Base::Utilities
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#redirect_uri ⇒ Object
readonly
Returns the value of attribute redirect_uri.
Attributes inherited from Base
#access, #api_endpoint, #auth_endpoint, #rate_limit, #user_agent
Instance Method Summary collapse
-
#auth_url(state, scope = ['identity'], duration = :temporary) ⇒ String
rubocop:disable Metrics/MethodLength.
-
#authorize!(fragment) ⇒ Access
Authorize using the url fragment.
-
#initialize(client_id, redirect_uri, **options) ⇒ Installed
constructor
A new instance of Installed.
Methods inherited from Base
#delete, #get, #patch, #post, #put, #refresh_access!, #revoke_access!, #with
Methods included from Base::Wikiread
Methods included from Base::Stream
Methods included from Base::Submit
Methods included from Base::Read
#from_fullname, #from_url, #get_comments, #get_controversial, #get_hot, #get_new, #get_top, #multi_from_path, #my_multis, #search, #subreddit_from_name, #user_from_name
Methods included from Base::Privatemessages
#my_messages, #read_all_messages
Methods included from Base::None
#captcha_url, #needs_captcha?, #new_captcha
Methods included from Base::Identity
Methods included from Base::Account
Methods included from Base::Utilities
#append_to_listing, #flat_comments, #object_from_body, #property, #request_object
Constructor Details
#initialize(client_id, redirect_uri, **options) ⇒ Installed
Returns a new instance of Installed.
18 19 20 21 22 |
# File 'lib/redd/clients/installed.rb', line 18 def initialize(client_id, redirect_uri, **) @client_id = client_id @redirect_uri = redirect_uri super(**) end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
10 11 12 |
# File 'lib/redd/clients/installed.rb', line 10 def client_id @client_id end |
#redirect_uri ⇒ Object (readonly)
Returns the value of attribute redirect_uri.
13 14 15 |
# File 'lib/redd/clients/installed.rb', line 13 def redirect_uri @redirect_uri end |
Instance Method Details
#auth_url(state, scope = ['identity'], duration = :temporary) ⇒ String
rubocop:disable Metrics/MethodLength
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/redd/clients/installed.rb', line 29 def auth_url(state, scope = ['identity'], duration = :temporary) query = { response_type: 'token', client_id: @client_id, redirect_uri: @redirect_uri, state: state, scope: scope.join(','), duration: duration } url = URI.join(auth_endpoint, '/api/v1/authorize') url.query = URI.encode_www_form(query) url.to_s end |
#authorize!(fragment) ⇒ Access
Authorize using the url fragment.
46 47 48 49 50 51 52 53 |
# File 'lib/redd/clients/installed.rb', line 46 def (fragment) parsed = CGI.parse(fragment) @access = Access.new( access_token: parsed[:access_token].first, expires_in: parsed[:expires_in].first, scope: parsed[:scope] ) end |