gdata_plus 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,27 +8,52 @@ Simple, easy to use GData API that supports OAuth, Ruby 1.8/1.9 and uses Typhoeu
8
8
 
9
9
  gem install gdata_plus
10
10
 
11
+ == Making requests
12
+
13
+ Start by getting the client from the authenticator (see Authentication below).
14
+
15
+ client = authenticator.client
16
+
17
+ Then make a request.
18
+
19
+ response = client.get("https://picasaweb.google.com/data/feed/api/user/default")
20
+
21
+ Then parse the response using your preferred XML library. I'll use {Nokogiri}[http://nokogiri.org/tutorials/searching_a_xml_html_document.html] for this example.
22
+
23
+ feed = Nokogiri::XML(response.body)
24
+ album_titles = feed.xpath("//xmlns:entry/xmlns:title/text()").collect {|i| "#{i}"}
25
+
26
+ If you need more control over the request, then you can create your own {Typhoeus}[https://github.com/pauldix/typhoeus] request and submit it to the client.
27
+
28
+ request = Typhoeus::Request.new(...)
29
+ client.submit request
30
+
11
31
  == Authentication
12
32
 
33
+ {OAuth}[http://code.google.com/apis/gdata/docs/auth/oauth.html] and {ClientLogin}[http://code.google.com/apis/gdata/docs/auth/clientlogin.html] are supported. OAuth is preferred for web apps and ClientLogin is convenient for installed apps and command-line utilities.
34
+
13
35
  === OAuth
14
36
 
15
- TODO
37
+ Before using OAuth, you will need to {register your domain}[http://code.google.com/apis/accounts/docs/RegistrationForWebAppsAuto.html] and get a consumer key and consumer secret from Google. See {the OAuth example}[https://github.com/balexand/gdata_plus/blob/master/examples/oauth_example.rb] for getting started with OAuth.
16
38
 
17
39
  ==== Using an existing access token
18
40
 
19
- TODO
41
+ If you already have an access token and access token secret, then you can construct an OAuth authenticator as follows:
42
+
43
+ GDataPlus::Authenticator::OAuth.new(
44
+ :consumer_key => CONSUMER_KEY,
45
+ :consumer_secret => CONSUMER_SECRET,
46
+ :access_token => access_token,
47
+ :access_secret => access_secret
48
+ )
20
49
 
21
50
  === ClientLogin
22
51
 
23
- TODO
52
+ See the {ClientLogin example}[https://github.com/balexand/gdata_plus/blob/master/examples/client_login_example.rb].
24
53
 
25
54
  === Serializing authenticators
26
55
 
27
- TODO
28
-
29
- == Making requests
30
-
31
- TODO
56
+ Both the OAuth and ClientLogin authenticators can be serialized using a method like to_yaml.
32
57
 
33
58
  == Error handling
34
59
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
@@ -1,6 +1,8 @@
1
+ # Highline is required for this example: gem install highline
2
+
1
3
  require 'rubygems'
2
4
  require 'gdata_plus'
3
- require 'highline/import' # gem install highline
5
+ require 'highline/import'
4
6
  require 'typhoeus'
5
7
 
6
8
  # prompt for email/password
@@ -11,5 +13,6 @@ password = ask("Enter your password: ") { |q| q.echo = "x" }
11
13
  authenticator = GDataPlus::Authenticator::ClientLogin.new(:service => "lh2", :source => "balexand-gdata_plus-1")
12
14
  authenticator.authenticate(email, password)
13
15
 
16
+ # Make a signed request (fetch a list of Picasa albums in this case)
14
17
  response = authenticator.client.get("https://picasaweb.google.com/data/feed/api/user/default")
15
18
  puts response.inspect
@@ -1,7 +1,6 @@
1
- # you don't need the following line if you've installed the gem
2
- $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3
-
1
+ require 'rubygems'
4
2
  require 'gdata_plus'
3
+ require 'nokogiri'
5
4
  require 'sinatra'
6
5
  require 'typhoeus'
7
6
 
@@ -9,29 +8,33 @@ require 'typhoeus'
9
8
  CONSUMER_KEY = ENV["GDATA_CONSUMER_KEY"]
10
9
  CONSUMER_SECRET = ENV["GDATA_CONSUMER_SECRET"]
11
10
 
12
- set :sessions, true # enable Sinatra sessions
11
+ set :sessions, true
13
12
 
13
+ # STEP #1: Obtain and store request token, and redirect browser to Google for authorization
14
14
  get "/" do
15
15
  oauth_callback = "#{request.scheme}://#{request.host}:#{request.port}/callback"
16
16
 
17
17
  authenticator = GDataPlus::Authenticator::OAuth.new(:consumer_key => CONSUMER_KEY, :consumer_secret => CONSUMER_SECRET)
18
18
  request_token = authenticator.fetch_request_token(:scope => "https://picasaweb.google.com/data/", :oauth_callback => oauth_callback)
19
19
 
20
- # store authenticator in the session since we'll need it when exchanging request token for an access token
21
20
  session[:gdata_authenticator] = authenticator
22
21
 
23
22
  redirect request_token.authorize_url
24
23
  end
25
24
 
25
+ # STEP #2: Exchange request token for access token when user is redirected back to your site
26
26
  get "/callback" do
27
27
  authenticator = session[:gdata_authenticator]
28
28
  authenticator.fetch_access_token(params[:oauth_verifier])
29
29
  redirect "/picasa_album_list"
30
30
  end
31
31
 
32
+ # STEP #3: Make a signed request (fetch a list of Picasa albums in this case)
32
33
  get "/picasa_album_list" do
33
34
  authenticator = session[:gdata_authenticator]
34
35
  response = authenticator.client.get("https://picasaweb.google.com/data/feed/api/user/default")
35
36
 
36
- response.inspect
37
+ feed = Nokogiri::XML(response.body)
38
+ album_titles = feed.xpath("//xmlns:entry/xmlns:title/text()").collect {|i| "#{i}"}
39
+ album_titles.collect {|title| "<li>#{title}</li>"}
37
40
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gdata_plus}
8
- s.version = "0.0.0"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brian Alexander"]
12
- s.date = %q{2010-12-31}
12
+ s.date = %q{2011-01-02}
13
13
  s.description = %q{Simple, easy to use GData API that supports OAuth, Ruby 1.8/1.9 and uses Typhoeus as an HTTP client}
14
14
  s.email = %q{balexand@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 1
7
8
  - 0
8
- - 0
9
- version: 0.0.0
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Brian Alexander
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-31 00:00:00 -08:00
17
+ date: 2011-01-02 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -184,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - ">="
186
186
  - !ruby/object:Gem::Version
187
- hash: -4078657378247043019
187
+ hash: 2629317293349709897
188
188
  segments:
189
189
  - 0
190
190
  version: "0"