Sha256: 130875b3318547259507f661065d55e2bd3cd37dd5b426633a29c8ece204035f

Contents?: true

Size: 901 Bytes

Versions: 8

Compression:

Stored size: 901 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
      GnipApi::JsonParser.new.encode(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

8 entries across 8 versions & 1 rubygems

Version Path
gnip_api-1.0.6 lib/gnip_api/gnip/message.rb
gnip_api-1.0.5 lib/gnip_api/gnip/message.rb
gnip_api-1.0.4 lib/gnip_api/gnip/message.rb
gnip_api-1.0.3 lib/gnip_api/gnip/message.rb
gnip_api-1.0.2 lib/gnip_api/gnip/message.rb
gnip_api-1.0.1 lib/gnip_api/gnip/message.rb
gnip_api-1.0.0 lib/gnip_api/gnip/message.rb
gnip_api-0.0.9 lib/gnip_api/gnip/message.rb