Class: Annict::Client

Inherits:
Object
  • Object
show all
Includes:
ApiMethods
Defined in:
lib/annict/client.rb

Constant Summary collapse

ENDPOINT_BASE_URL =
"https://api.annict.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ApiMethods

#activities, #add_record, #change_status, #episodes, #followers, #following, #following_activities, #me, #own_works, #programs, #records, #users, #works

Constructor Details

#initialize(access_token: nil) ⇒ Client

Returns a new instance of Client.



12
13
14
# File 'lib/annict/client.rb', line 12

def initialize(access_token: nil)
  @access_token = access_token
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



15
16
17
# File 'lib/annict/client.rb', line 15

def access_token
  @access_token
end

Instance Method Details

#annict_connectionObject



29
30
31
32
33
34
35
# File 'lib/annict/client.rb', line 29

def annict_connection
  @annict_connection ||= Faraday.new(faraday_options) do |faraday|
    faraday.request :json
    faraday.response :json
    faraday.adapter Faraday.default_adapter
  end
end

#send_get(path, params = {}) ⇒ Object



17
18
19
# File 'lib/annict/client.rb', line 17

def send_get(path, params = {})
  send_request(:get, path, params)
end

#send_post(path, params = {}) ⇒ Object



21
22
23
# File 'lib/annict/client.rb', line 21

def send_post(path, params = {})
  send_request(:post, path, params)
end

#send_request(method, path, params) ⇒ Object



25
26
27
# File 'lib/annict/client.rb', line 25

def send_request(method, path, params)
  Annict::Response.new(annict_connection.send(method, path, params))
end