Class: Minecraft::JSONAPIv2::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/minecraft_jsonapiv2/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Response

Returns a new instance of Response.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/minecraft_jsonapiv2/response.rb', line 5

def initialize(data)
  @response = {}
  data = JSON.parse(data)
  @raw_response = data
  if data.count == 1
    data = data[0]
  end
  if data.is_a? Array
    data.each do |d|
      @response[d['source'].gsub(/\./, '_')] = d['success']
    end
    @response = Mash.new @response.rubyify_keys!
  else
    @response = data['success']
    @response = Mash.new @response.rubyify_keys! if @response.is_a? Hash
  end
  @response
end

Instance Attribute Details

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



4
5
6
# File 'lib/minecraft_jsonapiv2/response.rb', line 4

def raw_response
  @raw_response
end

#responseObject (readonly)

Returns the value of attribute response.



4
5
6
# File 'lib/minecraft_jsonapiv2/response.rb', line 4

def response
  @response
end