Class: Wepawet::Submit
- Inherits:
-
Object
- Object
- Wepawet::Submit
- Defined in:
- lib/wepawet.rb
Overview
Wepawet::Submit is used to submit new files and/or URLs into the wepawet system.
Instance Method Summary collapse
-
#initialize(config = { 'wepawetSubmitUrl' => 'http://wepawet.cs.ucsb.edu/services/upload.php', 'wepawetQueryUrl' => 'http://wepawet.cs.ucsb.edu/services/query.php', 'wepawetDomainUrl' => 'http://wepawet.cs.ucsb.edu/services/domain.php', 'wepawetUrlUrl' => 'http://wepawet.cs.ucsb.edu/services/url.php', }) ⇒ Submit
constructor
A new instance of Submit.
- #parse_response(doc) ⇒ Object
- #submit_file(filename, resource_type = 'js') ⇒ Object
-
#submit_url(url, resource_type = 'js') ⇒ Object
Wepawet::Submit#submit_url(url) submits a new URL to the wepawet system and returns a task ID (a hash).
Constructor Details
#initialize(config = { 'wepawetSubmitUrl' => 'http://wepawet.cs.ucsb.edu/services/upload.php', 'wepawetQueryUrl' => 'http://wepawet.cs.ucsb.edu/services/query.php', 'wepawetDomainUrl' => 'http://wepawet.cs.ucsb.edu/services/domain.php', 'wepawetUrlUrl' => 'http://wepawet.cs.ucsb.edu/services/url.php', }) ⇒ Submit
Returns a new instance of Submit.
14 15 16 17 18 19 20 21 |
# File 'lib/wepawet.rb', line 14 def initialize(config = { 'wepawetSubmitUrl' => 'http://wepawet.cs.ucsb.edu/services/upload.php', 'wepawetQueryUrl' => 'http://wepawet.cs.ucsb.edu/services/query.php', 'wepawetDomainUrl' => 'http://wepawet.cs.ucsb.edu/services/domain.php', 'wepawetUrlUrl' => 'http://wepawet.cs.ucsb.edu/services/url.php', }) @config = config end |
Instance Method Details
#parse_response(doc) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/wepawet.rb', line 57 def parse_response(doc) xml = XML::Document.string(doc) h = xml.find("hash") h[0].child.to_s rescue Exception return nil end |
#submit_file(filename, resource_type = 'js') ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/wepawet.rb', line 23 def submit_file(filename, resource_type='js') params = {'resource_type' => resource_type} ['user','passwd','referer'].each do |opt| params[opt] = @config[opt] if @config[opt] end file = File.open(filename) params['file'] = UploadIO.new(file, "application/octet-stream", File.basename(filename)) uri = URI.parse(@config['wepawetSubmitUrl']) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = (uri.scheme == 'https') http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post::Multipart.new(uri.path, params) request.add_field("User-Agent", "Ruby/#{RUBY_VERSION} wepawet gem v#{Wepawet::VERSION}") response = http.request(request) parse_response(response.body) end |
#submit_url(url, resource_type = 'js') ⇒ Object
Wepawet::Submit#submit_url(url) submits a new URL to the wepawet system and returns a task ID (a hash).
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/wepawet.rb', line 41 def submit_url(url, resource_type='js') params = {'resource_type' => resource_type, 'url' => url} ['user','passwd','referer'].each do |opt| params[opt] = @config[opt] if @config[opt] end uri = URI.parse(@config['wepawetSubmitUrl']) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = (uri.scheme == 'https') http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new(uri.path) request.set_form_data(params) request.add_field("User-Agent", "Ruby/#{RUBY_VERSION} wepawet gem v#{Wepawet::VERSION}") response = http.request(request) parse_response(response.body) end |