Class: Discuz::CurlAgent

Inherits:
Object
  • Object
show all
Defined in:
lib/discuz_robot.rb

Instance Method Summary collapse

Constructor Details

#initializeCurlAgent

Returns a new instance of CurlAgent.



42
43
44
45
46
47
48
# File 'lib/discuz_robot.rb', line 42

def initialize
  @cookie_file = "/tmp/c.txt"
  `test #{@cookie_file} && rm #{@cookie_file}`   # remove existing cookie file if any
  
  user_agent  = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6"
  @curl_cmd   = %Q(curl --stderr /dev/null -A "#{user_agent}" -b #{@cookie_file})
end

Instance Method Details

#get(url, options = {}) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/discuz_robot.rb', line 50

def get url, options = {}
  cmd = @curl_cmd
  cmd += " -D #{@cookie_file}" if options[:save_cookie]
  cmd += %Q( "#{url}")
  puts cmd
  %x(#{cmd})
end

#post(url, data, options = {}) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/discuz_robot.rb', line 58

def post url, data, options = {}
  cmd = @curl_cmd
  cmd += " -D #{@cookie_file}" if options[:save_cookie]
  cmd += %Q( -d "#{data}")
  cmd += %Q( "#{url}")
  puts cmd
  %x(#{cmd})
end