Class: Tweedle::Statuses

Inherits:
Object
  • Object
show all
Defined in:
lib/tweedle/statuses.rb

Overview

Public: Wraps all generic Twitter Streaming API methods.

Constant Summary collapse

SERVER =

Public: The Twitter Stream server used by Tweedle::Statuses.

"https://stream.twitter.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Statuses

Initializes a new Tweedle::Statuses instance.

client - The Tweedle::Client used by the instance.

Examples

Tweedle::Statuses.new
# => Tweedle::Statuses

Tweedle::Statuses.new(client_instance)
# => Tweedle::Statuses

Returns a Tweedle::Statuses instance.



23
24
25
# File 'lib/tweedle/statuses.rb', line 23

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Public: The Tweedle::Client used by the Tweedle::Statuses instance.



8
9
10
# File 'lib/tweedle/statuses.rb', line 8

def client
  @client
end

Instance Method Details

#filter(params) ⇒ Object

Returns public statuses that match one or more filter predicates. At least one predicate parameter, follow, locations, or track must be specified. Multiple parameters may be specified.

The default access level allows up to 400 track keywords, 5,000 follow userids and 25 0.1-360 degree location boxes.

This method uses a POST request to submit the filter predicates to the Twitter Streaming API.

params - Hash containing the request parameters and filter predicates.

Examples:

predicates = {
 locations: [-122.75, 36.8, -121.75, 37.8, -74,40, -73,41],
     track: ["ruby", "tweedle"]
}

filter(predicates: predicates) do |body|
  next unless text = tweet[:text]
  puts "#{tweet[:user][:screen_name]}: #{text}"
end

filter(predicates: predicates, count: 100, stall_warnings: true) do |body|
  next unless text = tweet[:text]
  puts "#{tweet[:user][:screen_name]}: #{text}"
end

Returns nothing. Raises Tweedle::ConnectionError if the server response is not an

Net::HTTPSuccess.


143
144
145
146
147
148
# File 'lib/tweedle/statuses.rb', line 143

def filter(params)
  predicates = params.delete(:predicates)
  post("/1/statuses/filter.json", predicates, params) do |body|
    yield body if block_given?
  end
end

#firehose(params = {}) ⇒ Object

Returns all public statuses. The Firehose is not a generally available resource.

params - Hash containing request parameters (default: empty Hash).

Examples

firehose(stall_warnings: true) do |body|
  next unless text = tweet[:text]
  puts "#{tweet[:user][:screen_name]}: #{text}"
end

Returns nothing. Raises Tweedle::ConnectionError if the server response is not an

Net::HTTPSuccess.


83
84
85
86
87
# File 'lib/tweedle/statuses.rb', line 83

def firehose(params = {})
  get("/1/statuses/firehose.json", params) do |body|
    yield body if block_given?
  end
end

Returns all statuses containing http: and https:. The links stream is not a generally available resource.

params - Hash containing request parameters (default: empty Hash).

Examples

links(stall_warnings: true) do |body|
  next unless text = tweet[:text]
  puts "#{tweet[:user][:screen_name]}: #{text}"
end

Returns nothing. Raises Tweedle::ConnectionError if the server response is not an

Net::HTTPSuccess.


42
43
44
45
46
# File 'lib/tweedle/statuses.rb', line 42

def links(params = {})
  get("/1/statuses/links.json", params) do |body|
    yield body if block_given?
  end
end

#retweet(params = {}) ⇒ Object

Returns all retweets. The retweet stream is not a generally available resource.

params - Hash containing request parameters (default: empty Hash).

Examples

retweet(stall_warnings: true) do |body|
  next unless text = tweet[:text]
  puts "#{tweet[:user][:screen_name]}: #{text}"
end

Returns nothing. Raises Tweedle::ConnectionError if the server response is not an

Net::HTTPSuccess.


104
105
106
107
108
# File 'lib/tweedle/statuses.rb', line 104

def retweet(params = {})
  get("/1/statuses/retweet.json", params) do |body|
    yield body if block_given?
  end
end

#sample(params = {}) ⇒ Object

Returns a random sample of all public statuses.

params - Hash containing request parameters (default: empty Hash).

Examples

sample(stall_warnings: true) do |body|
  next unless text = tweet[:text]
  puts "#{tweet[:user][:screen_name]}: #{text}"
end

Returns nothing. Raises Tweedle::ConnectionError if the server response is not an

Net::HTTPSuccess.


62
63
64
65
66
# File 'lib/tweedle/statuses.rb', line 62

def sample(params = {})
  get("/1/statuses/sample.json", params) do |body|
    yield body if block_given?
  end
end