Class: KSequencing::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/k_sequencing/connection.rb

Instance Method Summary collapse

Instance Method Details

#get(path, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/k_sequencing/connection.rb', line 9

def get(path, options = {})
  response = connection.get do |request|
    request.url(path)
    request.headers["Content-Type"] = "application/json"
    request.headers["Authorization"] = options[:token] unless options[:token].nil?
    request.params = options
  end
  Response.new(data(response), true, response.status, "success", meta(response), total(response))
rescue Error, Faraday::Error => e
  handle_error(e)
end

#post(path, options = {}, query_params = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/k_sequencing/connection.rb', line 21

def post(path, options = {}, query_params = {})
  response = connection.post do |request|
    request.path = path
    request.headers["Content-Type"] = "application/json"
    request.headers["Authorization"] = options[:token] unless options[:token].nil?
    request.params = query_params
    request.body = options unless options.empty?
  end
  Response.new(data(response), true, response.status)
rescue Error, Faraday::Error => e
  handle_error(e)
end