Module: UrlTracker

Extended by:
UrlTracker
Included in:
UrlTracker
Defined in:
lib/url_tracker.rb,
lib/url_tracker/page.rb,
lib/url_tracker/client.rb,
lib/url_tracker/server.rb,
lib/url_tracker/version.rb,
lib/url_tracker/periodic.rb,
lib/url_tracker/socket_communication.rb

Defined Under Namespace

Modules: SocketCommunication Classes: Client, Page, Periodic, Server

Constant Summary collapse

VERSION =
'1.1'

Instance Method Summary collapse

Instance Method Details

#list_allObject

Returns an array with all URIs currently being tracked



31
32
33
34
35
36
# File 'lib/url_tracker.rb', line 31

def list_all
  init_ivars
  uri_list = @pages.map { |page| page.uri }

  uri_list.empty? ? ',' : uri_list.join(',')
end

#release_uri(uri) ⇒ Object

Stops tracking given URI



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/url_tracker.rb', line 39

def release_uri(uri)
  init_ivars

  p = Page.new(URI(uri))
  if @pages.include?(p)
    @pages.delete(p)
    @scheduler.remove_task(uri)
    'ok'
  else
    'error'
  end
end

#restartObject

Forget about current tracked URIs



53
54
55
56
57
# File 'lib/url_tracker.rb', line 53

def restart
  init_ivars
  @pages.clear
  @scheduler.restart
end

#track_uri(uri, time = 5*60) ⇒ Object

Tracks url fetching its content every time seconds (defaults to 5*60 - 5 minutes).



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/url_tracker.rb', line 17

def track_uri(uri, time = 5*60)
  init_ivars

  p = Page.new(URI(uri))
  
  if @pages.add?(p)
    @scheduler.task(uri).every(:minute) { check_change(p) }
    'ok'
  else
    'error'
  end
end