4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/medlink/client.rb', line 4
def post(url, params = {})
response = faraday_client.post do |req|
req.url api_url(url)
req.['Authorization'] = "Token token=\"#{token}\""
req.['Content-Type'] = "application/json"
req.['Accept'] = "application/json"
req.body = JSON.generate(params)
end
raise UnauthorizedError, "Token '#{token}' is not valid" if response.status == 401
json = JSON.parse response.body
if json.is_a? Hash and json.has_key?("errors")
error = json["errors"].first
raise(Error, "Error #{error["code"]}: #{error["detail"]}")
end
json
end
|