Class: Formidable::Remote

Inherits:
Object
  • Object
show all
Defined in:
lib/formidable/remote.rb

Class Method Summary collapse

Class Method Details

.send(data) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/formidable/remote.rb', line 9

def send(data)
  use_ssl = Config.use_ssl

  protocol = use_ssl ? "https://" : "http://"
  uri = URI.parse("#{protocol}#{HOST}/api/track")

  begin
    http = Net::HTTP.new(uri.host, uri.port)
    http.open_timeout = 1

    if use_ssl
      http.use_ssl = true
      http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    end

    query = "api_key=#{Config.api_key}&version=#{VERSION}"
    res = http.post("#{uri.path}?#{query}", data.to_json)

    (res.code.to_i == 200)
  rescue
    false
  end
end