Class: Tweetwine::Http::Client

Inherits:
Object
  • Object
show all
Includes:
Retrying
Defined in:
lib/tweetwine/http.rb

Constant Summary

Constants included from Retrying

Retrying::MAX_RETRIES, Retrying::RETRY_BASE_WAIT_TIMEOUT

Instance Method Summary collapse

Methods included from Retrying

#retrying

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



33
34
35
# File 'lib/tweetwine/http.rb', line 33

def initialize(options = {})
  @http = Net::HTTP::Proxy(*parse_proxy_url(options[:http_proxy]))
end

Instance Method Details

#as_resource(url) ⇒ Object



58
59
60
# File 'lib/tweetwine/http.rb', line 58

def as_resource(url)
  Resource.new(self, url)
end

#get(url, headers = nil, &block) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/tweetwine/http.rb', line 37

def get(url, headers = nil, &block)
  retrying do
    requesting(url) do |connection, uri|
      req = Net::HTTP::Get.new(uri.request_uri, headers)
      block.call(connection, req) if block
      connection.request(req)
    end
  end
end

#post(url, payload = nil, headers = nil, &block) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/tweetwine/http.rb', line 47

def post(url, payload = nil, headers = nil, &block)
  retrying do
    requesting(url) do |connection, uri|
      req = Net::HTTP::Post.new(uri.request_uri, headers)
      req.form_data = payload if payload
      block.call(connection, req) if block
      connection.request(req)
    end
  end
end