Class: TweetStream::SiteStreamClient
- Inherits:
-
Object
- Object
- TweetStream::SiteStreamClient
- Defined in:
- lib/tweetstream/site_stream_client.rb
Instance Method Summary (collapse)
- - (Object) add_user(user_id, &block)
- - (Object) friends_ids(user_id, &block)
- - (Object) info(&block)
-
- (SiteStreamClient) initialize(config_uri, oauth = {})
constructor
A new instance of SiteStreamClient.
- - (Object) on_error(&block)
- - (Object) remove_user(user_id, &block)
Constructor Details
- (SiteStreamClient) initialize(config_uri, oauth = {})
A new instance of SiteStreamClient
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/tweetstream/site_stream_client.rb', line 10 def initialize(config_uri, oauth = {}) @config_uri = config_uri = TweetStream..merge(oauth) Configuration::OAUTH_OPTIONS_KEYS.each do |key| send("#{key}=", [key]) end EventMachine::HttpRequest.use EventMachine::Middleware::JSONResponse end |
Instance Method Details
- (Object) add_user(user_id, &block)
46 47 48 49 |
# File 'lib/tweetstream/site_stream_client.rb', line 46 def add_user(user_id, &block) error_msg = 'Failed to add user to SiteStream' user_management(add_user_path, user_id, error_msg, &block) end |
- (Object) friends_ids(user_id, &block)
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/tweetstream/site_stream_client.rb', line 56 def friends_ids(user_id, &block) error_msg = 'Failed to retrieve SiteStream friends ids.' http = connection.post(:path => friends_ids_path, :body => { 'user_id' => user_id }) http.callback do if http.response_header.status == 200 block.call http.response if block && block.kind_of?(Proc) else @on_error.call(error_msg) if @on_error && @on_error.kind_of?(Proc) end end http.errback do @on_error.call(error_msg) if @on_error && @on_error.kind_of?(Proc) end end |
- (Object) info(&block)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tweetstream/site_stream_client.rb', line 30 def info(&block) error_msg = 'Failed to retrieve SiteStream info.' http = connection.get(:path => info_path) http.callback do if http.response_header.status == 200 block.call http.response if block && block.kind_of?(Proc) else @on_error.call(error_msg) if @on_error && @on_error.kind_of?(Proc) end end http.errback do @on_error.call(error_msg) if @on_error && @on_error.kind_of?(Proc) end end |
- (Object) on_error(&block)
21 22 23 24 25 26 27 28 |
# File 'lib/tweetstream/site_stream_client.rb', line 21 def on_error(&block) if block_given? @on_error = block self else @on_error end end |
- (Object) remove_user(user_id, &block)
51 52 53 54 |
# File 'lib/tweetstream/site_stream_client.rb', line 51 def remove_user(user_id, &block) error_msg = 'Failed to remove user from SiteStream.' user_management(remove_user_path, user_id, error_msg, &block) end |