Class: Tweedle::Client

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

Overview

Public: The Tweedle::Client class wraps methods for accessing sections of the Twitter streaming API and handles all client -> server requests.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = Tweedle.config) ⇒ Client

Initializes a new Tweedle::Client.

config - Options object for the Tweedle client. By default uses

the global Tweedle configuarion (default: Tweedle.config).

Examples

Tweedle::Client.new
# => Tweedle::Client

Tweedle::Client.new(config_object)
# => Tweedle::Client

Returns a Tweedle::Client instance.



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

def initialize(config = Tweedle.config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

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



7
8
9
# File 'lib/tweedle/client.rb', line 7

def config
  @config
end

Instance Method Details

#get(uri, params = {}, &block) ⇒ Object

Internal: Sends a GET request to the given stream.

uri - A String containing the request URI. block - Optional block to yield the response body to. params - Optional request parameters (default: empty Hash)

Examples

get(URI.parse("http://www.google.com/") do |body|
  puts body
end

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

Net::HTTPSuccess.


56
57
58
59
60
61
# File 'lib/tweedle/client.rb', line 56

def get(uri, params = {}, &block)
  uri = build_uri(uri, params)
  http = build_http(uri)
  request = build_get_request(uri, http, params)
  issue_request(http, request, &block)
end

#post(uri, post_data, params = {}, &block) ⇒ Object

Internal: Sends a POST request to the given stream.

uri - A String containing the request URI. block - Optional block to yield the response body to. post_data - Object responding to #to_s containing the data for

the POST request

params - Optional request parameters (default: empty Hash)

Examples

post(URI.parse("http://www.google.com/", "follow=12") do |body|
  puts body
end

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

Net::HTTPSuccess.


80
81
82
83
84
85
# File 'lib/tweedle/client.rb', line 80

def post(uri, post_data, params = {}, &block)
  uri = build_uri(uri, params)
  http = build_http(uri)
  request = build_post_request(uri, http, post_data, params)
  issue_request(http, request, &block)
end

#statusesObject

Returns a new Tweedle::Statuses instance associated with the client.

Examples

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

Returns a Tweedle::Statuses instance.



37
38
39
# File 'lib/tweedle/client.rb', line 37

def statuses
  Tweedle::Statuses.new(self)
end