Class: Keen::HTTP::Sync

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

Instance Method Summary collapse

Constructor Details

#initialize(base_url) ⇒ Sync

Returns a new instance of Sync.



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

def initialize(base_url)
  require 'uri'
  require 'net/http'

  uri = URI.parse(base_url)
  @http = Net::HTTP.new(uri.host, uri.port)

  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



32
33
34
35
36
# File 'lib/keen/http.rb', line 32

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

#get(options) ⇒ Object



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

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

#post(options) ⇒ Object



20
21
22
23
24
# File 'lib/keen/http.rb', line 20

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