class ConnectClient::EventPushResponse

Attributes

data[R]
http_status_code[R]

Public Class Methods

new(code, content_type, response_body, events_pushed) click to toggle source
# File lib/connect_client/event_push_response.rb, line 8
def initialize(code, content_type, response_body, events_pushed)
  @http_status_code = code.to_s

  if content_type.include? 'application/json'
    body = response_body
    body = '{}' if response_body.to_s.empty?
    parse_body(body, events_pushed)
  else
    @data = response_body
  end
end

Public Instance Methods

success?() click to toggle source
# File lib/connect_client/event_push_response.rb, line 20
def success?
  @http_status_code.start_with? '2'
end
to_s() click to toggle source
# File lib/connect_client/event_push_response.rb, line 24
def to_s
  %{
    Status: #{@http_status_code}
    Successful: #{success?}
    Data: #{data}
  }
end

Private Instance Methods

parse_body(body, events_pushed) click to toggle source
# File lib/connect_client/event_push_response.rb, line 34
def parse_body(body, events_pushed)
  @data = JSON.parse(body, :symbolize_names => true)

  if (events_pushed.is_a?(Hash) && @data.is_a?(Hash))
    @data.merge!(events_pushed) do |collection_name, responses, events|
      responses.zip(events).map do |response, event|
        response[:event] = event.data 
        response
      end
    end
  else
    @data[:event] = events_pushed.data
  end
end