Module: OpenTrackerWsHelpers

Included in:
OpenTrackerWs
Defined in:
lib/helpers.rb

Instance Method Summary collapse

Instance Method Details

#dynamic_content(data) ⇒ Object



12
13
14
15
16
# File 'lib/helpers.rb', line 12

def dynamic_content(data)
  content_type 'application/json', :charset => 'utf-8'

  return data.to_json
end

#torrent_stats(hash) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/helpers.rb', line 34

def torrent_stats(hash)
  response = {}
  if data = prepare_data(hash)
    response['seeders'] = get_seeders(data)
    response['leechers'] = get_leechers(data)
    response['downloaded'] = get_downloaded(data)
  end
  
  return response
end

#tracker_statsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/helpers.rb', line 18

def tracker_stats
  config = load_config
  doc = Nokogiri::XML(open(
    "http://#{config['opentracker']['host']}:#{config['opentracker']['port']}" +
      "/stats?mode=everything"
    )
  )
  response = {}
  response['uptime'] = doc.search('stats uptime').text
  response['peers'] = doc.search('stats peers count').text
  response['seeds'] = doc.search('stats seeds count').text
  response['completed'] = doc.search('stats completed count').text

  return response
end