weibo_sina 0.0.1 → 0.0.2

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: caa392a3a2ae9cb888b20bf8e32851362f8cb211
4
- data.tar.gz: a00748dafafc2f8e2103c506190297d6a01e7092
3
+ metadata.gz: a702532b8763b539396e18a43ad188352a70c309
4
+ data.tar.gz: 00613febd5f0caa99a4b68ddbfc1ad6fb07b72aa
5
5
  SHA512:
6
- metadata.gz: 8780c1ac0c9cfdc1dc09fafce5f3026484b67b8abcce18b54b4b2aeefc3f5d0e2861afaf2692fb479578286ca9cf64796df6e38007ef0b0a82b972543c72a7fe
7
- data.tar.gz: aa7423bfc36255223a24e2d5a0a133b72627ae4e1bde7fd6c572a60432ca336b2f6935a1ed7eddd34540321846655bbfa5df7e9294d4458878438231e25a196c
6
+ metadata.gz: 784b74c2b11731b8f647b80e07d63f706dbd55a3ab08c539dfb0bf48564a8375c551e65d1a5ec2e51e252f8298351a5dfd0e424c989875b6377a4175dea6dd3b
7
+ data.tar.gz: e8fa55cae19254d3f9fd7fabf8263e7a5f8fd6c73ddeaf9ce8f2ce49bd5d5ba9f5a96c2ae679b14fd8bc1a876c7b6718f7546558bc997467fc5ecbaa9cad1099
data/lib/test/debug.rb ADDED
@@ -0,0 +1,19 @@
1
+ require File.expand_path("../../weibo_sina/base.rb", __FILE__)
2
+ require File.expand_path("../../weibo_sina/access_token.rb", __FILE__)
3
+ require File.expand_path("../../weibo_sina/weibo.rb", __FILE__)
4
+
5
+ class Debug
6
+ # To change this template use File | Settings | File Templates.
7
+ include WeiboSina
8
+
9
+ #access = AccessToken.new("2997174788","http://office.ikanke.cn:100/admin/controller_channel_name_id","22abb9bb3151b9227b5cba3e5df81037")
10
+ #p access.accessToken("b0392f469d5835167743fec5492bbf3b")
11
+ weibo = Weibo.new("2.00Nc1OmBqEqpQD5402413820pf228E")
12
+ #p weibo.friendship_create_by_domain("aki129")
13
+ a = weibo.get_user_timelines_ids("2865597891",1)
14
+ p a
15
+ a.each do |timeline|
16
+ #p timeline["original_pic"]
17
+ p weibo.get_weibo_by_id(timeline)
18
+ end
19
+ end
@@ -1,5 +1,6 @@
1
1
  #encoding:utf-8
2
2
  require 'net/http'
3
+ require 'json'
3
4
 
4
5
  module WeiboSina
5
6
  # To change this template use File | Settings | File Templates.
@@ -24,7 +25,7 @@ module WeiboSina
24
25
  end
25
26
 
26
27
  #获取授权的页面请求地址
27
- def url_authorizeOAuth2(state=nil,redirect_uri)
28
+ def url_authorizeOAuth2(state=nil)
28
29
  authorize_url = 'https://api.weibo.com/oauth2/authorize'
29
30
  url = ""
30
31
  unless state
@@ -45,6 +46,7 @@ module WeiboSina
45
46
  uri = URI(accesstoken_url)
46
47
  if @redirect_uri
47
48
  res = Net::HTTP.post_form(uri, 'client_id' => @client_id, 'client_secret' => @client_secret,'grant_type'=>grant_type,'code'=>code,'redirect_uri'=>@redirect_uri)
49
+ p res.body
48
50
  ret = JSON.parse(res.body)
49
51
  @access_token = ret["access_token"]
50
52
  else
@@ -1,4 +1,8 @@
1
1
  #encoding:utf-8
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'net/https'
5
+ require 'json'
2
6
 
3
7
  module WeiboSina
4
8
  class Base
@@ -20,5 +24,19 @@ module WeiboSina
20
24
  response.body
21
25
  end
22
26
 
27
+ #https 请求
28
+ #url 请求地址
29
+ #args 需要传递的参数
30
+ def https_post(url,args)
31
+ uri = URI.parse(url)
32
+ https=Net::HTTP.new(uri.host,uri.port)
33
+ https.use_ssl=true
34
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
35
+ req = Net::HTTP::Post.new(uri.path)
36
+ req.set_form_data(args)
37
+ res = https.request(req)
38
+ res.body
39
+ end
40
+
23
41
  end
24
42
  end
@@ -1,3 +1,3 @@
1
1
  module WeiboSina
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,105 @@
1
+ #encoding:utf-8
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+ module WeiboSina
6
+ # To change this template use File | Settings | File Templates.
7
+ class Weibo
8
+ include WeiboSina
9
+
10
+ attr_reader :access_token
11
+
12
+ def initialize(access_token)
13
+ @access_token = access_token
14
+ end
15
+
16
+ #根据微博ID获取单条微博内容
17
+ def get_weibo_by_id(id)
18
+ url = "https://api.weibo.com/2/statuses/show.json"
19
+ args = {}
20
+ args.merge!(access_token:@access_token)
21
+ args.merge!(id:id)
22
+ base = Base.new()
23
+ return JSON.parse(base.https_get(url,args))
24
+ end
25
+
26
+
27
+ #用户关注的UID列表
28
+ def get_uid_friends(screen_name,count=500)
29
+ url = "https://api.weibo.com/2/friendships/friends/ids.json"
30
+ args = {}
31
+ args.merge!(access_token:@access_token)
32
+ args.merge!(screen_name:screen_name)
33
+ args.merge!(count:count)
34
+ base = Base.new()
35
+ return JSON.parse(base.https_get(url,args))["ids"]
36
+ end
37
+
38
+ #获取指定用于的微博ID列表
39
+ #uid 指定的用户ID
40
+ #feature 微博类型 0:全部、1:原创、2:图片、3:视频、4:音乐
41
+ def get_user_timelines_ids(uid,feature=1)
42
+ url = "https://api.weibo.com/2/statuses/user_timeline/ids.json"
43
+ args ={}
44
+ args.merge!(access_token:@access_token)
45
+ args.merge!(uid:uid)
46
+ args.merge!(feature:feature)
47
+ base = Base.new()
48
+ return JSON.parse(base.https_get(url,args))["statuses"]
49
+ end
50
+
51
+ #获取当前登录用户的动态列表
52
+ def get_home_time(feature=1)
53
+ url = "https://api.weibo.com/2/statuses/home_timeline.json"
54
+ args ={}
55
+ args.merge!(access_token:@access_token)
56
+ args.merge!(feature:feature)
57
+ args.merge!(count:100)
58
+ base = Base.new()
59
+ return JSON.parse(base.https_get(url,args))["statuses"]
60
+ end
61
+
62
+ #
63
+ def get_friends_timeline_ids(feature=1)
64
+ end
65
+
66
+ #获取朋友的动态
67
+ def get_friends_timeline(feature=1)
68
+ url = "https://api.weibo.com/2/statuses/friends_timeline.json"
69
+ args ={}
70
+ args.merge!(access_token:@access_token)
71
+ args.merge!(feature:feature)
72
+ args.merge!(count:100)
73
+ base = Base.new()
74
+ return JSON.parse(base.https_get(url,args))["statuses"]
75
+ end
76
+
77
+ #关注某人
78
+ def friendship_create(uid)
79
+ url = "https://api.weibo.com/2/friendships/create.json"
80
+ args ={}
81
+ args.merge!(access_token:@access_token)
82
+ args.merge!(uid:uid)
83
+ base = Base.new()
84
+ return JSON.parse(base.https_post(url,args))
85
+ end
86
+
87
+ #根据用户个性域名获取用户信息
88
+ def domain_show(domain)
89
+ url = "https://api.weibo.com/2/users/domain_show.json"
90
+ args ={}
91
+ args.merge!(access_token:@access_token)
92
+ args.merge!(domain:domain)
93
+ base = Base.new()
94
+ return JSON.parse(base.https_get(url,args))
95
+ end
96
+
97
+ #根据用户个性域名关注某人
98
+ def friendship_create_by_domain(domain)
99
+ user = domain_show(domain)
100
+ return friendship_create(user["id"])
101
+ end
102
+
103
+
104
+ end
105
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weibo_sina
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - zql
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-10 00:00:00.000000000 Z
11
+ date: 2013-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -50,11 +50,12 @@ files:
50
50
  - LICENSE.txt
51
51
  - README.md
52
52
  - Rakefile
53
- - lib/test/debug_access_token.rb
53
+ - lib/test/debug.rb
54
54
  - lib/weibo_sina.rb
55
55
  - lib/weibo_sina/access_token.rb
56
56
  - lib/weibo_sina/base.rb
57
57
  - lib/weibo_sina/version.rb
58
+ - lib/weibo_sina/weibo.rb
58
59
  - weibo_sina.gemspec
59
60
  homepage: ''
60
61
  licenses:
@@ -1,9 +0,0 @@
1
- require File.expand_path("../../weibo_sina/base.rb", __FILE__)
2
- require File.expand_path("../../weibo_sina/access_token.rb", __FILE__)
3
-
4
- class DebugAccessToken
5
- # To change this template use File | Settings | File Templates.
6
- include WeiboSina
7
-
8
- AccessToken.new("2997174788","http://127.0.0.1:3000/admin/get_sister_weibos","22abb9bb3151b9227b5cba3e5df81037")
9
- end