This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# access an http basic feed. You can't do this in a bulk feed get. It has to be when getting only one. | |
Feedzirra::Feed.fetch_and_parse(some_url, :http_authentication => ["username", "password"]) | |
# You can add custom parsing to the feed entry classes. Say you want the wfw:comments fields in an entry | |
Feedzirra::Feed.add_common_feed_entry_element("wfw:commentRss", :as => :comment_rss) | |
# The arguments are the same as the SAXMachine arguments for the element method. For more example usage look at the RSSEntry and | |
# AtomEntry classes. Now you can access those in an atom feed: | |
Feedzirra::Feed.parse(some_atom_xml).entries.first.comment_rss_ # => wfw:commentRss is now parsed! | |
# and the new accessors for feed entries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a code example for the Ruby HTTP library Typhoeus | |
# here's an example for twitter search | |
# Including Typhoeus adds http methods like get, put, post, and delete. | |
# What's more interesting though is the stuff to build up what I call | |
# remote_methods. | |
class Twitter | |
include Typhoeus | |
remote_defaults :on_success => lambda {|response| JSON.parse(response.body)}, | |
:on_failure => lambda {|response| puts "error code: #{response.code}"}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'json' | |
require 'typhoeus' | |
require 'net/http' | |
class CouchDB | |
include Typhoeus | |
remote_defaults :on_success => lambda {|response| JSON.parse(response.body)}, | |
:on_failure => lambda {|response| puts "error code: #{response.code}"}, | |
:base_uri => "http://127.0.0.1:5984/couch-test-db" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this shows how to use the update functionality for a single feed with feedzirra | |
require 'rubygems' | |
require 'feedzirra' | |
# I'm using Atom here, but it could be anything. You don't need to know ahead of time. | |
# It will parse out to the correct format when it updates. | |
feed_to_update = Feedzirra::Parser::Atom.new | |
feed_to_udpate.feed_url = some_stored_feed_url | |
feed_to_update.etag = some_stored_feed_etag | |
feed_to_update.last_modified = some_stored_feed_last_modified |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hydra = Typhoeus::Hydra.new(3) | |
@responses = [] | |
start_time = Time.now | |
request = Typhoeus::Request.new(:method => :get, :host => "localhost:3000", :path => "/first", :query_string => "delay=1") | |
request.when_complete do | |
@responses << request.response | |
YAML.load(request.response.body)[:path_info].should == "/first" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hydra = Typhoeus::Hydra.new(20) # number is the size of the easy object pool | |
user_request = User.find_request(1) # where 1 is the id of the user | |
user_request.when_complete do | |
@user = User.parse(user_request.response.body) | |
comment_requests = @user.comment_ids.map {|id| Comment.find_request(id)} | |
comment_requests.each do |comment_request| | |
comment_request.when_complete do | |
@user.comments << Comment.parse(comment_request.response.body) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User | |
def initialize(attrs = {}) | |
# do stuff here | |
end | |
def self.find_request(id) | |
request = Typhoeus::Request.new(:method => :get, | |
:host => "localhost:3000", | |
:path => "/users/#{id}") | |
request.on_complete do |response| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# single json object cache miss (passenger) | |
ab -n 10000 -c 50 http://ec2-some-ip.compute-1.amazonaws.com/api/v1/comments/1/no_cache | |
This is ApacheBench, Version 2.3 <$Revision: 655654 $> | |
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ | |
Licensed to The Apache Software Foundation, http://www.apache.org/ | |
Benchmarking ec2-some-ip.compute-1.amazonaws.com (be patient) | |
Completed 1000 requests | |
Completed 2000 requests | |
Completed 3000 requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'typhoeus' | |
require 'yajl/json_gem' | |
hydra = Typhoeus::Hydra.new | |
request = Typhoeus::Request.new('http://localhost:8089/?id=timeline', :method => :post, :body => stuff.to_json) | |
request.on_complete do |response| | |
response.code # http status | |
response.body | |
response.time # time taken in seconds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/usr/local/lib/ruby/gems/1.9.1/gems/typhoeus-0.1.6/lib/typhoeus/multi.rb:20: [BUG] Segmentation fault | |
ruby 1.9.1p243 (2009-07-16 revision 24175) [i686-linux] | |
-- control frame ---------- | |
c:0007 p:---- s:0019 b:0019 l:000018 d:000018 CFUNC :multi_perform | |
c:0006 p:0019 s:0016 b:0016 l:000015 d:000015 METHOD /usr/local/lib/ruby/gems/1.9.1/gems/typhoeus-0.1.6/lib/typhoeus/multi.rb:20 | |
c:0005 p:0023 s:0013 b:0013 l:000012 d:000012 METHOD /usr/local/lib/ruby/gems/1.9.1/gems/typhoeus-0.1.6/lib/typhoeus/hydra.rb:56 | |
c:0004 p:0023 s:0010 b:0010 l:000009 d:000009 METHOD source_worker.rb:39 | |
c:0003 p:0143 s:0007 b:0007 l:0020bc d:0018d8 EVAL source_worker.rb:152 | |
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH |