Class: Mks::Common::MethodResponse
- Inherits:
-
Object
- Object
- Mks::Common::MethodResponse
- Defined in:
- lib/mks/common/methodresponse.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#message ⇒ Object
Returns the value of attribute message.
-
#success ⇒ Object
Returns the value of attribute success.
-
#total ⇒ Object
Returns the value of attribute total.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(success = nil, message = nil, data = nil, errors = [], total = nil) ⇒ MethodResponse
constructor
A new instance of MethodResponse.
- #to_hash ⇒ Object
Constructor Details
#initialize(success = nil, message = nil, data = nil, errors = [], total = nil) ⇒ MethodResponse
Returns a new instance of MethodResponse.
8 9 10 11 12 13 14 |
# File 'lib/mks/common/methodresponse.rb', line 8 def initialize(success=nil, =nil, data=nil, errors=[], total=nil) @success = success @message = @data = data @errors = errors @total = total end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/mks/common/methodresponse.rb', line 6 def data @data end |
#errors ⇒ Object
Returns the value of attribute errors.
6 7 8 |
# File 'lib/mks/common/methodresponse.rb', line 6 def errors @errors end |
#message ⇒ Object
Returns the value of attribute message.
6 7 8 |
# File 'lib/mks/common/methodresponse.rb', line 6 def @message end |
#success ⇒ Object
Returns the value of attribute success.
6 7 8 |
# File 'lib/mks/common/methodresponse.rb', line 6 def success @success end |
#total ⇒ Object
Returns the value of attribute total.
6 7 8 |
# File 'lib/mks/common/methodresponse.rb', line 6 def total @total end |
Class Method Details
.from_json(json_response) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/mks/common/methodresponse.rb', line 16 def self.from_json(json_response) response = JSON.parse json_response success = response['success'] if response.has_key?('success') = response['message'] if response.has_key?('message') data = response['data'] if response.has_key?('data') errors = response['errors'] if response.has_key?('errors') total = response['total'] if response.has_key?('total') MethodResponse.new(success, , data, errors, total) end |
Instance Method Details
#to_hash ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/mks/common/methodresponse.rb', line 26 def to_hash hash = {} self.instance_variables.each do |var| hash[var.to_s.delete("@")] = self.instance_variable_get var end return hash end |