Class: Ghtk::Request

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

Class Method Summary collapse

Class Method Details

.get(endpoint, params = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/ghtk/request.rb', line 18

def self.get(endpoint, params={})
  full_endpoint = "#{Ghtk.setup.domain}#{endpoint}?ver=#{Ghtk.setup.version}"
  response = HTTP.headers(
    content_type: 'aplication/json',
    token: Ghtk.setup.access_token,
  ).get(full_endpoint, params: params)
  raise Ghtk::ForbiddenError.new(full_endpoint) if response.code == 403
  raise Ghtk::ServerError.new(full_endpoint) if response.code == 500
  response.parse
end

.post(endpoint, params = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/ghtk/request.rb', line 6

def self.post(endpoint, params={})
  full_endpoint = "#{Ghtk.setup.domain}#{endpoint}?ver=#{Ghtk.setup.version}"
  response = HTTP.headers(
    content_type: 'application/json',
    token: Ghtk.setup.access_token,
  ).post(full_endpoint, json: params)
  raise Ghtk::ForbiddenError.new(full_endpoint) if response.code == 403
  raise Ghtk::ServerError.new(full_endpoint) if response.code == 500
  raise Ghtk::RequestError.new(response.parse) unless response.parse['success']
  response.parse
end