Class: Rebay::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json_response) ⇒ Response

Returns a new instance of Response.



6
7
8
# File 'lib/rebay/response.rb', line 6

def initialize(json_response)
  @response = transform_json_response(json_response)
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



3
4
5
# File 'lib/rebay/response.rb', line 3

def response
  @response
end

#resultsObject

Returns the value of attribute results.



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

def results
  @results
end

Instance Method Details

#eachObject



24
25
26
27
28
29
30
31
32
# File 'lib/rebay/response.rb', line 24

def each
  unless @results.nil?
    if @results.class == Array
      @results.each { |r| yield r }
    else
      yield @results
    end
  end
end

#failure?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/rebay/response.rb', line 14

def failure?
  @response["Ack"] == 'Failure' || @response['ack'] == 'Failure'
end

#sizeObject



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

def size
  if @results.nil?
    return 0
  elsif @results.class == Array
    return @results.size
  else
    return 1
  end
end

#success?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/rebay/response.rb', line 10

def success?
  @response["Ack"] == 'Success' || @response['ack'] == 'Success'
end

#trim(key) ⇒ Object



18
19
20
21
22
# File 'lib/rebay/response.rb', line 18

def trim(key)
  if @response.has_key?(key.to_s)
    @response = @response[key.to_s]
  end
end