Sha256: 73368d090560ec0f22843a8f43a1b4ea84be5305ff54c5ba74e435cca958f5ca

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

module Gnip
  class Message
    SYSTEM_MESSAGE_TYPES = ['error', 'warn', 'info']
    TWITTER_COMPLIANCE_MESSAGES = ['delete', 'user_delete', 'user_undelete', 'scrub_geo', 
                                   'user_protect', 'user_unprotect', 'user_suspend', 'user_unsuspend',
                                   'user_withheld', 'status_withheld']

    def self.build params
      return build_system_message(params) if (SYSTEM_MESSAGE_TYPES & params.keys).any?
      return build_twitter_compliance_message(params) if TWITTER_COMPLIANCE_MESSAGES.include? params['verb']
      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_twitter_compliance_message params
      Gnip::TwitterComplianceMessage.new params
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gnip_api-1.1.0 lib/gnip_api/gnip/message.rb