Class: Gnip::Historical::Powertrack

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/gnip-rules/historical/powertrack.rb

Constant Summary collapse

JOB_URL_PATH =

debug_output $stdout

"/jobs"
JOBS_URL_PATH =
"/jobs"

Instance Method Summary collapse

Constructor Details

#initialize(configuration = nil, username = nil, password = nil, uri = nil, timeout = 60) ⇒ Powertrack

Returns a new instance of Powertrack.



22
23
24
25
26
27
28
29
30
31
32
33
34
# 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

Instance Method Details

#accept(uuid) ⇒ Object



59
60
61
62
# 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) ⇒ Object



45
46
47
48
49
50
51
52
53
# 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) ⇒ Object



36
37
38
39
# 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) ⇒ Object



69
70
71
# File 'lib/gnip-rules/historical/powertrack.rb', line 69

def get_results(uuid)
  self.class.get "#{JOB_URL_PATH}/#{uuid}/results"
end

#job(uuid) ⇒ Object



41
42
43
# File 'lib/gnip-rules/historical/powertrack.rb', line 41

def job(uuid)
  self.class.get "#{JOB_URL_PATH}/#{uuid}"
end

#jobsObject



55
56
57
# File 'lib/gnip-rules/historical/powertrack.rb', line 55

def jobs
  self.class.get JOBS_URL_PATH
end

#reject(uuid) ⇒ Object



64
65
66
67
# 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