Class: WealthForge::Connection

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

Class Method Summary collapse

Class Method Details

.get(endpoint, params, raw = false) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/wealth_forge/connection.rb', line 39

def self.get(endpoint, params, raw=false)
  begin
    response = connection.get do |req|
      req.url endpoint
      req.headers['Content-Type'] = 'application/json'
      req.body = prep_params(params)
    end
    raw == false ? JSON.parse(response.body, symbolize_names: true) : response.body
  rescue => e
    raise WealthForge::ApiException.new(e)
  end
end

.post(endpoint, params) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/wealth_forge/connection.rb', line 11

def self.post(endpoint, params)
  begin
    response = connection.post do |req|
      req.url endpoint
      req.headers['Content-Type'] = 'application/json'
      req.body = prep_params(params)
    end
    JSON.parse(response.body, symbolize_names: true)
  rescue => e
    raise WealthForge::ApiException.new(e)
  end
end

.put(endpoint, params) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/wealth_forge/connection.rb', line 25

def self.put(endpoint, params)
  begin
    response = connection.put do |req|
      req.url endpoint
      req.headers['Content-Type'] = 'application/json'
      req.body = prep_params(params)
    end
    JSON.parse(response.body, symbolize_names: true)
  rescue => e
    raise WealthForge::ApiException.new(e)
  end
end