social_oauth_api 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWFjNjg3NWU3ZWU2ZjYxYjdjOGFjNTY3OTBiY2RjZTk1YTdiMTQ2NQ==
4
+ NmZkODg3NmZmMTJiNmY5NWM4ZDllMDE4MGZhZDdhYTMzY2M5OWFhYg==
5
5
  data.tar.gz: !binary |-
6
- YzFmYzU2OThmOGQ3MzVmOTQ0NDliYzdlOWEzODQ3NzMzYzkwYzExYw==
6
+ MzA0OGJjNzdiOTk2NzM3ZmRhY2U4NzkyMTNmMzlkZDc4MzNmMmMxMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzcxN2FkMGViNjQ3MTBiOGNiNjM4M2E5Nzc0OWRjNzM1Y2M2MWQzOTFkNDdh
10
- MDJhOTY5MTgyY2I4ODliN2U2YmM0OGE5Y2M2MzNmZWU1NDUwZjdjOGQxZjVj
11
- ZjcyMDg2ZDU4ODk0NmY5MzIzOTVlM2Q5MGM3NjIyYmVmNmVhY2I=
9
+ Mjg3NWM1NWIxNWZkZTAyNDk4NzM0MTc1NTA5MGViZDM0NGRiNmVkMmViN2U2
10
+ OWZhZGM3Zjk1N2EzYTBmMGI3NjJiYTRlY2VlMzY1YWM5ZTI4MGUzZjcxNjdh
11
+ NDkxOGMwYzkzOTE5ODc0Y2NmNGJjZDVkN2NkMGM3ZmVlMmQ5NmQ=
12
12
  data.tar.gz: !binary |-
13
- MGFjYTZlMjE4ZjZlMDk1N2U4YTlmZTA3YThjODgyNTUwZGFkYTNlY2IxZTgy
14
- NGNjN2ZmMGU0YjE1ZDA3ZDcxNmMwNzk3Nzk5N2I0NjljMGNkMzY4ZTgzM2Rj
15
- M2ZjZDZiNzRjYmFkMzlmZGQyYmRjMDE0NmIzNWYyOGE0NTk2NzQ=
13
+ MmM4YWZkNGQwODFkZDU1MzFiYzNhNWE1OWNjNDcyZDE0MjM2NDAwOWQ5MzM3
14
+ MTJjMTI3ZGMzYTZlNWUzZDBiN2RiNTZiZWQ5Yzg3ODc3Y2ZkY2QzMTVlNjYy
15
+ NTI5YTk4NDJhYTI3NWNkNjJmMDdhYTViY2JkYzk5MjVkY2UyZjE=
@@ -4,6 +4,8 @@ module SocialOauthApi
4
4
  class Base
5
5
  attr_accessor :client_id, :client_secret, :access_token
6
6
 
7
+ HTTP_TIMEOUT = 15
8
+
7
9
  def initialize options
8
10
  @client_id = options[:client_id]
9
11
  @client_secret = options[:client_secret]
@@ -11,13 +13,15 @@ module SocialOauthApi
11
13
  end
12
14
 
13
15
  def get url, query
14
- uri = URI(url)
15
- uri.query = URI.encode_www_form(query)
16
- http = Net::HTTP.new(uri.host, uri.port)
17
- http.use_ssl = true if uri.scheme == 'https'
18
- request = Net::HTTP::Get.new(uri.request_uri)
19
- response = http.request(request)
20
- response.body
16
+ timeout(HTTP_TIMEOUT) do
17
+ uri = URI(url)
18
+ uri.query = URI.encode_www_form(query)
19
+ http = Net::HTTP.new(uri.host, uri.port)
20
+ http.use_ssl = true if uri.scheme == 'https'
21
+ request = Net::HTTP::Get.new(uri.request_uri)
22
+ response = http.request(request)
23
+ response.body
24
+ end
21
25
  end
22
26
  end
23
27
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module SocialOauthApi
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.4"
5
5
  end
@@ -0,0 +1,36 @@
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_oauth_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spirit
@@ -55,6 +55,7 @@ files:
55
55
  - lib/social_oauth_api/social/qq.rb
56
56
  - lib/social_oauth_api/social/weibo.rb
57
57
  - lib/social_oauth_api/version.rb
58
+ - lib/social_oauth_api/weibo.rb
58
59
  - social_oauth_api.gemspec
59
60
  homepage: https://github.com/NaixSpirit/social_oauth_api
60
61
  licenses: