class Gnip::Historical::Powertrack

Constants

JOBS_URL_PATH
JOB_URL_PATH

debug_output $stdout

Public Class Methods

new( configuration = nil, username = nil, password = nil, uri = nil, timeout = 60 ) click to toggle source
# File lib/gnip-rules/historical/powertrack.rb, line 22
def initialize( configuration = nil, username = nil, password = nil, uri = nil, timeout = 60 )
  @configuration_file = configuration
  unless username && password && uri
    load_credentials!
    username = @config["username"]
    password = @config["password"]
    uri = uri || @config["historical_powertrack_url"]
  end

  self.class.basic_auth username , password
  self.class.base_uri uri
  self.class.default_timeout timeout
end

Public Instance Methods

accept(uuid) click to toggle source
# File lib/gnip-rules/historical/powertrack.rb, line 59
def accept(uuid)
  opts = ActiveSupport::JSON.encode( {status: 'accept'} )
  self.class.put "#{JOB_URL_PATH}/#{uuid}", body: opts
end
create(opts) click to toggle source
# File lib/gnip-rules/historical/powertrack.rb, line 45
def create(opts)
  #dataFormat: 'original'
  #fromDate: 201808280000
  #toDate: 201808290000
  #title: 'Spencer Test DO NOT RUN'
  #rules: []
  job_opts =  ActiveSupport::JSON.encode( opts.merge!({publisher: 'twitter', streamType: 'track_v2', dataFormat: 'activity_streams'}) )
  self.class.post(JOBS_URL_PATH, body: job_opts)
end
default_timeout(timeout) click to toggle source
# File lib/gnip-rules/historical/powertrack.rb, line 36
def default_timeout(timeout)
  self.class.default_timeout timeout
  self.class.default_options
end
get_results(uuid) click to toggle source
# File lib/gnip-rules/historical/powertrack.rb, line 69
def get_results(uuid)
  self.class.get "#{JOB_URL_PATH}/#{uuid}/results"
end
job(uuid) click to toggle source
# File lib/gnip-rules/historical/powertrack.rb, line 41
def job(uuid)
  self.class.get "#{JOB_URL_PATH}/#{uuid}"
end
jobs() click to toggle source
# File lib/gnip-rules/historical/powertrack.rb, line 55
def jobs
  self.class.get JOBS_URL_PATH
end
reject(uuid) click to toggle source
# File lib/gnip-rules/historical/powertrack.rb, line 64
def reject(uuid)
  opts = ActiveSupport::JSON.encode( {status: 'reject'} )
  self.class.put "#{JOB_URL_PATH}/#{uuid}", body: opts
end

Private Instance Methods

environment() click to toggle source
# File lib/gnip-rules/historical/powertrack.rb, line 96
def environment
  if defined?(Rails)
    Rails.env
  elsif defined?(RAILS_ENV)
    RAILS_ENV
  elsif defined?(RACK_ENV)
    RACK_ENV
  else
    :development
  end
end
load_credentials!() click to toggle source
# File lib/gnip-rules/historical/powertrack.rb, line 76
      def load_credentials!
        if File.exists?( @configuration_file )
           @config = YAML.load_file( @configuration_file )[environment.to_s]
        else
          raise Exception.new( <<-RUBY
            You must provide a configuration file at config/gnip.yml

              development: &development
                username: omg@omg.com
                password: your_password
                account: your_account
                streaming_url: 'https://gnip-stream.twitter.com/stream/powertrack/accounts/YOUR_ACCOUNT/publishers/twitter/Sandbox.json'
                rules_api: 'https://gnip-api.twitter.com/rules/powertrack/accounts/YOUR_ACCOUNT/publishers/twitter/Sandbox.json'
                validation_url: 'https://gnip-api.twitter.com/rules/powertrack/accounts/<accountName>/<streamLabel>/validation.json'

          RUBY
          )
        end
      end