Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS 

wsdl the google API (search google with ruby)

sign up to get a key first

   1  
   2  require 'soap/wsdlDriver'
   3  $KCODE = "UTF8"
   4  key = 'LVJnAm5QFHblahblahblah your key here'
   5  
   6  #create driver
   7  wsdl = "http://api.google.com/GoogleSearch.wsdl"
   8  driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
   9  query = "your query string here"
  10  start = 0
  11  max = 10
  12    
  13  # see http://dev.ctor.org/soap4r/browser/trunk/sample/wsdl/googleSearch/wsdlDriver.rb
  14  @results = driver.doGoogleSearch( key, query, start, max, true, "", true, 'lang_en', '','')
  15  snippets = @results.resultElements.collect { |r| r.snippet } # you can get all kinds'a' info here
  16  self.update_attribute(:html, snippets.join("\n")) # or whatever

find the http-auth username in rails

in lighttpd
   1  
   2   auth.backend = your_preferred_method
   3   auth.backend.your_method.userfile = "yourfile.password"
   4   auth.require = ("/" => ("method" => "digest", "realm" => "your site", "require"=>"valid-user" ) )
   5  


in rails
   1  
   2  @request.env["HTTP_AUTHORIZATION"].scan(/Digest username=\W+["]?([a-z0-9]+)/i).to_s

rdoc the edge rails source

   1  
   2   cd vendor/rails
   3   svn up
   4   rdoc --inline-source -x railties/lib/rails_generator/generators/components/controller/templates/controller.rb --all --tab-width 2  --title 'Rails Edge API documentation'


there's a bug in one of the methods that you have to skip, in order for it to run properly.

lol

or

   1  
   2  rake reapidoc

(edited)

Using xpath to test the rails

Originally posted in #rubyonrails by ? springjp

   1  
   2  def test_account_list
   3      #  There should be some accounts to test
   4      assert @ttrueheart.accounts.count > 0
   5   
   6      @request.session[:user] = @ttrueheart
   7      get :list
   8      assert_success
   9   
  10      xml = nil
  11      assert_nothing_thrown { xml = REXML::Document.new(@response.body) }
  12   
  13      @ttrueheart.accounts.each do |account|
  14        td = REXML::XPath.match(xml, "//td[text()=\"#{account.display_string}\"]")
  15        assert_equal(1, td.size)  # Unique entry
  16   
  17        assert_equal(3, REXML::XPath.match(td, 'following-sibling::td/a').size)
  18   
  19        href = REXML::XPath.match(td, "following-sibling::td/a[@href='/account/activity_list/#{account.id}']")
  20        assert_equal(1, href.size)
  21   
  22        href = REXML::XPath.match(td, "following-sibling::td/a[@href='/account/edit/#{account.id}']")
  23        assert_equal(1, href.size)
  24   
  25        href = REXML::XPath.match(td, "following-sibling::td/a[@href='/account/delete/#{account.id}']")
  26        assert_equal(1, href.size)
  27      end
  28    end
« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS