lib/dato/api_client.rb in dato-0.7.5 vs lib/dato/api_client.rb in dato-0.7.6
- old
+ new
@@ -54,12 +54,35 @@
end
end
end
end
+ def put(absolute_path, body = {}, params = {})
+ request(:put, absolute_path, body, params)
+ end
+
+ def post(absolute_path, body = {}, params = {})
+ request(:post, absolute_path, body, params)
+ end
+
+ def get(absolute_path, params = {})
+ request(:get, absolute_path, nil, params)
+ end
+
+ def delete(absolute_path, params = {})
+ request(:delete, absolute_path, nil, params)
+ end
+
def request(*args)
- response = connection.send(*args)
+ method, absolute_path, body, params = args
+
+ response = connection.send(method, absolute_path, body) do |c|
+ if params
+ c.params = params
+ end
+ end
+
if response.body.is_a?(Hash)
response.body.with_indifferent_access
else
nil
end
@@ -80,11 +103,11 @@
elsif e.response[:status] == 422 && batch_data_validation?(e.response)
puts "Validating items, waiting 1 second and retrying..."
sleep(1)
request(*args)
else
- error = ApiError.new(e)
+ error = ApiError.new(e.response)
puts "===="
puts error.message
puts "===="
raise error
end
@@ -113,15 +136,15 @@
default_headers = {
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'Authorization' => "Bearer #{@token}",
'User-Agent' => "ruby-client v#{Dato::VERSION}",
- 'X-Api-Version' => '2'
+ 'X-Api-Version' => '3'
}
options = {
url: base_url,
- headers: default_headers.merge(extra_headers)
+ headers: default_headers.merge(extra_headers),
}
@connection ||= Faraday.new(options) do |c|
c.request :json
c.response :json, content_type: /\bjson$/