Module: RallyUp::Request

Defined in:
lib/rally_up.rb

Instance Method Summary collapse

Instance Method Details

#delete(path, params: {}, headers: {}) ⇒ Object



16
17
18
# File 'lib/rally_up.rb', line 16

def delete(path, params: {}, headers: {})
  request(:delete, path, params: params, headers: headers)
end

#get(path, params: {}, headers: {}) ⇒ Object



20
21
22
# File 'lib/rally_up.rb', line 20

def get(path, params: {}, headers: {})
  request(:get, path, params: params, headers: headers)
end

#json(method, path, params: {}, headers: {}) ⇒ Object



39
40
41
42
# File 'lib/rally_up.rb', line 39

def json(method, path, params: {}, headers: {})
  response = request(method, path, params: params, headers: headers)
  JSON.parse(response, symbolize_names: true)
end

#post(path, params: {}, headers: {}) ⇒ Object



24
25
26
# File 'lib/rally_up.rb', line 24

def post(path, params: {}, headers: {})
  request(:post, path, params: params, headers: headers)
end

#put(path, params: {}, headers: {}) ⇒ Object



28
29
30
# File 'lib/rally_up.rb', line 28

def put(path, params: {}, headers: {})
  request(:put, path, params: params, headers: headers)
end

#request(method, path, domain: 'go.rallyup.com', params: {}, headers: {}) ⇒ Object



32
33
34
35
36
37
# File 'lib/rally_up.rb', line 32

def request(method, path, domain: 'go.rallyup.com', params: {}, headers: {})
  request_params = method == :get ? { params: params } : { body: URI.encode_www_form(params) }
  response = HTTP.headers(headers).send(method, "https://#{domain}#{path}", request_params)
  verify!(response)
  response
end