Skip to content

Instantly share code, notes, and snippets.

@cantremember
Created March 23, 2012 05:31
Show Gist options
  • Save cantremember/2167260 to your computer and use it in GitHub Desktop.
Save cantremember/2167260 to your computer and use it in GitHub Desktop.
a little patch to Twitter4R for Twitter Search API
@@config_mutex = Mutex.new
def configuration_mutex
@@config_mutex
end
alias :raw_http_connect :http_connect
def http_connect(*args, &block)
ops = (Hash === args.last) ? args.pop : {}
result = nil
self.configuration_mutex.synchronize do
ops[:call_before].call if ops[:call_before]
result = raw_http_connect *args, &block
ops[:call_after].call if ops[:call_after]
end
result
end
#
# ...
#
@@SEARCH_CONNECT_HOOKS = {
:call_before => lambda { self.configure_apply(:search) },
:call_after => lambda { self.configure_apply(:default) },
}
#
# ...
#
# broken out of closure for mocking
req = create_http_get_request(uri, params)
response = http_connect(@@SEARCH_CONNECT_HOOKS) {|conn| req }
return nil unless Net::HTTPOK === response
model = bless_model(Twitter::Search.unmarshal(response.body))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment