lib/filepreviews/http.rb in filepreviews-1.1.0 vs lib/filepreviews/http.rb in filepreviews-1.2.0
- old
+ new
@@ -20,10 +20,11 @@
# @return [Typhoeus::Connection] configured http client for requests to API
def default_connection(url = API_URL, debug = false)
Faraday.new(url: url) do |conn|
conn.adapter :typhoeus
conn.headers[:user_agent] = USER_AGENT
+ conn.headers[:content_type] = 'application/json'
configure_api_auth_header(conn.headers)
configure_logger(conn) if debug
end
end
@@ -45,18 +46,20 @@
# Returns processed metadata, and image attributes params
# @param params [Hash<Symbol>] metadata and image attributes
# @return [Hash<Symbol>] processed parameters
def prepare_request(params)
request = process_params(params)
- request.store(:size, extract_size(params.size)) if params.size
+ request.store(:sizes, [extract_size(params.size)]) if params.size
+ request.store(:format, params.format) if params.format
request
end
# Returns parsed response from API
# @return [Filepreviews::Response] json response as callable methods
def fetch(params)
+ options = prepare_request(params)
response = default_connection(API_URL, params.debug)
- .get nil, prepare_request(params)
+ .post { |req| req.body = JSON.generate(options) }
parse(response.body)
end
# Returns callable methods from parsed JSON response
# @param response_body [String<JSON>] stringified version of json response