Refactor ejabberd API integration
This commit is contained in:
@@ -13,15 +13,17 @@ class RestApiService < ApplicationService
|
||||
"#{base_url}/#{path.gsub(/^\//, '')}"
|
||||
end
|
||||
|
||||
def parse_responses?
|
||||
true
|
||||
end
|
||||
|
||||
def get(path, params = {})
|
||||
res = Faraday.get endpoint_url(path), params, headers
|
||||
# TODO handle unsuccessful responses with no valid JSON body
|
||||
JSON.parse(res.body)
|
||||
parse_responses? ? JSON.parse(res.body) : res
|
||||
end
|
||||
|
||||
def post(path, payload)
|
||||
res = Faraday.post endpoint_url(path), payload.to_json, headers
|
||||
# TODO handle unsuccessful responses with no valid JSON body
|
||||
JSON.parse(res.body)
|
||||
parse_responses? ? JSON.parse(res.body) : res
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user