Class: Tweedle::Client
- Inherits:
-
Object
- Object
- Tweedle::Client
- 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
-
#config ⇒ Object
readonly
Public: The configuration used by the Tweedle::Client instance.
Instance Method Summary collapse
-
#get(uri, params = {}, &block) ⇒ Object
Internal: Sends a GET request to the given stream.
-
#initialize(config = Tweedle.config) ⇒ Client
constructor
Initializes a new Tweedle::Client.
-
#post(uri, post_data, params = {}, &block) ⇒ Object
Internal: Sends a POST request to the given stream.
-
#statuses ⇒ Object
Returns a new Tweedle::Statuses instance associated with the client.
Constructor Details
Instance Attribute Details
#config ⇒ Object (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 |