Class: Keen::HTTP::Sync

Inherits:
Object
  • Object
show all
Defined in:
lib/keen/http.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_url, proxy_url = nil, read_timeout = nil, open_timeout = nil) ⇒ Sync

Returns a new instance of Sync.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/keen/http.rb', line 4

def initialize(base_url, proxy_url=nil, read_timeout=nil, open_timeout=nil)
  require 'uri'
  require 'net/http'

  uri = URI.parse(base_url)
  arguments = [uri.host, uri.port]
  arguments+= proxy_arguments_for(proxy_url) if proxy_url

  @http = Net::HTTP.new(*arguments)
  @http.open_timeout = open_timeout if open_timeout
  @http.read_timeout = read_timeout if read_timeout

  if uri.scheme == "https"
    require 'net/https'
    @http.use_ssl = true;
    @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
    @http.verify_depth = 5
    @http.ca_file = File.expand_path("../../../config/cacert.pem", __FILE__)
  end
end

Instance Method Details

#delete(options) ⇒ Object



48
49
50
51
52
# File 'lib/keen/http.rb', line 48

def delete(options)
  path, headers = options.values_at(
    :path, :headers)
  @http.delete(path, headers)
end

#get(options) ⇒ Object



42
43
44
45
46
# File 'lib/keen/http.rb', line 42

def get(options)
  path, headers = options.values_at(
    :path, :headers)
  @http.get(path, headers)
end

#post(options) ⇒ Object



30
31
32
33
34
# File 'lib/keen/http.rb', line 30

def post(options)
  path, headers, body = options.values_at(
    :path, :headers, :body)
  @http.post(path, body, headers)
end

#proxy_arguments_for(uri) ⇒ Object



25
26
27
28
# File 'lib/keen/http.rb', line 25

def proxy_arguments_for(uri)
  proxy_uri = URI.parse(uri)
  [proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password]
end

#put(options) ⇒ Object



36
37
38
39
40
# File 'lib/keen/http.rb', line 36

def put(options)
  path, headers, body = options.values_at(
    :path, :headers, :body)
  @http.put(path, body, headers)
end