Class: Rgcm::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Response

Returns a new instance of Response.



5
6
7
# File 'lib/rgcm/response.rb', line 5

def initialize(json)
  @body = JSON.parse(json, symbolize_names: true)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

Instance Method Details

#count_failuresObject



17
18
19
# File 'lib/rgcm/response.rb', line 17

def count_failures
  self.body[:failure]
end

#count_successesObject



9
10
11
# File 'lib/rgcm/response.rb', line 9

def count_successes
  self.body[:success]
end

#errorsObject



29
30
31
# File 'lib/rgcm/response.rb', line 29

def errors
  self.results.select { |result| result.key?(:error) }
end

#has_failures?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/rgcm/response.rb', line 21

def has_failures?
  self.count_failures > 0
end

#has_successes?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/rgcm/response.rb', line 13

def has_successes?
  self.count_successes > 0
end

#resultsObject



25
26
27
# File 'lib/rgcm/response.rb', line 25

def results
  self.body[:results]
end

#successesObject



33
34
35
# File 'lib/rgcm/response.rb', line 33

def successes
  self.results.select { |result| !result.key?(:error) }
end