Class: ForestLiana::ForestApiRequester

Inherits:
Object
  • Object
show all
Defined in:
app/services/forest_liana/forest_api_requester.rb

Class Method Summary collapse

Class Method Details

.get(route, query: nil, headers: {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'app/services/forest_liana/forest_api_requester.rb', line 5

def self.get(route, query: nil, headers: {})
  begin
    HTTParty.get("#{forest_api_url}#{route}", {
      :verify => Rails.env.production?,
      headers: base_headers.merge(headers),
      query: query,
    }).response
  rescue
    raise "Cannot reach Forest API at #{forest_api_url}#{route}, it seems to be down right now."
  end
end

.post(route, body: nil, query: nil, headers: {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/forest_liana/forest_api_requester.rb', line 17

def self.post(route, body: nil, query: nil, headers: {})
  begin
    if route.start_with?('https://')
      post_route = route
    else
      post_route = "#{forest_api_url}#{route}"
    end

    HTTParty.post(post_route, {
      :verify => Rails.env.production?,
      headers: base_headers.merge(headers),
      query: query,
      body: body.to_json,
    }).response
  rescue
    raise "Cannot reach Forest API at #{post_route}, it seems to be down right now."
  end
end