Class: Skink::Client::Response
- Inherits:
-
Object
- Object
- Skink::Client::Response
show all
- Includes:
- Utils
- Defined in:
- lib/skink/client/response.rb
Instance Method Summary
collapse
Methods included from Utils
#normalize_header_name
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
85
86
87
88
89
90
91
|
# File 'lib/skink/client/response.rb', line 85
def method_missing(name, *args)
if name.match(/has_(\w+)_header\?/)
[($1)] === args.first
else
super
end
end
|
Instance Method Details
#body ⇒ Object
41
42
43
|
# File 'lib/skink/client/response.rb', line 41
def body
raise NotImplementedError
end
|
20
21
22
23
24
25
26
27
|
# File 'lib/skink/client/response.rb', line 20
def
case
when String
[.keys.detect {|key| key.match(/^#{header}$/i)}] rescue nil
when Symbol
[.keys.detect {|key| key.match(/^#{header.to_s.gsub('_', '-')}$/i)}] rescue nil
end
end
|
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/skink/client/response.rb', line 29
def
if ()
true
elsif .respond_to? :keys
.all? do |key, value|
value === (key)
end
else
false
end
end
|
#has_jsonpath?(path, value = nil) ⇒ Boolean
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/skink/client/response.rb', line 74
def has_jsonpath? path, value = nil
elems = jsonpath(path)
if value
block = ->(elem) {value === elem}
else
block = nil
end
elems.any?(&block)
end
|
#has_xpath?(path, value = nil) ⇒ Boolean
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/skink/client/response.rb', line 53
def has_xpath? path, value = nil
elems = xpath(path)
elems = [elems] unless elems.respond_to? :any?
if value
block = ->(elem) {value === elem.to_s}
else
block = nil
end
elems.any?(&block)
end
|
16
17
18
|
# File 'lib/skink/client/response.rb', line 16
def
raise NotImplementedError
end
|
#json_doc ⇒ Object
66
67
68
|
# File 'lib/skink/client/response.rb', line 66
def json_doc
@json_doc ||= MultiJson.load body
end
|
#jsonpath(path) ⇒ Object
70
71
72
|
# File 'lib/skink/client/response.rb', line 70
def jsonpath path
JsonPath.new(path).on json_doc
end
|
#status_code ⇒ Object
12
13
14
|
# File 'lib/skink/client/response.rb', line 12
def status_code
raise NotImplementedError
end
|
#xml_doc ⇒ Object
45
46
47
|
# File 'lib/skink/client/response.rb', line 45
def xml_doc
@xml_doc ||= Nokogiri::XML.parse body
end
|
#xpath(path) ⇒ Object
49
50
51
|
# File 'lib/skink/client/response.rb', line 49
def xpath path
xml_doc.xpath path
end
|