Class: WikiLeaks

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/cablegator/wikileaks.rb

Constant Summary collapse

PROXY_URL =
'localhost'
PROXY_PORT =
8118
HOME =
'/cablegate.html'

Class Method Summary collapse

Class Method Details

.reference_id(cable_url) ⇒ Object



22
23
24
# File 'lib/cablegator/wikileaks.rb', line 22

def reference_id(cable_url)
  File.basename(cable_url).gsub(File.extname(cable_url),'') 
end

.with_each_cableObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cablegator/wikileaks.rb', line 26

def with_each_cable
  doc = Nokogiri::HTML(self.get(HOME))
  doc.css(%{a[href^='/date']}).each do |link|
  cable_url = link.attributes['href'].value
    page_with_cables = Nokogiri::HTML(WikiLeaks.get(cable_url))
    page_with_cables.css(%{a[href^='/cable']}).each do |cable|
      cable_url = cable.attributes['href'].value
      yield cable_url
    end
  end
end

.with_each_cable_dataObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cablegator/wikileaks.rb', line 38

def with_each_cable_data
  doc = Nokogiri::HTML(self.get(HOME))
  doc.css(%{a[href^='/date']}).each do |link|
    cable_url = link.attributes['href'].value
    begin
      page_with_cables = Nokogiri::HTML(WikiLeaks.get(cable_url))
      page_with_cables.css(%{table.cable tr:has(td)}).each do |cable|
        cable_hash = {}	
        #cable_hash['cable_url'] = cable.css(%{a[href='/cable']}).first.attributes['href'].value
        children = cable.element_children.map{ |x| x.text.strip }
        cable_hash['reference_id'] = children[0]	  
        cable_hash['subject'] = children[1]	  
        cable_hash['origin_date'] =  children[2]	  
        cable_hash['release_date'] = children[3]	  
        cable_hash['classification'] = children[4]
        cable_hash['location'] = children[5]
        yield cable_hash
      end
    rescue
      STDOUT.puts "error GETtin page #{cable_url}"
    end
  end
end