Sha256: df7e36c6f7a7ce44127f6f1a9b75c5c803573c05c5eadecdfebfceacd5bd7e6e

Contents?: true

Size: 884 Bytes

Versions: 6

Compression:

Stored size: 884 Bytes

Contents

module Gnip
  class Message
    SYSTEM_MESSAGE_TYPES = ['error', 'warn', 'info']

    def self.build params
      return build_system_message(params) if (SYSTEM_MESSAGE_TYPES & params.keys).any?
      return build_activity(params) if params['objectType'] && params['objectType'] == 'activity'
      raise Gnip::UndefinedMessage
    end

    def system_message?
      @message_type ? true : false
    end

    def error?
      @message_type == 'error'
    end
    
    def warn?
      @message_type == 'warn'
    end
    
    def info?
      @message_type == 'info'
    end

    def activity?
      @object_type == 'activity'
    end
    
    def generate_json data
      JSON.generate(data)
    end

    private
    def self.build_system_message params
      Gnip::SystemMessage.new params
    end

    def self.build_activity params
      Gnip::Activity.new params
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gnip_api-0.0.7 lib/gnip_api/gnip/message.rb
gnip_api-0.0.6 lib/gnip_api/gnip/message.rb
gnip_api-0.0.5 lib/gnip_api/gnip/message.rb
gnip_api-0.0.4 lib/gnip_api/gnip/message.rb
gnip_api-0.0.3 lib/gnip_api/gnip/message.rb
gnip_api-0.0.2 lib/gnip_api/gnip/message.rb