Class: GrowthPush::Response

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

Class Method Summary collapse

Class Method Details

.handle(response) ⇒ Object



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

def self.handle(response)
  _response = if response_body_not_json?(response.body)
    (response.body == 'true')
  else
    begin
      ::MultiJson.load(response.body)
    rescue MultiJson::DecodeError
      response.body
    end
  end

  if (200...300).include?(response.code.to_i)
    _response
  else
    Exception.handle_response(response)
  end
end

.response_body_not_json?(body) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/growth_push/response.rb', line 23

def self.response_body_not_json?(body)
  body == 'true' || body == 'false' || body == '[]'
end