Class: Tito::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/tito/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token:, base_url: nil) ⇒ Connection

Returns a new instance of Connection.



5
6
7
8
# File 'lib/tito/connection.rb', line 5

def initialize(token:, base_url: nil)
  @token = token
  @base_url = base_url || Tito.configuration.base_url
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



3
4
5
# File 'lib/tito/connection.rb', line 3

def base_url
  @base_url
end

Instance Method Details

#delete(path) ⇒ Object



22
23
24
# File 'lib/tito/connection.rb', line 22

def delete(path)
  handle_response faraday.delete(path)
end

#faradayObject



26
27
28
29
30
31
32
33
34
# File 'lib/tito/connection.rb', line 26

def faraday
  @faraday ||= Faraday.new(url: @base_url) do |f|
    f.headers["Authorization"] = "Token token=#{@token}"
    f.headers["Accept"] = "application/json"
    f.request :json
    f.response :logger, Tito.logger, headers: false, bodies: false if Tito.logger
    f.response :json, content_type: /\bjson$/
  end
end

#get(path, params: {}) ⇒ Object



10
11
12
# File 'lib/tito/connection.rb', line 10

def get(path, params: {})
  handle_response faraday.get(path, params)
end

#patch(path, body: {}) ⇒ Object



18
19
20
# File 'lib/tito/connection.rb', line 18

def patch(path, body: {})
  handle_response faraday.patch(path, body)
end

#post(path, body: {}) ⇒ Object



14
15
16
# File 'lib/tito/connection.rb', line 14

def post(path, body: {})
  handle_response faraday.post(path, body)
end