debian-mirror-gitlab/lib/gitlab/phabricator_import/conduit/response.rb

61 lines
1.3 KiB
Ruby
Raw Normal View History

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
2021-06-08 01:23:25 +05:30
raise ResponseError, e
2019-09-04 21:01:54 +05:30
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