Module: Cartowrap::HTTPService

Defined in:
lib/cartowrap/http_service.rb,
lib/cartowrap/http_service/endpoint.rb,
lib/cartowrap/http_service/response.rb

Defined Under Namespace

Classes: Endpoint, Response

Class Method Summary collapse

Class Method Details

.make_request(options, credentials = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cartowrap/http_service.rb', line 8

def self.make_request(options, credentials={})
  http_method = options.http_method&.to_sym || :get
   = credentials["account"]
  endpoint = Endpoint.new(options, credentials).get
  con = Faraday.new(:url => "https://#{}.cartodb.com") do |faraday|
    faraday.request  :multipart
    faraday.response :logger
    faraday.adapter  Faraday.default_adapter
  end
  response = con.send(http_method) do |req|
    req.url "#{endpoint}"
    req.headers['Content-Type'] = 'application/json' if options.http_method == 'post' || options.http_method == 'put'
    req.body = options.marshal_dump.to_json if options.http_method == 'post' || options.http_method == 'put'
  end
  Cartowrap::HTTPService::Response.new(response.status.to_i, response.body, response.headers)
end