Class: Betavites::Remote

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

Class Method Summary collapse

Class Method Details

.send(path, data) ⇒ Object



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

def send(path, data)
  uri = URI.parse("#{HOST}/#{path}")
  query = "api_key=#{Config.api_key}&version=#{VERSION}"

  begin
    post = Net::HTTP::Post.new("#{uri.path}?#{query}")
    post.set_form_data(data)

    req = Net::HTTP.new(uri.host, uri.port)
    req.use_ssl = true
    req.verify_mode = OpenSSL::SSL::VERIFY_NONE

    res = req.start do |http|
      http.read_timeout = 2
      http.request(post)
    end
    res_data = JSON.parse(res.body)
    return res_data["code"], res_data["message"]
  rescue
    return 500, "Internal server error"
  end
end