Class: Wepawet::Query
- Inherits:
-
Object
- Object
- Wepawet::Query
- Defined in:
- lib/wepawet.rb
Instance Method Summary collapse
- #_parse_response(doc) ⇒ Object
- #by_domain(domain) ⇒ Object
- #by_taskid(taskid) ⇒ Object (also: #by_hash)
- #by_url(url) ⇒ Object
- #by_whatever(whatever, value) ⇒ Object
-
#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', }) ⇒ Query
constructor
A new instance of Query.
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', }) ⇒ Query
Returns a new instance of Query.
67 68 69 70 71 72 73 74 |
# File 'lib/wepawet.rb', line 67 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
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/wepawet.rb', line 103 def _parse_response(doc) xml = XML::Document.string(doc) hash = {} xml.child.children.each do |node| if node.name =~ /\w/ and node.child hash[node.name] = node.child.content end end hash rescue Exception return nil end |
#by_domain(domain) ⇒ Object
95 96 97 |
# File 'lib/wepawet.rb', line 95 def by_domain(domain) by_whatever('domain',domain) end |
#by_taskid(taskid) ⇒ Object Also known as: by_hash
89 90 91 |
# File 'lib/wepawet.rb', line 89 def by_taskid(taskid) by_whatever('hash',taskid) end |
#by_url(url) ⇒ Object
99 100 101 |
# File 'lib/wepawet.rb', line 99 def by_url(url) by_whatever('url', CGI.escape(url)) end |
#by_whatever(whatever, value) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/wepawet.rb', line 76 def by_whatever(whatever, value) params = {'resource_type' => 'js', whatever => value} urlkey = (whatever == 'hash') ? 'wepawetQueryUrl' : (whatever == 'domain') ? 'wepawetDomainUrl' : (whatever == 'url') ? 'wepawetUrlUrl' : 'wepawetQueryUrl' uri = URI.parse(@config[urlkey]+"?"+params.map{|k,v| "#{k}=#{v}"}.join("&")) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = (uri.scheme == 'https') http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(uri.path+"?"+uri.query) request.add_field("User-Agent", "Ruby/#{RUBY_VERSION} wepawet gem v#{Wepawet::VERSION}") response = http.request(request) _parse_response(response.body) end |