Class: Height::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/height/request.rb

Class Method Summary collapse

Class Method Details

.get(endpoint, query = nil) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/height/request.rb', line 2

def self.get(endpoint, query = nil)
  uri = URI("https://api.height.app/#{endpoint}")
  http = Net::HTTP.new(uri.hostname, uri.port)
  http.use_ssl = true
  headers = {
    'Authorization' => "api-key #{ENV['HEIGHT_API_KEY']}",
    'Content-Type' => 'application/json'
  }
  uri.query = URI.encode_www_form(query) if query 
  req = Net::HTTP::Get.new(uri, headers)

  http.request(req)
end

.put(endpoint, data) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/height/request.rb', line 16

def self.put(endpoint, data)
  uri = URI("https://api.height.app/#{endpoint}")
  http = Net::HTTP.new(uri.hostname, uri.port)
  http.use_ssl = true
  headers = {
    'Authorization' => "api-key #{ENV['HEIGHT_API_KEY']}",
    'Content-Type' => 'application/json'
  }
  req = Net::HTTP::Put.new(uri, headers)
  req.body = data.to_json
  res = http.request(req)

  http.request(req)
end