Class: Freefeed::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/freefeed/client.rb

Constant Summary collapse

HOST =
'freefeed.net'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_token = nil, faraday_options = {}) ⇒ Client

Returns a new instance of Client.



7
8
9
10
# File 'lib/freefeed/client.rb', line 7

def initialize(api_token = nil, faraday_options = {})
  @api_token = api_token
  @faraday_options = faraday_options
end

Instance Attribute Details

#api_tokenObject

Returns the value of attribute api_token.



5
6
7
# File 'lib/freefeed/client.rb', line 5

def api_token
  @api_token
end

#faraday_optionsObject

Returns the value of attribute faraday_options.



5
6
7
# File 'lib/freefeed/client.rb', line 5

def faraday_options
  @faraday_options
end

#resourcesObject

Returns the value of attribute resources.



5
6
7
# File 'lib/freefeed/client.rb', line 5

def resources
  @resources
end

Instance Method Details

#authenticate(username:, password:) ⇒ Object



12
13
14
15
16
# File 'lib/freefeed/client.rb', line 12

def authenticate(username:, password:)
  Session.create(self, username: username, password: password).tap do |re|
    @api_token = re.fetch('authToken')
  end
end

#call!(verb, endpoint, params = {}, headers = {}) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/freefeed/client.rb', line 18

def call!(verb, endpoint, params = {}, headers = {})
  response = conn.send(
    verb, endpoint, params, auth_header.merge(headers)
  )
  handle_erros(response)
  prepare_response(response)
end