Class: EncodingDotCom::HttpAdapters::CurbAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/encoding_dot_com/http_adapters/curb_adapter.rb

Overview

Wraps the curb library for use with the Queue.

Instance Method Summary collapse

Constructor Details

#initializeCurbAdapter

Returns a new instance of CurbAdapter.



9
10
11
# File 'lib/encoding_dot_com/http_adapters/curb_adapter.rb', line 9

def initialize
  require 'curb'
end

Instance Method Details

#post(url, parameters = {}) ⇒ Object

Makes a POST request. Raises an AvailabilityError if the request times out or has other problems.



15
16
17
18
19
20
21
22
23
24
# File 'lib/encoding_dot_com/http_adapters/curb_adapter.rb', line 15

def post(url, parameters={})
  curl = Curl::Easy.new(url) {|c| c.follow_location = true }
  post_parameters = parameters.map {|k,v| Curl::PostField.content(k.to_s, v.to_s) }
  begin
    curl.http_post(*post_parameters)
  rescue => e
    raise AvailabilityError.new(e.message)
  end
  Response.new(curl.response_code.to_s, curl.body_str)
end