Class: Greedy::Connection
- Inherits:
-
Object
- Object
- Greedy::Connection
- Defined in:
- lib/greedy/connection.rb
Constant Summary collapse
- BASE_URL =
"http://www.google.com/reader/api/0/"
Instance Method Summary collapse
-
#connected? ⇒ Boolean
Determine the status of the connection.
-
#fetch(path, options = {}) ⇒ Object
Issue a GET HTTP request to the Google Reader API Example connection.fetch “stream/contents/user/-/state/com.google/unread”, :c => ‘976H987BKU’.
-
#initialize(username, password, appname = "Greedy") ⇒ Connection
constructor
Create a new connection to the Google Reader API Example: Greedy::Connection.new ‘username’, ‘password’, ‘my aggregator application’.
-
#post(path, form_data = {}) ⇒ Object
Issue a POST HTTP request to the Google Reader API Example: connection.fetch “stream/contents/user/-/state/com.google/edit-tag”, :form_data => { :async => false, :a => ‘broadcast’ }.
Constructor Details
#initialize(username, password, appname = "Greedy") ⇒ Connection
Create a new connection to the Google Reader API Example:
Greedy::Connection.new 'username', 'password', 'my aggregator application'
8 9 10 11 12 13 |
# File 'lib/greedy/connection.rb', line 8 def initialize(username, password, appname = "Greedy") @username = username @password = password @application_name = appname connect! end |
Instance Method Details
#connected? ⇒ Boolean
Determine the status of the connection
46 47 48 |
# File 'lib/greedy/connection.rb', line 46 def connected? !@client.nil? end |
#fetch(path, options = {}) ⇒ Object
Issue a GET HTTP request to the Google Reader API Example
connection.fetch "stream/contents/user/-/state/com.google/unread", :c => '976H987BKU'
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/greedy/connection.rb', line 18 def fetch(path, = {}) url = [full_path(path), convert_to_querystring()].join response = @client.get url JSON.parse response.body rescue GData::Client::RequestError => e if Greedy::AuthorizationError.gdata_errors.include?(e.class.to_s) raise Greedy::AuthorizationError.new(e.) else raise Greedy::ServiceError.new(e.) end end |
#post(path, form_data = {}) ⇒ Object
Issue a POST HTTP request to the Google Reader API Example:
connection.fetch "stream/contents/user/-/state/com.google/edit-tag", :form_data => { :async => false, :a => 'broadcast' }
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/greedy/connection.rb', line 33 def post(path, form_data = {}) uri = [full_path(path), convert_to_querystring(:client => @application_name)].join response = @client.post uri, convert_to_post_body(form_data) JSON.parse response.body rescue GData::Client::RequestError => e if Greedy::AuthorizationError.gdata_errors.include?(e.class.to_s) raise Greedy::AuthorizationError.new(e.) else raise Greedy::ServiceError.new(e.) end end |