douban-ruby 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -10,3 +10,4 @@ coverage
10
10
  html
11
11
  .bundle
12
12
  *.gem
13
+ .loadpath
data/Gemfile CHANGED
@@ -1,8 +1,3 @@
1
1
  source :gemcutter
2
2
 
3
- gem 'oauth'
4
- group :development, :test do
5
- gem 'rspec', '~> 1.3.0'
6
- gem 'rcov'
7
- gem 'rake'
8
- end
3
+ gemspec
@@ -1,16 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ douban-ruby (0.0.8)
5
+ oauth
6
+
1
7
  GEM
2
8
  remote: http://rubygems.org/
3
9
  specs:
4
- oauth (0.4.3)
10
+ diff-lcs (1.1.2)
11
+ oauth (0.4.4)
5
12
  rake (0.8.7)
6
13
  rcov (0.9.9)
7
- rspec (1.3.0)
14
+ rspec (2.3.0)
15
+ rspec-core (~> 2.3.0)
16
+ rspec-expectations (~> 2.3.0)
17
+ rspec-mocks (~> 2.3.0)
18
+ rspec-core (2.3.1)
19
+ rspec-expectations (2.3.0)
20
+ diff-lcs (~> 1.1.2)
21
+ rspec-mocks (2.3.0)
8
22
 
9
23
  PLATFORMS
10
24
  ruby
11
25
 
12
26
  DEPENDENCIES
27
+ bundler (>= 1.0.0)
28
+ douban-ruby!
13
29
  oauth
14
30
  rake
15
31
  rcov
16
- rspec (~> 1.3.0)
32
+ rspec (~> 2.0)
@@ -1,3 +1,8 @@
1
+ === 0.0.8 / 2011-01-02
2
+ * switch to rspec 2
3
+ * Douban::Authorize
4
+ * access_token, request_token support :as_token argument.
5
+
1
6
  === 0.0.7 / 2010-09-23
2
7
  * Douban::Authorize
3
8
  * get_miniblog_comments support start_index and max_results option.
@@ -0,0 +1,72 @@
1
+ = Douban Ruby Client
2
+
3
+ http://github.com/lidaobing/douban-ruby
4
+
5
+ == Description
6
+
7
+ douban ruby client. including OAuth support.
8
+
9
+ * RDoc: http://rubydoc.info/github/lidaobing/douban-ruby/master/frames
10
+ * Douban API reference: http://www.douban.com/service/apidoc/reference/
11
+
12
+ == Installation
13
+
14
+ gem install douban-ruby
15
+
16
+ == Usage
17
+
18
+ === Basic Process
19
+
20
+ require 'douban'
21
+
22
+ douban = Douban::Authorize.new(apikey, secret)
23
+ puts "please open #{douban.get_authorize_url}"
24
+ puts "after login, press Enter to continue"
25
+
26
+ gets
27
+ puts douban.get_people
28
+
29
+ === Async Process (or Server Process)
30
+
31
+ class DoubanController < ApplicationController
32
+ DOUBAN_APIKEY = '0fb6d0a851af01a12f2471f8f50d04e3'
33
+ DOUBAN_SECRET = 'c59e3be2ccdde999'
34
+
35
+ def index
36
+ unless params[:oauth_token]
37
+ unless session[:access_token]
38
+ # step 1, initial state, store request_token to session
39
+ callback_url = url_for :action => :index
40
+ redirect_url = douban.get_authorize_url(callback_url)
41
+ session[:request_token] = douban.request_token :as_token
42
+ redirect_to redirect_url
43
+ else
44
+ # step 3, have access_token, now you can use douban API
45
+ douban.access_token = session[:access_token]
46
+ render :text => douban.get_people.inspect
47
+ end
48
+ else
49
+ if session[:request_token]
50
+ # step 2, return from douban, store access_token to session
51
+ douban.request_token = session[:request_token]
52
+ douban.auth
53
+ reset_session
54
+ session[:access_token] = douban.access_token :as_token
55
+ redirect_to :action => :index
56
+ else
57
+ # error branch, you return from douban, but no request_token in session
58
+ logger.info "return from oauth but no request_token"
59
+ redirect_to :action => :index
60
+ end
61
+ end
62
+ end
63
+
64
+ private
65
+ def douban
66
+ @douban ||= Douban::Authorize.new DOUBAN_APIKEY, DOUBAN_SECRET
67
+ end
68
+ end
69
+
70
+ == LICENSE:
71
+
72
+ licensed under Artistic License or GPL license.
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
- require 'bundler/setup'
3
- require 'spec/rake/spectask'
2
+ require 'bundler'
3
+ Bundler::GemHelper.install_tasks
4
+ require 'rspec/core/rake_task'
4
5
  require 'rake/rdoctask'
5
6
  require File.expand_path("../lib/douban/version", __FILE__)
6
7
 
@@ -8,29 +9,16 @@ ENV["SPEC_OPTS"] ||= "-f nested --color -b"
8
9
  ENV["RDOC_OPTS"] ||= "-c UTF-8"
9
10
 
10
11
 
11
- Spec::Rake::SpecTask.new :spec
12
+ RSpec::Core::RakeTask.new :spec
12
13
  task :default => :spec
13
14
 
14
- namespace :spec do
15
- desc "Run specs with RCov"
16
- Spec::Rake::SpecTask.new('rcov') do |t|
17
- t.spec_files = FileList['spec/**/*_spec.rb' ]
18
- t.rcov = true
19
- t.rcov_opts = ['--exclude' , 'gems,spec' ]
20
- end
15
+ RSpec::Core::RakeTask.new :rcov do |t|
16
+ t.rcov = true
17
+ t.rcov_opts = ['--exclude' , 'gems,spec' ]
21
18
  end
22
19
 
23
20
  Rake::RDocTask.new do |rd|
21
+ rd.main = "README.rdoc"
22
+ rd.rdoc_files.include("README.rdoc", "History.rdoc", "lib/**/*.rb")
24
23
  rd.options << "--charset" << "UTF-8"
25
24
  end
26
-
27
- desc 'build gem file'
28
- task :build do
29
- system "gem build douban-ruby.gemspec"
30
- end
31
-
32
- desc 'upload gem file'
33
- task :release => :build do
34
- system "gem push douban-ruby-#{Douban::VERSION}"
35
- end
36
-
@@ -10,13 +10,16 @@ Gem::Specification.new do |s|
10
10
  s.homepage = "http://rubygems.org/gems/douban-ruby"
11
11
  s.summary = "douban ruby client. including OAuth support."
12
12
  s.description = "Douban API reference: http://www.douban.com/service/apidoc/reference/"
13
+ s.rdoc_options << '--main' << 'README.rdoc' <<
14
+ '--charset' << 'UTF-8'
15
+ s.extra_rdoc_files = ['README.rdoc', 'History.rdoc']
13
16
 
14
17
  s.required_rubygems_version = ">= 1.3.6"
15
18
  s.rubyforge_project = "douban-ruby"
16
19
 
17
20
  s.add_dependency "oauth"
18
21
  s.add_development_dependency "bundler", ">= 1.0.0"
19
- s.add_development_dependency 'rspec', '~> 1.3.0'
22
+ s.add_development_dependency 'rspec', '~> 2.0'
20
23
  s.add_development_dependency 'rake'
21
24
  s.add_development_dependency 'rcov'
22
25
 
@@ -3,6 +3,8 @@
3
3
  # Copyright (c) 2008 Hooopo
4
4
  # Written and maintained by Hooopo<hoooopo@gmail.com>
5
5
  #
6
+ # Copyright (C) 2010-2011 LI Daobing <lidaobing@gmail.com>
7
+ #
6
8
  #
7
9
  # This program is free software. You can re-distribute and/or
8
10
  # modify this program under the same terms of ruby itself ---
@@ -49,5 +51,8 @@
49
51
  #==Install and Wiki
50
52
  # http://code.google.com/p/doubanclient-ruby/
51
53
 
52
- require 'douban/authorize'
54
+
55
+ module Douban
56
+ autoload :Authorize, 'douban/authorize'
57
+ end
53
58
  require 'douban/version'
@@ -1,5 +1,3 @@
1
- require 'rubygems'
2
- gem 'oauth'
3
1
  require 'oauth'
4
2
  require 'oauth/consumer'
5
3
  require 'rexml/document'
@@ -25,8 +23,6 @@ module Douban
25
23
  attr_reader :api_secret
26
24
  attr_reader :authorize_url
27
25
  attr_reader :consumer
28
- attr_reader :request_token
29
- attr_reader :access_token
30
26
 
31
27
  @@debug = false
32
28
 
@@ -1122,6 +1118,23 @@ module Douban
1122
1118
  @request_token = token
1123
1119
  end
1124
1120
 
1121
+
1122
+ # :call-seq:
1123
+ # request_token => OAuth::RequestToken
1124
+ # request_token :as_token => OAuth::Token
1125
+ #
1126
+ # if you want to serialize request_token, use :as_token will be much shorter
1127
+ def request_token(arg=nil)
1128
+ if arg.nil?
1129
+ @request_token
1130
+ elsif arg == :as_token
1131
+ @request_token.nil? ? nil :
1132
+ OAuth::Token.new(@request_token.token, @request_token.secret)
1133
+ else
1134
+ raise ArgumentError
1135
+ end
1136
+ end
1137
+
1125
1138
  def access_token=(token)
1126
1139
  unless token.kind_of? OAuth::AccessToken
1127
1140
  token = OAuth::AccessToken.new(
@@ -1132,6 +1145,22 @@ module Douban
1132
1145
  @access_token = token
1133
1146
  end
1134
1147
 
1148
+ # :call-seq:
1149
+ # access_token => OAuth::AccessToken
1150
+ # access_token :as_token => OAuth::Token
1151
+ #
1152
+ # if you want to serialize access_token, use :as_token will be much shorter
1153
+ def access_token(arg=nil)
1154
+ if arg.nil?
1155
+ @access_token
1156
+ elsif arg == :as_token
1157
+ @access_token.nil? ? nil :
1158
+ OAuth::Token.new(@access_token.token, @access_token.secret)
1159
+ else
1160
+ raise ArgumentError
1161
+ end
1162
+ end
1163
+
1135
1164
  def get_recommendation(id)
1136
1165
  resp=get("/recommendation/#{u(id.to_s)}")
1137
1166
  if resp.code=="200"
@@ -1,3 +1,3 @@
1
1
  module Douban
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -1,4 +1,5 @@
1
- require File.join(File.dirname(__FILE__), '/../spec_helper')
1
+ # -*- encoding: UTF-8 -*-
2
+ require "spec_helper"
2
3
 
3
4
  require 'douban/author'
4
5
 
@@ -1,4 +1,5 @@
1
- require File.join(File.dirname(__FILE__), '/../spec_helper')
1
+ # -*- encoding: UTF-8 -*-
2
+ require "spec_helper"
2
3
 
3
4
  require 'douban/authorize'
4
5
 
@@ -1,4 +1,5 @@
1
- require File.join(File.dirname(__FILE__), '/../spec_helper')
1
+ # -*- encoding: UTF-8 -*-
2
+ require "spec_helper"
2
3
 
3
4
  require 'douban/collection'
4
5
 
@@ -1,4 +1,5 @@
1
- require File.join(File.dirname(__FILE__), '/../spec_helper')
1
+ # -*- encoding: UTF-8 -*-
2
+ require "spec_helper"
2
3
 
3
4
  require 'douban/event'
4
5
 
@@ -1,4 +1,5 @@
1
- require File.join(File.dirname(__FILE__), '/../spec_helper')
1
+ # -*- encoding: UTF-8 -*-
2
+ require "spec_helper"
2
3
 
3
4
  require 'douban/mail'
4
5
 
@@ -1,4 +1,5 @@
1
- require File.join(File.dirname(__FILE__), '/../spec_helper')
1
+ # -*- encoding: UTF-8 -*-
2
+ require "spec_helper"
2
3
 
3
4
  require 'douban/miniblog_comment'
4
5
 
@@ -1,4 +1,5 @@
1
- require File.join(File.dirname(__FILE__), '/../spec_helper')
1
+ # -*- encoding: UTF-8 -*-
2
+ require "spec_helper"
2
3
 
3
4
  require 'douban/miniblog_comments'
4
5
 
@@ -1,11 +1,12 @@
1
- require File.join(File.dirname(__FILE__), '/../spec_helper')
1
+ # -*- encoding: UTF-8 -*-
2
+ require "spec_helper"
2
3
 
3
4
  require 'douban/miniblog'
4
5
 
5
6
  module Douban
6
7
  describe Miniblog do
7
8
  before do
8
- @s = <<eos
9
+ @s = %q{
9
10
  <?xml version="1.0" encoding="UTF-8"?>
10
11
  <entry xmlns="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:opensearch="http://a9.com/-/spec/opensearchrss/1.0/">
11
12
  <id>http://api.douban.com/miniblog/374100199</id>
@@ -20,8 +21,7 @@ module Douban
20
21
  <published>2010-06-30T19:27:41+08:00</published>
21
22
  <content type="html">&amp;lt;b&amp;gt;单元测试0.921892231299059</content>
22
23
  <db:attribute name="comments_count">0</db:attribute>
23
- </entry>
24
- eos
24
+ </entry>}
25
25
  end
26
26
 
27
27
  it "should correct deserialize from string" do
@@ -1,4 +1,5 @@
1
- require File.join(File.dirname(__FILE__), '/../spec_helper')
1
+ # -*- encoding: UTF-8 -*-
2
+ require "spec_helper"
2
3
 
3
4
  require 'douban/note'
4
5
 
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '/../spec_helper')
1
+ require 'spec_helper'
2
2
 
3
3
  require 'douban/page_info'
4
4
 
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '/../spec_helper')
1
+ require 'spec_helper'
2
2
 
3
3
  require 'douban/people'
4
4
 
@@ -1,4 +1,5 @@
1
- require File.join(File.dirname(__FILE__), "/../spec_helper")
1
+ # -*- encoding: UTF-8 -*-
2
+ require "spec_helper"
2
3
 
3
4
  require 'douban/recommendation_comment'
4
5
 
@@ -1,4 +1,5 @@
1
- require File.join(File.dirname(__FILE__), "/../spec_helper")
1
+ # -*- encoding: UTF-8 -*-
2
+ require "spec_helper"
2
3
 
3
4
  require 'douban/recommendation'
4
5
 
@@ -1,4 +1,5 @@
1
- require File.join(File.dirname(__FILE__), "/../spec_helper")
1
+ # -*- encoding: UTF-8 -*-
2
+ require "spec_helper"
2
3
 
3
4
  require 'douban/review'
4
5
 
@@ -1,4 +1,5 @@
1
- require File.join(File.dirname(__FILE__), '/../spec_helper')
1
+ # -*- encoding: UTF-8 -*-
2
+ require "spec_helper"
2
3
 
3
4
  require 'douban/subject'
4
5
 
@@ -1,4 +1,5 @@
1
- require File.join(File.dirname(__FILE__), "/../spec_helper")
1
+ # -*- encoding: UTF-8 -*-
2
+ require "spec_helper"
2
3
 
3
4
  require 'douban/tag'
4
5
 
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '/spec_helper')
1
+ require 'spec_helper'
2
2
 
3
3
  require 'douban'
4
4
 
@@ -1,4 +1,5 @@
1
- $: << File.join(File.dirname(__FILE__), '/../lib')
1
+ require 'rspec'
2
2
 
3
- require 'bundler/setup'
4
- require 'spec'
3
+ RSpec.configure do |c|
4
+ # ....
5
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: douban-ruby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - LI Daobing
@@ -16,10 +16,12 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-09-23 00:00:00 +08:00
19
+ date: 2011-01-02 00:00:00 +08:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
+ name: oauth
24
+ prerelease: false
23
25
  requirement: &id001 !ruby/object:Gem::Requirement
24
26
  none: false
25
27
  requirements:
@@ -30,10 +32,10 @@ dependencies:
30
32
  - 0
31
33
  version: "0"
32
34
  type: :runtime
33
- name: oauth
34
- prerelease: false
35
35
  version_requirements: *id001
36
36
  - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ prerelease: false
37
39
  requirement: &id002 !ruby/object:Gem::Requirement
38
40
  none: false
39
41
  requirements:
@@ -46,26 +48,25 @@ dependencies:
46
48
  - 0
47
49
  version: 1.0.0
48
50
  type: :development
49
- name: bundler
50
- prerelease: false
51
51
  version_requirements: *id002
52
52
  - !ruby/object:Gem::Dependency
53
+ name: rspec
54
+ prerelease: false
53
55
  requirement: &id003 !ruby/object:Gem::Requirement
54
56
  none: false
55
57
  requirements:
56
58
  - - ~>
57
59
  - !ruby/object:Gem::Version
58
- hash: 27
60
+ hash: 3
59
61
  segments:
60
- - 1
61
- - 3
62
+ - 2
62
63
  - 0
63
- version: 1.3.0
64
+ version: "2.0"
64
65
  type: :development
65
- name: rspec
66
- prerelease: false
67
66
  version_requirements: *id003
68
67
  - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ prerelease: false
69
70
  requirement: &id004 !ruby/object:Gem::Requirement
70
71
  none: false
71
72
  requirements:
@@ -76,10 +77,10 @@ dependencies:
76
77
  - 0
77
78
  version: "0"
78
79
  type: :development
79
- name: rake
80
- prerelease: false
81
80
  version_requirements: *id004
82
81
  - !ruby/object:Gem::Dependency
82
+ name: rcov
83
+ prerelease: false
83
84
  requirement: &id005 !ruby/object:Gem::Requirement
84
85
  none: false
85
86
  requirements:
@@ -90,8 +91,6 @@ dependencies:
90
91
  - 0
91
92
  version: "0"
92
93
  type: :development
93
- name: rcov
94
- prerelease: false
95
94
  version_requirements: *id005
96
95
  description: "Douban API reference: http://www.douban.com/service/apidoc/reference/"
97
96
  email:
@@ -101,15 +100,16 @@ executables: []
101
100
 
102
101
  extensions: []
103
102
 
104
- extra_rdoc_files: []
105
-
103
+ extra_rdoc_files:
104
+ - README.rdoc
105
+ - History.rdoc
106
106
  files:
107
107
  - .gitignore
108
108
  - Gemfile
109
109
  - Gemfile.lock
110
- - History.txt
110
+ - History.rdoc
111
111
  - Manifest.txt
112
- - README.txt
112
+ - README.rdoc
113
113
  - Rakefile
114
114
  - douban-ruby.gemspec
115
115
  - examples/example.rb
@@ -155,8 +155,11 @@ homepage: http://rubygems.org/gems/douban-ruby
155
155
  licenses: []
156
156
 
157
157
  post_install_message:
158
- rdoc_options: []
159
-
158
+ rdoc_options:
159
+ - --main
160
+ - README.rdoc
161
+ - --charset
162
+ - UTF-8
160
163
  require_paths:
161
164
  - lib
162
165
  required_ruby_version: !ruby/object:Gem::Requirement
data/README.txt DELETED
@@ -1,25 +0,0 @@
1
- = Douban Ruby Client
2
-
3
- http://github.com/lidaobing/douban-ruby
4
-
5
- == Description
6
-
7
- douban ruby client. including OAuth support.
8
-
9
- Douban API reference: http://www.douban.com/service/apidoc/reference/
10
-
11
- == Requirments
12
-
13
- * oauth: sudo gem install oauth
14
-
15
- == INSTALL:
16
-
17
- gem install douban-ruby
18
-
19
- == Usage:
20
-
21
- http://github.com/lidaobing/douban-ruby/blob/master/examples/example.rb
22
-
23
- == LICENSE:
24
-
25
- licensed under Artistic License or GPL license.