lib/lifen/app_authenticated_client.rb in lifen-0.2.1 vs lib/lifen/app_authenticated_client.rb in lifen-1.0.0

- old
+ new

@@ -1,39 +1,27 @@ module Lifen class AppAuthenticatedClient < Client - def post(url, params = {}) + private - response = faraday_client.post do |req| - req.url url + def handle_status!(response) + super(response) - req.headers['secret_key'] = secret_key - req.headers['Content-Type'] = "application/json" + case response.status + when 400 + raise Error, "Error 400" + when 401 + raise InvalidSecretTokenError + when 403 + raise UserAlreadyExistingError + when 404 + raise Error, "Error 404, Page not found" + end - req.body = JSON.generate(params) end - if response.status == 500 - json = JSON.parse response.body - - trace_id = json.fetch("X-B3-TraceId", "unknown") - raise Error, "Error 500, Internal server error (trace ID: #{trace_id})" - end - - raise Error, "Error 400" if response.status == 400 - raise Error, "Error 404, Page not found" if response.status == 404 - raise InvalidSecretTokenError if response.status == 401 - raise UserAlreadyExistingError if response.status == 403 - - json = JSON.parse response.body - - json - end - - private - - def secret_key - Lifen.configuration.secret_key + def bearer + Lifen.configuration.application_access_token end end end \ No newline at end of file