Class: Honey::Response
- Inherits:
-
Object
show all
- Defined in:
- lib/honey/response.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(http_response) ⇒ Response
Returns a new instance of Response.
7
8
9
10
|
# File 'lib/honey/response.rb', line 7
def initialize(http_response)
data = http_response.parsed_response['HPEnvelope']
@data = OpenStruct.new(data)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/honey/response.rb', line 12
def method_missing(method, *args, &block)
if method.to_s.end_with?('=')
data.send(method, *args)
else
data.send(method)
end
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5
6
7
|
# File 'lib/honey/response.rb', line 5
def data
@data
end
|
Instance Method Details
#cancelled? ⇒ Boolean
32
33
34
|
# File 'lib/honey/response.rb', line 32
def cancelled?
data.cancelled == 'Yes'
end
|
#error ⇒ Object
40
41
42
|
# File 'lib/honey/response.rb', line 40
def error
Honey::Error.new(data.code.to_i)
end
|
#failed? ⇒ Boolean
28
29
30
|
# File 'lib/honey/response.rb', line 28
def failed?
data.code.present? && data.code.to_i != 100
end
|
#inspect ⇒ Object
20
21
22
|
# File 'lib/honey/response.rb', line 20
def inspect
data.inspect
end
|
#log ⇒ Object
44
45
46
|
# File 'lib/honey/response.rb', line 44
def log
"[#{data.code}] #{message}"
end
|
#message ⇒ Object
48
49
50
|
# File 'lib/honey/response.rb', line 48
def message
data.error || data.details
end
|
#notes ⇒ Object
56
57
58
|
# File 'lib/honey/response.rb', line 56
def notes
data.warehousenotes || ""
end
|
#shipped? ⇒ Boolean
36
37
38
|
# File 'lib/honey/response.rb', line 36
def shipped?
data.status == 'Shipped'
end
|
#successful? ⇒ Boolean
24
25
26
|
# File 'lib/honey/response.rb', line 24
def successful?
!failed?
end
|
#tracking_numbers ⇒ Object
52
53
54
|
# File 'lib/honey/response.rb', line 52
def tracking_numbers
(1..5).map { |i| data.try(:"trackingnumber#{i}") }.compact.join(',')
end
|