social_oauth_api 0.0.4 → 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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NmZkODg3NmZmMTJiNmY5NWM4ZDllMDE4MGZhZDdhYTMzY2M5OWFhYg==
4
+ OGUwZWRlMzM2NTgyYjkzZjJhMTkxMTRmNDFlMzkwMDNiMzZmYjk0Nw==
5
5
  data.tar.gz: !binary |-
6
- MzA0OGJjNzdiOTk2NzM3ZmRhY2U4NzkyMTNmMzlkZDc4MzNmMmMxMw==
6
+ YjRhMjEyYzIxMWM0YTUwODhkNjdlMzllZTMzYmU3MmZkM2I2ZmYzNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Mjg3NWM1NWIxNWZkZTAyNDk4NzM0MTc1NTA5MGViZDM0NGRiNmVkMmViN2U2
10
- OWZhZGM3Zjk1N2EzYTBmMGI3NjJiYTRlY2VlMzY1YWM5ZTI4MGUzZjcxNjdh
11
- NDkxOGMwYzkzOTE5ODc0Y2NmNGJjZDVkN2NkMGM3ZmVlMmQ5NmQ=
9
+ ZmEzODVhOTc3ZjY4ZjIwODA0Yzc1NWIwMTNmMTc0Y2Q0N2UxZmQ2NWQyMTJh
10
+ Mzc4YjFjZWQzZWE3NzY5OThiYzNlNWQ5YTczOTc2NGE3NzQyNWEyMDYxY2Iz
11
+ ZDRjZWQ3ZWNiMDJmY2ZlYjgzYjI0MDI1NzFlOTczNTkwMTEyOTk=
12
12
  data.tar.gz: !binary |-
13
- MmM4YWZkNGQwODFkZDU1MzFiYzNhNWE1OWNjNDcyZDE0MjM2NDAwOWQ5MzM3
14
- MTJjMTI3ZGMzYTZlNWUzZDBiN2RiNTZiZWQ5Yzg3ODc3Y2ZkY2QzMTVlNjYy
15
- NTI5YTk4NDJhYTI3NWNkNjJmMDdhYTViY2JkYzk5MjVkY2UyZjE=
13
+ NzNlMjhiNTFiOWQ0OTQzNWExMjUxYjg3MTVjODkyOWJkNjMxNDI5YmNjM2Qy
14
+ ODViNzMwNzFkOWEyNTQ1ZmQ0MzEzNTQ2MGI5MDA5NGE3NjljZjk0MDMyYjFk
15
+ NzI0OWFkZTE2OTcwYzIxMjRhYTNkMWZjNGJmYTVmM2U1OGUzNDU=
data/README.md CHANGED
@@ -6,7 +6,10 @@
6
6
 
7
7
  只接受前端sdk传回来的第三方 **access_token** 参数
8
8
 
9
- 支持微博和qq登录
9
+ 支持第三方列表如下:
10
+
11
+ - 新浪微博
12
+ - QQ号登录
10
13
 
11
14
  ## Installation
12
15
 
@@ -27,22 +30,23 @@ Or install it yourself as:
27
30
  require 'social_oauth_api'
28
31
 
29
32
  weibo_config = {
30
- client_id: 'xxxxxx',
31
- access_token: 'xxxxxxxxxxx',
33
+ provider_type: 'sinaweibo',
34
+ access_token: 'xxxxxxxxx'
32
35
  }
33
36
 
34
37
  qq_config = {
35
- client_id: 'xxxxx',
36
- access_token: 'xxxxxxxxxxx'
38
+ provider_type: 'qqdenglu',
39
+ access_token: 'xxxxxxxx',
40
+ client_id: 'xxxxxxxx' # => 如果只需要user_id, 不需要用户信息可以不传 client_id 参数
37
41
  }
38
42
 
39
- weibo = SocialOauthApi::Weibo::User.new(weibo_config)
40
- p weibo.id # => weibo uid
43
+ weibo = SocialOauthApi::User.new(weibo_config)
44
+ p weibo.id # => weibo uid
41
45
  p weibo.name # => weibo screen_name
42
46
  p weibo.image_url # => weibo profile_image_url
43
47
  p weibo.user_info
44
48
 
45
- qq = SocialOauthApi::Qq::User.new(qq_config)
49
+ qq = SocialOauthApi::User.new(qq_config)
46
50
  p qq.id # => qq open_id
47
51
  p qq.name # => qq nickname
48
52
  p qq.image_url # => qq figureurl
File without changes
@@ -1,14 +1,14 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module SocialOauthApi
4
- class Base
5
- attr_accessor :client_id, :client_secret, :access_token
4
+ module Base
5
+ attr_reader :client_id, :provider_type, :access_token
6
6
 
7
7
  HTTP_TIMEOUT = 15
8
8
 
9
9
  def initialize options
10
10
  @client_id = options[:client_id]
11
- @client_secret = options[:client_secret]
11
+ @provider_type = options[:provider_type]
12
12
  @access_token = options[:access_token]
13
13
  end
14
14
 
@@ -23,5 +23,13 @@ module SocialOauthApi
23
23
  response.body
24
24
  end
25
25
  end
26
+
27
+ class << self
28
+ def klass(str)
29
+ str.split('::').inject(Object) do |mod, class_name|
30
+ mod.const_get(class_name)
31
+ end
32
+ end
33
+ end
26
34
  end
27
35
  end
@@ -0,0 +1,4 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative './qqdenglu_config'
4
+ require_relative './qqdenglu_user'
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ module SocialOauthApi
4
+ module Qqdenglu
5
+ module Config
6
+ def open_id_url
7
+ 'https://graph.qq.com/oauth2.0/me'
8
+ end
9
+
10
+ def user_info_url
11
+ 'https://graph.qq.com/user/get_user_info'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ module SocialOauthApi
4
+ module Qqdenglu
5
+ class User
6
+ include SocialOauthApi::Base
7
+ include SocialOauthApi::Qqdenglu::Config
8
+
9
+ def open_id
10
+ @open_id ||= get(open_id_url, access_token: access_token)
11
+ @open_id.match(/"openid":"(?<openid>\w+)"/)[:openid]
12
+ end
13
+
14
+ def user_info
15
+ @user_info ||= JSON.parse(
16
+ get(user_info_url,
17
+ access_token: access_token,
18
+ oauth_consumer_key: client_id,
19
+ openid: open_id)
20
+ )
21
+ end
22
+
23
+ def nickname
24
+ user_info['nickname']
25
+ end
26
+
27
+ def figureurl
28
+ user_info['figureurl']
29
+ end
30
+
31
+ alias :id :open_id
32
+ alias :name :nickname
33
+ alias :image_url :figureurl
34
+ end
35
+ end
36
+ end
File without changes
File without changes
@@ -0,0 +1,4 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative './sinaweibo_config'
4
+ require_relative './sinaweibo_user'
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ module SocialOauthApi
4
+ module Sinaweibo
5
+ module Config
6
+ def uid_url
7
+ 'https://api.weibo.com/2/account/get_uid.json'
8
+ end
9
+
10
+ def show_url
11
+ 'https://api.weibo.com/2/users/show.json'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ module SocialOauthApi
4
+ module Sinaweibo
5
+ class User
6
+ include SocialOauthApi::Base
7
+ include SocialOauthApi::Sinaweibo::Config
8
+
9
+ def uid
10
+ @uid ||= JSON.parse(get(uid_url, access_token: access_token))
11
+ @uid['uid'].to_s
12
+ end
13
+
14
+ def show
15
+ @user_info ||= JSON.parse(
16
+ get(show_url, access_token: access_token, uid: uid)
17
+ )
18
+ end
19
+
20
+ def screen_name
21
+ show['screen_name']
22
+ end
23
+
24
+ def profile_image_url
25
+ show['profile_image_url']
26
+ end
27
+
28
+ alias :id :uid
29
+ alias :name :screen_name
30
+ alias :image_url :profile_image_url
31
+ alias :user_info :show
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ module SocialOauthApi
4
+ class User
5
+ def initialize options
6
+ initialize_provider_user(options)
7
+ end
8
+
9
+ def user_info
10
+ @provider_user.user_info
11
+ end
12
+
13
+ def id
14
+ @provider_user.id
15
+ end
16
+
17
+ def name
18
+ @provider_user.name
19
+ end
20
+
21
+ def image_url
22
+ @provider_user.image_url
23
+ end
24
+
25
+ def initialize_provider_user options
26
+ provider_type = options[:provider_type].capitalize
27
+ user_class_name = "SocialOauthApi::#{provider_type}::User"
28
+ @provider_user = SocialOauthApi::Base.klass(user_class_name).new(options)
29
+ end
30
+ end
31
+ end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module SocialOauthApi
4
- VERSION = "0.0.4"
4
+ VERSION = "0.1.0"
5
5
  end
@@ -2,7 +2,11 @@ require 'uri'
2
2
  require 'net/http'
3
3
  require 'json'
4
4
 
5
- require 'social_oauth_api/version'
6
- require 'social_oauth_api/base'
7
- require 'social_oauth_api/social/weibo'
8
- require 'social_oauth_api/social/qq'
5
+ require '../lib/social_oauth_api/version'
6
+ require '../lib/social_oauth_api/base'
7
+ require '../lib/social_oauth_api/user'
8
+ require '../lib/social_oauth_api/baidu/baidu'
9
+ require '../lib/social_oauth_api/qqdenglu/qqdenglu'
10
+ require '../lib/social_oauth_api/qqweibo/qqweibo'
11
+ require '../lib/social_oauth_api/renren/renren'
12
+ require '../lib/social_oauth_api/sinaweibo/sinaweibo'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_oauth_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spirit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-11 00:00:00.000000000 Z
11
+ date: 2014-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -51,11 +51,18 @@ files:
51
51
  - README.md
52
52
  - Rakefile
53
53
  - lib/social_oauth_api.rb
54
+ - lib/social_oauth_api/baidu/baidu.rb
54
55
  - lib/social_oauth_api/base.rb
55
- - lib/social_oauth_api/social/qq.rb
56
- - lib/social_oauth_api/social/weibo.rb
56
+ - lib/social_oauth_api/qqdenglu/qqdenglu.rb
57
+ - lib/social_oauth_api/qqdenglu/qqdenglu_config.rb
58
+ - lib/social_oauth_api/qqdenglu/qqdenglu_user.rb
59
+ - lib/social_oauth_api/qqweibo/qqweibo.rb
60
+ - lib/social_oauth_api/renren/renren.rb
61
+ - lib/social_oauth_api/sinaweibo/sinaweibo.rb
62
+ - lib/social_oauth_api/sinaweibo/sinaweibo_config.rb
63
+ - lib/social_oauth_api/sinaweibo/sinaweibo_user.rb
64
+ - lib/social_oauth_api/user.rb
57
65
  - lib/social_oauth_api/version.rb
58
- - lib/social_oauth_api/weibo.rb
59
66
  - social_oauth_api.gemspec
60
67
  homepage: https://github.com/NaixSpirit/social_oauth_api
61
68
  licenses:
@@ -1,35 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SocialOauthApi
4
- module Qq
5
- class User < Base
6
- OPENID_URL = 'https://graph.qq.com/oauth2.0/me'
7
- USER_INFO_URL = 'https://graph.qq.com/user/get_user_info'
8
-
9
- def default_query
10
- { oauth_consumer_key: client_id, access_token: access_token }
11
- end
12
-
13
- def open_id
14
- @open_id ||= get(OPENID_URL, default_query)
15
- @open_id.match(/"openid":"(?<openid>\w+)"/)[:openid]
16
- end
17
-
18
- def user_info
19
- @user_info ||= JSON.parse(get(USER_INFO_URL, default_query.merge(openid: open_id)))
20
- end
21
-
22
- def nickname
23
- user_info['nickname']
24
- end
25
-
26
- def figureurl
27
- user_info['figureurl']
28
- end
29
-
30
- alias :id :open_id
31
- alias :name :nickname
32
- alias :image_url :figureurl
33
- end
34
- end
35
- end
@@ -1,36 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SocialOauthApi
4
- module Weibo
5
- class User < Base
6
- UID_URL = 'https://api.weibo.com/2/account/get_uid.json'
7
- SHOW_URL = 'https://api.weibo.com/2/users/show.json'
8
-
9
- def default_query
10
- { source: client_id, access_token: access_token }
11
- end
12
-
13
- def uid
14
- @uid ||= JSON.parse(get(UID_URL, default_query))
15
- @uid['uid'].to_s
16
- end
17
-
18
- def show
19
- @user_info ||= JSON.parse(get(SHOW_URL, default_query.merge(uid: uid)))
20
- end
21
-
22
- def screen_name
23
- show['screen_name']
24
- end
25
-
26
- def profile_image_url
27
- show['profile_image_url']
28
- end
29
-
30
- alias :id :uid
31
- alias :name :screen_name
32
- alias :image_url :profile_image_url
33
- alias :user_info :show
34
- end
35
- end
36
- end
@@ -1,36 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SocialOauthApi
4
- module Weibo
5
- class User < Base
6
- UID_URL = 'https://api.weibo.com/2/account/get_uid.json'
7
- SHOW_URL = 'https://api.weibo.com/2/users/show.json'
8
-
9
- def default_query
10
- { source: client_id, access_token: access_token }
11
- end
12
-
13
- def uid
14
- @uid ||= JSON.parse(get(UID_URL, default_query))
15
- @uid['uid'].to_s
16
- end
17
-
18
- def show
19
- @user_info ||= JSON.parse(get(SHOW_URL, default_query.merge(uid: uid)))
20
- end
21
-
22
- def screen_name
23
- show['screen_name']
24
- end
25
-
26
- def profile_image_url
27
- show['profile_image_url']
28
- end
29
-
30
- alias :id :uid
31
- alias :name :screen_name
32
- alias :image_url :profile_image_url
33
- alias :user_info :show
34
- end
35
- end
36
- end