Class: Wowapi::ResponseData
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Wowapi::ResponseData
- Defined in:
- lib/wowapi/response_data.rb
Overview
Every ModuleClass inherits from this object, so GuildClass, AchievementClass etc. ResponseData class inherits from OpenStruct which makes it easy to define arbitrary fields, using a Hash (so a default response object) www.ruby-doc.org/stdlib-2.0/libdoc/ostruct/rdoc/OpenStruct.html
Direct Known Subclasses
Modules::Character::CharacterClass, Modules::Guild::GuildClass
Instance Attribute Summary collapse
-
#raw ⇒ Object
Raw holds the response Hash, untouched.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
-
#from_json(data) ⇒ Object
Create a object of suitable class e.g.: guild = api.guild …
-
#initialize(data = {}) ⇒ ResponseData
constructor
A new instance of ResponseData.
-
#to_json(*options) ⇒ Object
Return raw data (retrieved by Blizzard servers).
Constructor Details
#initialize(data = {}) ⇒ ResponseData
Returns a new instance of ResponseData.
13 14 15 16 17 18 |
# File 'lib/wowapi/response_data.rb', line 13 def initialize(data={}) unless data.is_a?(Hash) raise ArgumentError, 'Data has to be passed as a Hash object.' end super end |
Instance Attribute Details
#raw ⇒ Object
Raw holds the response Hash, untouched
11 12 13 |
# File 'lib/wowapi/response_data.rb', line 11 def raw @raw end |
Instance Method Details
#as_json(options = {}) ⇒ Object
32 33 34 |
# File 'lib/wowapi/response_data.rb', line 32 def as_json(={}) @table end |
#from_json(data) ⇒ Object
Create a object of suitable class e.g.: guild = api.guild … guild = guild.from_json(data)
28 29 30 |
# File 'lib/wowapi/response_data.rb', line 28 def from_json(data) self.class.new(JSON.parse(data)) end |
#to_json(*options) ⇒ Object
Return raw data (retrieved by Blizzard servers)
21 22 23 |
# File 'lib/wowapi/response_data.rb', line 21 def to_json(*) as_json(*).to_json(*) end |