2019-09-04 21:01:54 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
module Gitlab
|
|
|
|
module PhabricatorImport
|
|
|
|
module Conduit
|
|
|
|
class Response
|
|
|
|
def self.parse!(http_response)
|
|
|
|
unless http_response.success?
|
|
|
|
raise Gitlab::PhabricatorImport::Conduit::ResponseError,
|
|
|
|
"Phabricator responded with #{http_response.status}"
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
response = new(Gitlab::Json.parse(http_response.body))
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
unless response.success?
|
|
|
|
raise ResponseError,
|
|
|
|
"Phabricator Error: #{response.error_code}: #{response.error_info}"
|
|
|
|
end
|
|
|
|
|
|
|
|
response
|
|
|
|
rescue JSON::JSONError => e
|
|
|
|
raise ResponseError.new(e)
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(json)
|
|
|
|
@json = json
|
|
|
|
end
|
|
|
|
|
|
|
|
def success?
|
|
|
|
error_code.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
def error_code
|
|
|
|
json['error_code']
|
|
|
|
end
|
|
|
|
|
|
|
|
def error_info
|
|
|
|
json['error_info']
|
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
|
|
|
json_result&.fetch('data')
|
|
|
|
end
|
|
|
|
|
|
|
|
def pagination
|
|
|
|
return unless cursor_info = json_result&.fetch('cursor')
|
|
|
|
|
|
|
|
@pagination ||= Pagination.new(cursor_info)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :json
|
|
|
|
|
|
|
|
def json_result
|
|
|
|
json['result']
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|