Class: Addons::Client::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/addons-client/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



4
5
6
7
8
9
10
11
12
# File 'lib/addons-client/response.rb', line 4

def initialize(response)
  @data = case response
          when String
            response.strip.empty? ? {} : JSON.parse(response)
          when Hash
            response
          end
  @data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &blk) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/addons-client/response.rb', line 34

def method_missing(name, *args, &blk)
  if @data.keys.include? name
    @data[name]
  elsif @data.keys.include? name.to_s
    @data[name.to_s]
  else
    super
  end
end

Instance Method Details

#dataObject



14
15
16
# File 'lib/addons-client/response.rb', line 14

def data
  @data
end

#each(&blk) ⇒ Object



26
27
28
# File 'lib/addons-client/response.rb', line 26

def each(&blk)
  data.each(&blk)
end

#inject(hash, &blk) ⇒ Object



30
31
32
# File 'lib/addons-client/response.rb', line 30

def inject(hash, &blk)
  data.inject(hash,&blk)
end

#to_aObject



22
23
24
# File 'lib/addons-client/response.rb', line 22

def to_a
  [*data]
end

#to_sObject



18
19
20
# File 'lib/addons-client/response.rb', line 18

def to_s
  data.to_s
end