lib/link_shrink/request.rb in link_shrink-0.0.2 vs lib/link_shrink/request.rb in link_shrink-0.0.3
- old
+ new
@@ -8,15 +8,16 @@
base.extend self
end
module_function
- def process_request(url, options, shrinker = LinkShrink::Shrinkers::Google.new)
+ def process_request(url, options, shrinker = LinkShrink::Config.api)
process_response(request(url, shrinker).body, options, shrinker)
end
def process_response(response, options, shrinker, json = JSONParser)
+ return response if shrinker.content_type.eql?('text/plain')
option = Options.new(options)
parsed_json = json.parse_json(response)
plain = parsed_json['id']
if option.json? && option.qr_code?
@@ -43,14 +44,15 @@
# Calls URL API
# @see LinkShrink::Shrinkers::Base#api_url
# @see LinkShrink::Shrinkers::Base#body_parameters
def request(url, shrinker)
+ shrinker.url = url
Typhoeus::Request.new(
shrinker.api_url,
- method: :post,
+ method: shrinker.http_method,
body: shrinker.body_parameters(url),
- headers: { 'Content-Type' => 'application/json' }
+ headers: { 'Content-Type' => shrinker.content_type }
).run
end
end
end