Created
March 23, 2012 05:31
-
-
Save cantremember/2167260 to your computer and use it in GitHub Desktop.
a little patch to Twitter4R for Twitter Search API
This file contains hidden or 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
@@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