Class: Gecko::Http
- Inherits:
-
Object
- Object
- Gecko::Http
- Defined in:
- lib/gecko/http.rb
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
- #encode_body(body) ⇒ Object
- #headers ⇒ Object
-
#initialize(*args) ⇒ Http
constructor
A new instance of Http.
- #post(url, body, &request_block) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Http
Returns a new instance of Http.
5 6 7 8 9 10 11 12 13 |
# File 'lib/gecko/http.rb', line 5 def initialize(*args) @connection = Faraday.new(*args) do |connection| connection.response :multi_json, :symbolize_keys => true Gecko.config.connection_builder.call(connection) if Gecko.config.connection_builder.respond_to?(:call) yield connection if block_given? connection.adapter Faraday.default_adapter if connection.builder.handlers.none? { |handler| handler.klass < Faraday::Adapter } end self end |
Instance Method Details
#encode_body(body) ⇒ Object
22 23 24 |
# File 'lib/gecko/http.rb', line 22 def encode_body(body) MultiJson.encode(body) end |
#headers ⇒ Object
15 16 17 18 19 20 |
# File 'lib/gecko/http.rb', line 15 def headers { :accept => 'application/json', :user_agent => Gecko.config.http_user_agent } end |
#post(url, body, &request_block) ⇒ Object
26 27 28 |
# File 'lib/gecko/http.rb', line 26 def post(url, body, &request_block) Result.new(@connection.post(url, self.encode_body(body), self.headers, &request_block)) end |