shixian_weibo_2 0.1.7
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 +7 -0
- data/.gitignore +18 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +135 -0
- data/Rakefile +2 -0
- data/lib/weibo_2/access_token.rb +20 -0
- data/lib/weibo_2/api/v2/account.rb +31 -0
- data/lib/weibo_2/api/v2/base.rb +79 -0
- data/lib/weibo_2/api/v2/comments.rb +51 -0
- data/lib/weibo_2/api/v2/common.rb +28 -0
- data/lib/weibo_2/api/v2/favorites.rb +59 -0
- data/lib/weibo_2/api/v2/friendships.rb +64 -0
- data/lib/weibo_2/api/v2/location.rb +83 -0
- data/lib/weibo_2/api/v2/notification.rb +12 -0
- data/lib/weibo_2/api/v2/place.rb +123 -0
- data/lib/weibo_2/api/v2/register.rb +14 -0
- data/lib/weibo_2/api/v2/remind.rb +23 -0
- data/lib/weibo_2/api/v2/search.rb +38 -0
- data/lib/weibo_2/api/v2/short_url.rb +49 -0
- data/lib/weibo_2/api/v2/statuses.rb +121 -0
- data/lib/weibo_2/api/v2/suggestions.rb +45 -0
- data/lib/weibo_2/api/v2/tags.rb +36 -0
- data/lib/weibo_2/api/v2/trends.rb +39 -0
- data/lib/weibo_2/api/v2/users.rb +30 -0
- data/lib/weibo_2/base.rb +6 -0
- data/lib/weibo_2/client.rb +138 -0
- data/lib/weibo_2/config.rb +29 -0
- data/lib/weibo_2/errors.rb +20 -0
- data/lib/weibo_2/oauth.rb +6 -0
- data/lib/weibo_2/strategy/auth_code.rb +12 -0
- data/lib/weibo_2/version.rb +19 -0
- data/lib/weibo_2.rb +39 -0
- data/spec/client_spec.rb +44 -0
- data/weibo_2.gemspec +25 -0
- metadata +149 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: bd2179efefd6a862284ec08f43a7a7124f89bd66dc81ad66dcad7471eea74fca
|
|
4
|
+
data.tar.gz: 621d8fdc267f0c8ee8523b28f836b56679d9137aec52ce86000845a8dae0604c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 531d8a6f23a02ae182631b63994f3f9086ed5baf30562dfd2d29e3a93dc7368ae891d3ae7c6055e7bef663ab1f6935cb1fc00846666b7ec5e5ff13e0326e4f9f
|
|
7
|
+
data.tar.gz: 8f3280debf8feb480e6a64c16b3c594af969f67694d808f69d628663e913958eb14b33302c6526ca940fa13642ceadd0c29df315857cff5bd454e89722ce686f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2012 simsicon
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
Note: I got a lot of inspiration from [this gem](https://github.com/ballantyne/weibo) and [this gem](https://github.com/acenqiu/weibo2). The first one will soon be deprecated since weibo is planning to switch to oauth2. The second one has not been fully implemented and is still lacking some features (but a nice try nevertheless). Thanks Scott and acenqiu.
|
|
2
|
+
|
|
3
|
+
# WeiboOAuth2
|
|
4
|
+
|
|
5
|
+
WeioOAuth2 is a Ruby gem that provides a wrapper for interacting with sina weibo's v2 [API](http://open.weibo.com/wiki/API%E6%96%87%E6%A1%A3_V2), which is currently the latest version. Check out the link if you are interested in browsing the details. The output data format is Hashie::Mash, check out [here](https://github.com/intridea/hashie#mash). If you are not familiar with oauth2, I recommend that you read this [article](http://open.weibo.com/wiki/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E).
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
1. weibo account
|
|
10
|
+
2. weibo app API key
|
|
11
|
+
3. weibo app API secret
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
I call it weibo_2 because someone else took the name weibo_oauth2.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
$ gem install weibo_2
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Basic Usage
|
|
22
|
+
|
|
23
|
+
The example have been moved to [here](https://github.com/simsicon/weibo_2_example). It wiil be more convenient to update.
|
|
24
|
+
|
|
25
|
+
The [example](https://github.com/simsicon/weibo_2_example) written with sinatra shows how to ask for oauth2 permission, get the token and send status with picture. It should cover basic usage in all ruby apps. You can run your own demo!
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
$ KEY=change_this_to_your_key SECRET=change_this_to_your_secret REDIR_URI=change_this_to_your_redir_uri ruby example.rb
|
|
29
|
+
```
|
|
30
|
+
It should work.
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
1. How to get the token?
|
|
34
|
+
|
|
35
|
+
OAuth2 is simpler than its first version. In order to get the access token, you first need to get an Authorization Code through a callback request. Now use the following code to get the token.
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
WeiboOAuth2::Config.api_key = YOUR_KEY
|
|
39
|
+
WeiboOAuth2::Config.api_secret = YOUR_SECRET
|
|
40
|
+
WeiboOAuth2::Config.redirect_uri = YOUR_CALLBACK_URL
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
If you are developing in your localhost, you can set YOUR_CALLBACK_URL as 'http://127.0.0.1/callback' something. Then set your weibo app account's callback URL as this URL too. Weibo will call the URL using GET method, which will then enable you to retrieve the authorization code.
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
client = WeiboOAuth2::Client.new
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Or you can pass the key and secret to new a client if you did not set WeiboOAuth2::Config
|
|
50
|
+
|
|
51
|
+
Redirect to this URL. If user grants you permission, then you will get the authorization code.
|
|
52
|
+
|
|
53
|
+
```ruby
|
|
54
|
+
client.authorize_url
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
In your callback handling method, you should add something like the following,
|
|
58
|
+
|
|
59
|
+
```ruby
|
|
60
|
+
client.auth_code.get_token(params[:code])
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
which will give permission to your client.
|
|
64
|
+
|
|
65
|
+
2. How to post a status with picture? (or call other interfaces)
|
|
66
|
+
|
|
67
|
+
Simply update a status
|
|
68
|
+
|
|
69
|
+
```ruby
|
|
70
|
+
client.statuses.update(params[:status])
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Upload a picture.
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
pic = params[:file].delete(:tempfile)
|
|
77
|
+
client.statuses.upload(params[:status], pic, params[:file])
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
pass params[:file] into upload method as options could help weibo_2 to build post body, useful options as:
|
|
81
|
+
* filename, filename with extension of the uploading file, example 'pic.jpg'
|
|
82
|
+
* type, mime type of the uploading file, example 'image/jpeg'
|
|
83
|
+
|
|
84
|
+
## Setting up SSL certificates
|
|
85
|
+
|
|
86
|
+
This gem using [faraday](https://github.com/technoweenie/faraday) for connection, which supports ssl. According to [this article](https://github.com/lostisland/faraday/wiki/Setting-up-SSL-certificates), you can do as following to support ssl connection.
|
|
87
|
+
|
|
88
|
+
### Ubuntu
|
|
89
|
+
|
|
90
|
+
To locate your SSL certificate folder, type `openssl version -a`. Append `/certs` to the OPENSSLDIR listed, here it would be `/usr/lib/ssl/certs`.
|
|
91
|
+
|
|
92
|
+
```ruby
|
|
93
|
+
client = WeiboOAuth2::Client.new(YOUR_KEY, YOUR_SECRET, :ssl => {:ca_path => "/usr/lib/ssl/certs"})
|
|
94
|
+
# or as below if you have set WeiboOAuth2::Config.api_key and WeiboOAuth2::Config.api_secret already
|
|
95
|
+
# client = WeiboOAuth2::Client.new('', '', :ssl => {:ca_path => "/usr/lib/ssl/certs"})
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### On Heroku, Fedora, CentOS
|
|
99
|
+
|
|
100
|
+
```ruby
|
|
101
|
+
client = WeiboOAuth2::Client.new(YOUR_KEY, YOUR_SECRET, :ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'})
|
|
102
|
+
# or as below if you have set WeiboOAuth2::Config.api_key and WeiboOAuth2::Config.api_secret already
|
|
103
|
+
# client = WeiboOAuth2::Client.new('', '', :ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'})
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
For Fedora and CentOS, use the path and file `/etc/pki/tls/certs/ca-bundle.crt` instead, or find your system path with `openssl version -a`.
|
|
107
|
+
|
|
108
|
+
## Integrate with Devise and omniauth
|
|
109
|
+
|
|
110
|
+
1. Install gems in Gemfile
|
|
111
|
+
|
|
112
|
+
```ruby
|
|
113
|
+
gem 'devise'
|
|
114
|
+
gem 'omniauth'
|
|
115
|
+
gem 'omniauth-weibo-oauth2'
|
|
116
|
+
gem 'weibo_2'
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
2. In devise initailize file config/initiallizers/devise.rb, add a line into setup block, please replace key and secret with yours.
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
config.omniauth :weibo, 'key', 'secret', :scope => 'user,public_repo'
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
3. Then you should handle omini callback controller by yourself, there is sample project show how to integrate devise and omniauth you can follow [devise-omniauth-example](https://github.com/holden/devise-omniauth-example)
|
|
127
|
+
|
|
128
|
+
4. After get the callback data, you will see `env['omniauth.auth']['credentials']` has the value `token` and `expires_at`, store them into session or record,now you can use WeiboOAuth2 in anywhere:
|
|
129
|
+
|
|
130
|
+
```ruby
|
|
131
|
+
client = WeiboOAuth2::Client.new
|
|
132
|
+
client.get_token_from_hash({:access_token=>session[:token],:expires_at=>session[:expires_at]})
|
|
133
|
+
statuses = client.statuses
|
|
134
|
+
statuses.update('just test from my app')
|
|
135
|
+
```
|
data/Rakefile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module WeiboOAuth2
|
|
2
|
+
class AccessToken < OAuth2::AccessToken
|
|
3
|
+
|
|
4
|
+
def validated?
|
|
5
|
+
!!expires_at && !expired?
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def expired?
|
|
9
|
+
expires? && (expires_at < time_convertion(Time.now, '+08:00').to_i)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
#Convert Time from a time zone to another time zone
|
|
14
|
+
#'+08:00' or '-08:00'
|
|
15
|
+
#return Time
|
|
16
|
+
def time_convertion(time, time_zone)
|
|
17
|
+
time.getutc.getlocal(time_zone)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module WeiboOAuth2
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
class Account < Base
|
|
5
|
+
|
|
6
|
+
#read interfaces
|
|
7
|
+
def get_privacy(opt={})
|
|
8
|
+
hashie get("account/get_privacy.json", :params => opt)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def profile_school_list(opt={})
|
|
12
|
+
hashie get("account/profile/school_list.json", :params => opt)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def rate_limit_status(opt={})
|
|
16
|
+
hashie get("account/rate_limit_status.json", :params => opt)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_uid(opt={})
|
|
20
|
+
hashie get("account/get_uid.json", :params => opt)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
#write interfaces
|
|
24
|
+
def end_session(opt={})
|
|
25
|
+
hashie get("account/end_session.json", :params => opt)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require 'hashie'
|
|
2
|
+
require 'json'
|
|
3
|
+
require 'net/http/post/multipart'
|
|
4
|
+
|
|
5
|
+
module WeiboOAuth2
|
|
6
|
+
module Api
|
|
7
|
+
module V2
|
|
8
|
+
class Base
|
|
9
|
+
extend Forwardable
|
|
10
|
+
|
|
11
|
+
def_delegators :@access_token, :get, :post, :put, :delete
|
|
12
|
+
|
|
13
|
+
@@API_VERSION = 2
|
|
14
|
+
|
|
15
|
+
def initialize(access_token)
|
|
16
|
+
@access_token = access_token
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def hashie(response)
|
|
20
|
+
json_body = MultiJson.decode(response.body)
|
|
21
|
+
if json_body.is_a? Array
|
|
22
|
+
Array.new(json_body.count){|i| Hashie::Mash.new(json_body[i])}
|
|
23
|
+
else
|
|
24
|
+
Hashie::Mash.new json_body
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
protected
|
|
29
|
+
def mime_type(file)
|
|
30
|
+
case
|
|
31
|
+
when file =~ /\.jpeg$/i then 'image/jpeg'
|
|
32
|
+
when file =~ /\.jpg$/i then 'image/jpeg'
|
|
33
|
+
when file =~ /\.gif$/i then 'image/gif'
|
|
34
|
+
when file =~ /\.png$/i then 'image/png'
|
|
35
|
+
when file =~ /\.tiff$/i then 'image/tiff'
|
|
36
|
+
else 'image/jpeg'
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def bin_encode(chunk)
|
|
41
|
+
chunk.force_encoding(Encoding::BINARY) if chunk.respond_to? :force_encoding
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
CRLF = "\r\n"
|
|
45
|
+
def build_multipart_bodies(parts, opts)
|
|
46
|
+
boundary = Time.now.to_i.to_s(16)
|
|
47
|
+
|
|
48
|
+
body = bin_encode('')
|
|
49
|
+
|
|
50
|
+
parts.each do |key, value|
|
|
51
|
+
esc_key = CGI.escape(key.to_s)
|
|
52
|
+
body << bin_encode("--#{boundary}#{CRLF}")
|
|
53
|
+
if value.respond_to?(:read)
|
|
54
|
+
filename = opts.delete(:filename) || File.basename(value.path)
|
|
55
|
+
mime_type = opts.delete(:type) || mime_type(value.path)
|
|
56
|
+
|
|
57
|
+
body << bin_encode("Content-Disposition: form-data; name=\"#{esc_key}\"; filename=\"#{filename}\"#{CRLF}")
|
|
58
|
+
body << bin_encode("Content-Type: #{mime_type}#{CRLF}")
|
|
59
|
+
body << bin_encode("Content-Transfer-Encoding: binary#{CRLF*2}")
|
|
60
|
+
body << bin_encode(value.read)
|
|
61
|
+
else
|
|
62
|
+
body << bin_encode("Content-Disposition: form-data; name=\"#{esc_key}\"#{CRLF*2}#{value}")
|
|
63
|
+
end
|
|
64
|
+
body << bin_encode(CRLF)
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
body << bin_encode("--#{boundary}--#{CRLF*2}")
|
|
69
|
+
|
|
70
|
+
{
|
|
71
|
+
:body => body,
|
|
72
|
+
:headers => {"Content-Type" => "multipart/form-data; boundary=#{boundary}"}
|
|
73
|
+
}
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module WeiboOAuth2
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
class Comments < Base
|
|
5
|
+
|
|
6
|
+
#read interfaces
|
|
7
|
+
def show(id, opt={})
|
|
8
|
+
hashie get("comments/show.json", :params => {:id => id}.merge(opt))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def by_me(opt={})
|
|
12
|
+
hashie get("comments/by_me.json", :params => opt)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_me(opt={})
|
|
16
|
+
hashie get("comments/to_me.json", :params => opt)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def timeline(opt={})
|
|
20
|
+
hashie get("comments/timeline.json", :params => opt)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def mentions(opt={})
|
|
24
|
+
hashie get("comments/mentions.json", :params => opt)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def show_batch(cids, opt={})
|
|
28
|
+
hashie get("comments/show_batch.json", :params => {:cids => cids}.merge(opt))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
#write interfaces
|
|
32
|
+
def create(comment, id, opt={})
|
|
33
|
+
hashie post("comments/create.json", :params => {:comment => comment, :id => id}.merge(opt))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def destroy(cid, opt={})
|
|
37
|
+
hashie post("comments/destroy.json", :params => {:cid => cid}.merge(opt))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def destroy_batch(cids, opt={})
|
|
41
|
+
hashie post("comments/destroy_batch.json", :params => {:cids => cids}.merge(opt))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def reply(cid, id, comment, opt={})
|
|
45
|
+
hashie post("comments/reply.json", :params => {:cid => cid, :id => id, :comment => comment}.merge(opt))
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module WeiboOAuth2
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
class Common < Base
|
|
5
|
+
#read interfaces
|
|
6
|
+
def code_to_location(codes, opt={})
|
|
7
|
+
hashie get("common/code_to_location", :params => {:codes => codes}.merge(opt))
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def get_city(province, opt={})
|
|
11
|
+
hashie get("common/send", :params => {:province => province}.merge(opt))
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def get_province(country, opt={})
|
|
15
|
+
hashie get("common/send", :params => {:country => country}.merge(opt))
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def get_country(opt={})
|
|
19
|
+
hashie get("common/send", :params => {:uids => uids, :tpl_id => tpl_id}.merge(opt))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def get_timezone(opt={})
|
|
23
|
+
hashie get("common/send", :params => {:uids => uids, :tpl_id => tpl_id}.merge(opt))
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module WeiboOAuth2
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
class Favorites < Base
|
|
5
|
+
|
|
6
|
+
#read interfaces
|
|
7
|
+
def favorites(opt={})
|
|
8
|
+
hashie get("favorites.json", :params => opt)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def ids(opt={})
|
|
12
|
+
hashie get("favorites/ids.json", :params => opt)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def show(id, opt={})
|
|
16
|
+
hashie get("favorites/show.json", :params => {:id => id}.merge(opt))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def by_tags(tid, opt={})
|
|
20
|
+
hashie get("favorites/by_tags.json", :params => {:tid => tid}.merge(opt))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def tags(opt={})
|
|
24
|
+
hashie get("favorites/tags.json", :params => opt)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def by_tags_ids(tid, opt={})
|
|
28
|
+
hashie get("favorites/by_tags/ids.json", :params => {:tid => tid}.merge(opt))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
#write interfaces
|
|
32
|
+
def create(id, opt={})
|
|
33
|
+
hashie post("favorites/create.json", :params => {:id => id}.merge(opt))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def destroy(id, opt={})
|
|
37
|
+
hashie post("favorites/destroy.json", :params => {:id => id}.merge(opt))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def destroy_batch(ids, opt={})
|
|
41
|
+
hashie post("favorites/destroy_batch.json", :params => {:ids => ids}.merge(opt))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def tags_update(id, tags, opt={})
|
|
45
|
+
hashie post("favorites/tags/update.json", :params => {:id => id, :tags => CGI::escape(tags)}.merge(opt))
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def tags_update_batch(tid, tag, opt={})
|
|
49
|
+
hashie post("favorites/tags/update_batch.json", :params => {:tid => tid, :tag => CGI::escape(tag)}.merge(opt))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def tags_destroy_batch(tid, opt={})
|
|
53
|
+
hashie post("favorites/tags/destroy_batch.json", :params => {:tid => tid}.merge(opt))
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module WeiboOAuth2
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
class Friendships < Base
|
|
5
|
+
|
|
6
|
+
#read interfaces
|
|
7
|
+
def friends(opt={})
|
|
8
|
+
hashie get("friendships/friends.json", :params => opt)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def friends_in_common(uid, opt={})
|
|
12
|
+
hashie get("friendships/friends/in_common.json", :params => {:uid => uid}.merge(opt))
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def friends_bilateral(uid, opt={})
|
|
16
|
+
hashie get("friendships/friends/bilateral.json", :params => {:uid => uid}.merge(opt))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def friends_bilateral_ids(uid, opt={})
|
|
20
|
+
hashie get("friendships/friends/bilateral/ids.json", :params => {:uid => uid}.merge(opt))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def friends_ids(opt={})
|
|
24
|
+
hashie get("friendships/friends/ids.json", :params => opt)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def followers(opt={})
|
|
28
|
+
hashie get("friendships/followers.json", :params => opt)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def followers_ids(opt={})
|
|
32
|
+
hashie get("friendships/followers/ids.json", :params => opt)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def followers_active(uid, opt={})
|
|
36
|
+
hashie get("friendships/followers/active.json", :params => {:uid => uid}.merge(opt))
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def friends_chain_followers(uid, opt={})
|
|
40
|
+
hashie get("friendships/friends_chain/followers.json", :params => {:uid => uid}.merge(opt))
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def show(opt={})
|
|
44
|
+
hashie get("friendships/show.json", :params => opt)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
#write interfaces
|
|
49
|
+
def create(opt={})
|
|
50
|
+
hashie post("friendships/create.json", :params => opt)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def destroy(opt={})
|
|
54
|
+
hashie post("friendships/destroy.json", :params => opt)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def remark_update(uid, remark, opt={})
|
|
58
|
+
hashie post("friendships/remark/update.json", :params => {:uid => uid, :remark => remark}.merge(opt))
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module WeiboOAuth2
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
class Location < Base
|
|
5
|
+
|
|
6
|
+
#read interfaces
|
|
7
|
+
def base_get_map_image(opt={})
|
|
8
|
+
hashie get("location/base/get_map_image.json", :params => opt)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def geo_ip_to_geo(ip, opt={})
|
|
12
|
+
hashie get("location/geo/ip_to_geo.json", :params => {:ip => ip}.merge(opt))
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def geo_address_to_geo(address, opt={})
|
|
16
|
+
hashie get("location/geo/address_to_geo.json", :params => {:address => address}.merge(opt))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def geo_geo_to_address(coordinate, opt={})
|
|
20
|
+
hashie get("location/geo/geo_to_address.json", :params => {:coordinate => coordinate}.merge(opt))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def geo_gps_to_offset(coordinate, opt={})
|
|
24
|
+
hashie get("location/geo/gps_to_offset.json", :params => {:coordinate => coordinate}.merge(opt))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def geo_is_domestic(coordinates, opt={})
|
|
28
|
+
hashie get("location/geo/is_domestic.json", :params => {:coordinate => coordinate}.merge(opt))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def pois_show_batch(srcids, opt={})
|
|
32
|
+
hashie get("location/pois/show_batch.json", :params => {:srcids => srcids}.merge(opt))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def pois_search_by_location(opt={})
|
|
36
|
+
hashie get("location/pois/search/by_location.json", :params => opt)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def pois_search_by_geo(opt={})
|
|
40
|
+
hashie get("location/pois/search/by_geo.json", :params => opt)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def pois_search_by_area(coordinates, opt={})
|
|
44
|
+
hashie get("location/pois/search/by_area.json", :params => {:coordinate => coordinate}.merge(opt))
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
#to implement
|
|
48
|
+
def mobile_get_location(opt={})
|
|
49
|
+
#hashie get("location/mobile/get_location.json", :params => opt)
|
|
50
|
+
nil
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def line_drive_route(opt={})
|
|
54
|
+
hashie get("location/line/drive_route.json", :params => opt)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def line_bus_route(opt={})
|
|
58
|
+
hashie get("location/line/bus_route.json", :params => opt)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def line_bus_line(q, opt={})
|
|
62
|
+
hashie get("location/line/bus_line.json", :params => {:q => q}.merge(opt))
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def line_bus_station(q, opt={})
|
|
66
|
+
hashie get("location/line/bus_station.json", :params => {:q => q}.merge(opt))
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
#write interfaces
|
|
70
|
+
def pois_add(srcid, name, address, city_name, category, longitude, latitude, opt={})
|
|
71
|
+
hashie post("location/pois/add.json", :params => {:srcid => srcid,
|
|
72
|
+
:name => name,
|
|
73
|
+
:address => address,
|
|
74
|
+
:city_name => city_name,
|
|
75
|
+
:category => category,
|
|
76
|
+
:longitude => longitude,
|
|
77
|
+
:latitude => latitude}.merge(opt))
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|