Class: Imgurapi::Session
- Inherits:
-
Object
- Object
- Imgurapi::Session
- Defined in:
- lib/imgurapi/session.rb
Constant Summary collapse
- HOST =
'https://api.imgur.com'
Class Method Summary collapse
-
.instance(options) ⇒ Object
Singleton initializer to allow access_token reuse.
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
- #use_ssl? ⇒ Boolean
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 16 |
# File 'lib/imgurapi/session.rb', line 7 def initialize() required_arguments = %i(client_id client_secret refresh_token) raise ArgumentError unless required_arguments.all? { |key| .keys.include? key } @client_id = [:client_id] @client_secret = [:client_secret] @access_token = [:access_token] @refresh_token = [:refresh_token] @use_ssl = !![:use_ssl] end |
Class Method Details
.instance(options) ⇒ Object
Singleton initializer to allow access_token reuse
19 20 21 |
# File 'lib/imgurapi/session.rb', line 19 def self.instance() @@session ||= new() end |
Instance Method Details
#access_token=(access_token) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/imgurapi/session.rb', line 33 def access_token=(access_token) @access_token = access_token # Forces to create a new connection with new header @connection = nil end |
#connection ⇒ Object
48 49 50 51 52 53 |
# File 'lib/imgurapi/session.rb', line 48 def connection @connection ||= Faraday.new( HOST, headers: {'Authorization' => 'Bearer ' << @access_token} ) end |
#params ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/imgurapi/session.rb', line 40 def params { refresh_token: @refresh_token, client_id: @client_id, client_secret: @client_secret } end |
#use_ssl? ⇒ Boolean
29 30 31 |
# File 'lib/imgurapi/session.rb', line 29 def use_ssl? @use_ssl end |