Class: Imgur::Session
- Inherits:
-
Object
- Object
- Imgur::Session
- Defined in:
- lib/imgur/session.rb
Constant Summary collapse
- HOST =
'https://api.imgur.com'
Instance Method Summary collapse
- #access_token=(access_token) ⇒ Object
- #connection ⇒ Object
-
#initialize(options) ⇒ Session
constructor
Creates the session instance that handles all the API calls to Imgur access_token is optional.
- #params ⇒ Object
Constructor Details
#initialize(options) ⇒ Session
Creates the session instance that handles all the API calls to Imgur access_token is optional
7 8 9 10 11 12 13 14 15 |
# File 'lib/imgur/session.rb', line 7 def initialize() required_arguments = %i(client_id client_secret refresh_token) raise ArgumentError if required_arguments & .keys != required_arguments @client_id = [:client_id] @client_secret = [:client_secret] @access_token = [:access_token] @refresh_token = [:refresh_token] end |
Instance Method Details
#access_token=(access_token) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/imgur/session.rb', line 23 def access_token=(access_token) @access_token = access_token # Forces to create a new connection with new header @connection = nil end |
#connection ⇒ Object
38 39 40 41 42 43 |
# File 'lib/imgur/session.rb', line 38 def connection @connection ||= Faraday.new( HOST, headers: {'Authorization' => 'Bearer ' << @access_token} ) end |
#params ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/imgur/session.rb', line 30 def params { refresh_token: @refresh_token, client_id: @client_id, client_secret: @client_secret } end |