Class: Tito::Connection
- Inherits:
-
Object
- Object
- Tito::Connection
- Defined in:
- lib/tito/connection.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
Instance Method Summary collapse
- #delete(path) ⇒ Object
- #faraday ⇒ Object
- #get(path, params: {}) ⇒ Object
-
#initialize(token:, base_url: nil) ⇒ Connection
constructor
A new instance of Connection.
- #patch(path, body: {}) ⇒ Object
- #post(path, body: {}) ⇒ Object
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_url ⇒ Object (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 |
#faraday ⇒ Object
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 |