Class: Exponent::Push::ResponseHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/exponent-server-sdk-jm.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error_builder = ErrorBuilder.new) ⇒ ResponseHandler

Returns a new instance of ResponseHandler.



114
115
116
117
118
119
120
# File 'lib/exponent-server-sdk-jm.rb', line 114

def initialize(error_builder = ErrorBuilder.new)
  @error_builder       = error_builder
  @response            = nil
  @receipt_ids         = []
  @invalid_push_tokens = []
  @errors              = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



112
113
114
# File 'lib/exponent-server-sdk-jm.rb', line 112

def errors
  @errors
end

#invalid_push_tokensObject (readonly)

Returns the value of attribute invalid_push_tokens.



112
113
114
# File 'lib/exponent-server-sdk-jm.rb', line 112

def invalid_push_tokens
  @invalid_push_tokens
end

#receipt_idsObject (readonly)

Returns the value of attribute receipt_ids.



112
113
114
# File 'lib/exponent-server-sdk-jm.rb', line 112

def receipt_ids
  @receipt_ids
end

#responseObject (readonly)

Returns the value of attribute response.



112
113
114
# File 'lib/exponent-server-sdk-jm.rb', line 112

def response
  @response
end

Instance Method Details

#errors?Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/exponent-server-sdk-jm.rb', line 133

def errors?
  @errors.any?
end

#handle(response) ⇒ Object

Deprecated.


138
139
140
141
142
143
144
145
146
147
# File 'lib/exponent-server-sdk-jm.rb', line 138

def handle(response)
  warn '[DEPRECATION] `handle` is deprecated. Please use `process_response` instead.'
  @response = response
  case response.code.to_s
  when /(^4|^5)/
    raise build_error_from_failure
  else
    extract_data
  end
end

#process_response(response) ⇒ Object



122
123
124
125
126
127
128
129
130
131
# File 'lib/exponent-server-sdk-jm.rb', line 122

def process_response(response)
  @response = response

  case response.code.to_s
  when /(^4|^5)/
    raise @error_builder.parse_response(response)
  else
    sort_results
  end
end