- resp = Oj.load(json, :symbol_keys => true)
- if resp[:errors]
- if resp[:errors][0] == 'Not logged in'
- raise NotLoggedInException.new
- else
- errors = resp[:errors]
- errors = errors.join("\n\n") if errors.is_a? Array
- raise "API errors:\n\n#{errors}\n"
- end
+
+ header = {"Accept" => "application/json"}
+
+ profile_checkpoint { "Prepare request #{url} #{query[:uuid]} #{query[:where]}" }
+ msg = @@api_client.post(url,
+ query,
+ header: header)
+ profile_checkpoint 'API transaction'
+
+ if msg.status_code == 401
+ raise NotLoggedInException.new
+ end
+
+ json = msg.content
+
+ begin
+ resp = Oj.load(json, :symbol_keys => true)
+ rescue Oj::ParseError
+ raise InvalidApiResponseException.new json
+ end
+ if not resp.is_a? Hash
+ raise InvalidApiResponseException.new json
+ end
+ if msg.status_code != 200
+ errors = resp[:errors]
+ errors = errors.join("\n\n") if errors.is_a? Array
+ raise "#{errors} [API: #{msg.status_code}]"