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
16
17
# 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 => error
    FOREST_LOGGER.error "Cannot reach Forest API at #{forest_api_url}#{route}, it seems to be down right now."
    FOREST_REPORTER.report error
    raise error
  end
end

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



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

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 => error
    FOREST_LOGGER.error "Cannot reach Forest API at #{post_route}, it seems to be down right now."
    FOREST_REPORTER.report error
    raise error
  end
end