Class: Wowapi::ResponseData

Inherits:
OpenStruct
  • Object
show all
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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#rawObject

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(options={})
  @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(*options)
  as_json(*options).to_json(*options)
end