Class: GCR::Response
- Inherits:
-
Object
- Object
- GCR::Response
- Defined in:
- lib/gcr/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opts) ⇒ Response
constructor
A new instance of Response.
- #parsed_body ⇒ Object
- #to_json(*_) ⇒ Object
- #to_proto ⇒ Object
Constructor Details
#initialize(opts) ⇒ Response
Returns a new instance of Response.
18 19 20 21 |
# File 'lib/gcr/response.rb', line 18 def initialize(opts) @class_name = opts["class_name"] @body = opts["body"] end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
16 17 18 |
# File 'lib/gcr/response.rb', line 16 def body @body end |
#class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
16 17 18 |
# File 'lib/gcr/response.rb', line 16 def class_name @class_name end |
Class Method Details
.from_hash(hash_resp) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/gcr/response.rb', line 9 def self.from_hash(hash_resp) new( "class_name" => hash_resp["class_name"], "body" => hash_resp["body"], ) end |
.from_proto(proto_resp) ⇒ Object
2 3 4 5 6 7 |
# File 'lib/gcr/response.rb', line 2 def self.from_proto(proto_resp) new( "class_name" => proto_resp.class.name, "body" => proto_resp.to_json, ) end |
Instance Method Details
#parsed_body ⇒ Object
23 24 25 |
# File 'lib/gcr/response.rb', line 23 def parsed_body @parsed_body ||= JSON.decode(body) end |
#to_json(*_) ⇒ Object
27 28 29 |
# File 'lib/gcr/response.rb', line 27 def to_json(*_) JSON.dump("class_name" => class_name, "body" => body) end |
#to_proto ⇒ Object
31 32 33 |
# File 'lib/gcr/response.rb', line 31 def to_proto Object.const_get(class_name).decode_json(body) end |