fanfou 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,6 +3,9 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
 
6
+ gem "json", ">= 0"
7
+ gem "oauth", ">= 0"
8
+
6
9
  # Add dependencies to develop your gem here.
7
10
  # Include everything needed to run rake, tests, features, etc.
8
11
  group :development do
@@ -9,6 +9,7 @@ GEM
9
9
  rdoc
10
10
  json (1.6.5)
11
11
  multi_json (1.0.4)
12
+ oauth (0.4.5)
12
13
  rake (0.9.2.2)
13
14
  rdoc (3.12)
14
15
  json (~> 1.4)
@@ -24,6 +25,8 @@ PLATFORMS
24
25
  DEPENDENCIES
25
26
  bundler (~> 1.0.0)
26
27
  jeweler (~> 1.8.3)
28
+ json
29
+ oauth
27
30
  rdoc (~> 3.12)
28
31
  shoulda
29
32
  simplecov
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.3.0
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ require 'oauth'
4
+ require 'fanfou'
5
+
6
+ require 'sinatra' # install via gem install sinatra
7
+ require 'sinatra/cookies' # install via gem install sinatra-contrib
8
+
9
+ set :fanfou_consumer_key, "" # set your consumer key here
10
+ set :fanfou_consumer_secret, "" # set your consumer secret here
11
+
12
+ before do
13
+ @fanfou_client = Fanfou::Fanfou.new(settings.fanfou_consumer_key,
14
+ settings.fanfou_consumer_secret)
15
+ # cookies.options.delete(:domain) # dirty hack for cookie error.. if you got 401 Unauthorized, you can try to enable this.
16
+ end
17
+
18
+ get '/' do
19
+ '<a href="/oauth">Click here to login with fanfou</a>'
20
+ end
21
+
22
+ get '/oauth' do
23
+ redirect_url = @fanfou_client.get_authorize_url
24
+ cookies[:request_token] = @fanfou_client.request_token.token
25
+ cookies[:request_token_secret] = @fanfou_client.request_token.secret
26
+ puts @fanfou_client.request_token.token
27
+ redirect redirect_url
28
+ end
29
+
30
+ get '/callback' do
31
+ @fanfou_client.get_access_token(cookies[:request_token], cookies[:request_token_secret], params[:oauth_token])
32
+ cookies[:request_token] = nil
33
+ cookies[:request_token_secret] = nil
34
+ result = @fanfou_client.fanfou_request("/account/verify_credentials")
35
+ "token: #{@fanfou_client.access_token.token}\n secret: #{@fanfou_client.access_token.secret}\n #{result.to_s}"
36
+ end
@@ -0,0 +1,71 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "fanfou"
8
+ s.version = "0.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Zeray Rice"]
12
+ s.date = "2012-02-02"
13
+ s.description = "A simple ruby SDK for fanfou"
14
+ s.email = "fanzeyi1994@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "examples/simple_oauth_login.rb",
30
+ "fanfou.gemspec",
31
+ "lib/fanfou.rb",
32
+ "test/helper.rb",
33
+ "test/test_fanfou.rb"
34
+ ]
35
+ s.homepage = "http://github.com/fanzeyi/ruby-fanfou"
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = "1.8.10"
39
+ s.summary = "A simple ruby SDK for fanfou"
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<json>, [">= 0"])
46
+ s.add_runtime_dependency(%q<oauth>, [">= 0"])
47
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
48
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
49
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
51
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<json>, [">= 0"])
54
+ s.add_dependency(%q<oauth>, [">= 0"])
55
+ s.add_dependency(%q<shoulda>, [">= 0"])
56
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
59
+ s.add_dependency(%q<simplecov>, [">= 0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<json>, [">= 0"])
63
+ s.add_dependency(%q<oauth>, [">= 0"])
64
+ s.add_dependency(%q<shoulda>, [">= 0"])
65
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
66
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
67
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
68
+ s.add_dependency(%q<simplecov>, [">= 0"])
69
+ end
70
+ end
71
+
@@ -55,26 +55,31 @@ module Fanfou
55
55
  )
56
56
  @access_token = OAuth::AccessToken.new(@api_client, access_token, access_token_secret)
57
57
  end
58
- def fanfou_request(path, post_args = nil, args = {})
58
+ def fanfou_request(path, args = {})
59
59
  path += ".json"
60
60
  if not @access_token
61
61
  raise 'No Access Token Set!'
62
62
  end
63
- method = if post_args then :post
64
- else :get
65
- end
66
- if args
67
- path += "?" + _encode(args)
63
+ method = :get
64
+ method = :post if args[:post_args]
65
+ if args[:get_args]
66
+ path += "?" + _encode(args[:get_args])
68
67
  end
69
- if post_args == :get
70
- result = JSON::parse(@access_token.get(path).body)
68
+ if method == :get
69
+ response = @access_token.get(path)
71
70
  else
72
- result = JSON::parse(@access_token.post(path, post_args).body)
71
+ response = @access_token.post(path, args[:post_args])
73
72
  end
74
- result
73
+ if response.code != "200"
74
+ raise "Network Error #{response.code}: #{response.msg}"
75
+ end
76
+ JSON::parse(response.body)
75
77
  end
76
78
  def request_token
77
79
  @request_token
78
80
  end
81
+ def access_token
82
+ @access_token
83
+ end
79
84
  end
80
85
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fanfou
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,33 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-28 00:00:00.000000000Z
12
+ date: 2012-02-02 00:00:00.000000000Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: &82554460 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *82554460
25
+ - !ruby/object:Gem::Dependency
26
+ name: oauth
27
+ requirement: &82511970 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *82511970
14
36
  - !ruby/object:Gem::Dependency
15
37
  name: shoulda
16
- requirement: &75221550 !ruby/object:Gem::Requirement
38
+ requirement: &82511700 !ruby/object:Gem::Requirement
17
39
  none: false
18
40
  requirements:
19
41
  - - ! '>='
@@ -21,10 +43,10 @@ dependencies:
21
43
  version: '0'
22
44
  type: :development
23
45
  prerelease: false
24
- version_requirements: *75221550
46
+ version_requirements: *82511700
25
47
  - !ruby/object:Gem::Dependency
26
48
  name: rdoc
27
- requirement: &75221190 !ruby/object:Gem::Requirement
49
+ requirement: &82511440 !ruby/object:Gem::Requirement
28
50
  none: false
29
51
  requirements:
30
52
  - - ~>
@@ -32,10 +54,10 @@ dependencies:
32
54
  version: '3.12'
33
55
  type: :development
34
56
  prerelease: false
35
- version_requirements: *75221190
57
+ version_requirements: *82511440
36
58
  - !ruby/object:Gem::Dependency
37
59
  name: bundler
38
- requirement: &75220800 !ruby/object:Gem::Requirement
60
+ requirement: &82511190 !ruby/object:Gem::Requirement
39
61
  none: false
40
62
  requirements:
41
63
  - - ~>
@@ -43,10 +65,10 @@ dependencies:
43
65
  version: 1.0.0
44
66
  type: :development
45
67
  prerelease: false
46
- version_requirements: *75220800
68
+ version_requirements: *82511190
47
69
  - !ruby/object:Gem::Dependency
48
70
  name: jeweler
49
- requirement: &75220430 !ruby/object:Gem::Requirement
71
+ requirement: &82510890 !ruby/object:Gem::Requirement
50
72
  none: false
51
73
  requirements:
52
74
  - - ~>
@@ -54,10 +76,10 @@ dependencies:
54
76
  version: 1.8.3
55
77
  type: :development
56
78
  prerelease: false
57
- version_requirements: *75220430
79
+ version_requirements: *82510890
58
80
  - !ruby/object:Gem::Dependency
59
81
  name: simplecov
60
- requirement: &75220110 !ruby/object:Gem::Requirement
82
+ requirement: &82510640 !ruby/object:Gem::Requirement
61
83
  none: false
62
84
  requirements:
63
85
  - - ! '>='
@@ -65,7 +87,7 @@ dependencies:
65
87
  version: '0'
66
88
  type: :development
67
89
  prerelease: false
68
- version_requirements: *75220110
90
+ version_requirements: *82510640
69
91
  description: A simple ruby SDK for fanfou
70
92
  email: fanzeyi1994@gmail.com
71
93
  executables: []
@@ -83,6 +105,8 @@ files:
83
105
  - README.rdoc
84
106
  - Rakefile
85
107
  - VERSION
108
+ - examples/simple_oauth_login.rb
109
+ - fanfou.gemspec
86
110
  - lib/fanfou.rb
87
111
  - test/helper.rb
88
112
  - test/test_fanfou.rb
@@ -101,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
125
  version: '0'
102
126
  segments:
103
127
  - 0
104
- hash: 458115277
128
+ hash: 447231441
105
129
  required_rubygems_version: !ruby/object:Gem::Requirement
106
130
  none: false
107
131
  requirements: