blob: 6053ecfbd5e3415dd527e48d599ee81f45b2d663 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# 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
response = new(JSON.parse(http_response.body))
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
|