weibo_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/weibo_api/configuration.rb +11 -0
- data/lib/weibo_api/endpoint.rb +48 -0
- data/lib/weibo_api/user.rb +40 -0
- data/lib/weibo_api/version.rb +3 -0
- data/lib/weibo_api.rb +8 -0
- data/weibo_api.gemspec +27 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 240ec3775db755ee4a9dfb4a9f4d23f0ffb2d3679740d729bd7f4f6f727d5ac6
|
4
|
+
data.tar.gz: a64866a07c43824e2104c91a75d00b9f9dc188f23d58dd32e140c14c13d38dca
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d4c7bae3a41e126b845ec821340e8c73fdb1220964c80677e8e56a4068f17664fb3a080a1bb119b376ddeb6f3f90caf68d49026f9f391f9b8c306d044393e8dc
|
7
|
+
data.tar.gz: e055f376210fec8b0ed3ebcabff8ff319a3d71651926e39adacf8e4224f244bf009018f828ca58bab0af1ba2f06956d933bba1fafa9bc69fcf6580632a670d73
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 oren
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# WeiboApi
|
2
|
+
|
3
|
+
A Ruby wrapper for the Weibo API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'weibo_api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install weibo_api
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
**config/initializers/weibo_api.rb**
|
24
|
+
```ruby
|
25
|
+
WeiboApi.config do |config|
|
26
|
+
config.client_id = ENV['weibo_client_id']
|
27
|
+
config.client_secret = ENV['weibo_client_secret']
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ocarta-l/weibo_api.
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "weibo_api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'hashie'
|
3
|
+
|
4
|
+
module WeiboApi
|
5
|
+
module Endpoint
|
6
|
+
include HTTParty
|
7
|
+
|
8
|
+
BASE_API_URI = 'https://api.weibo.com/2'.freeze
|
9
|
+
|
10
|
+
ERROR_CODES = {
|
11
|
+
400 => BadRequest,
|
12
|
+
404 => NotFound,
|
13
|
+
429 => TooManyRequests,
|
14
|
+
500 => InternalServerError,
|
15
|
+
502 => BadGateway,
|
16
|
+
503 => ServiceUnavailable,
|
17
|
+
504 => GatewayTimeout
|
18
|
+
}.freeze
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def resource_path(id = nil, opts = {})
|
23
|
+
suffix = id.to_s
|
24
|
+
params = opts.map { |k, v| "#{k}=#{v}" }.join('&')
|
25
|
+
"#{BASE_API_URI}/#{suffix}.json?#{params}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def make_request(url, options, method = :get)
|
29
|
+
response = HTTParty.send(method, url, options)
|
30
|
+
return parse_success response if response.success?
|
31
|
+
parse_failed response
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def parse_success(response)
|
37
|
+
response_hash = JSON.parse(response.body).merge(
|
38
|
+
limit: response.headers['x-ratelimit-limit'],
|
39
|
+
remaining: response.headers['x-ratelimit-remaining']
|
40
|
+
)
|
41
|
+
::Hashie::Mash.new(response_hash)
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse_failed(response)
|
45
|
+
response.parsed_response
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module WeiboApi
|
2
|
+
class User
|
3
|
+
include Endpoint
|
4
|
+
|
5
|
+
def initialize(access_token, uid)
|
6
|
+
@access_token = access_token
|
7
|
+
@uid = uid
|
8
|
+
end
|
9
|
+
|
10
|
+
# Return the authenticating user's personnal infos or the one specified on the options (uid).
|
11
|
+
def info(options = {})
|
12
|
+
params = options.merge(access_token: @access_token, uid: @uid) { |_, important, _| important }
|
13
|
+
make_request resource_path('users/show', params), {}
|
14
|
+
end
|
15
|
+
|
16
|
+
# Return the authenticating user's followers statistics.
|
17
|
+
# [WIP]
|
18
|
+
def statistics(options = {})
|
19
|
+
params = options.merge(access_token: @access_token, uid: @uid) { |_, important, _| important }
|
20
|
+
make_request resource_path('friendships/followers', params), {}
|
21
|
+
end
|
22
|
+
|
23
|
+
# Return the authenticating user's latest weibos.
|
24
|
+
def timeline(options = {})
|
25
|
+
params = options.merge(access_token: @access_token, trim_user: 1) { |_, important, _| important }
|
26
|
+
make_request resource_path('statuses/user_timeline', params), {}
|
27
|
+
end
|
28
|
+
|
29
|
+
# Return the single weibo's content by its ID
|
30
|
+
def show_status(id)
|
31
|
+
params = { access_token: @access_token, id: id }
|
32
|
+
make_request resource_path('statuses/show', params), {}
|
33
|
+
end
|
34
|
+
|
35
|
+
def custom_request(path, options = {})
|
36
|
+
params = options.merge(access_token: @access_token) { |_, important, _| important }
|
37
|
+
make_request resource_path(path, params), {}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/weibo_api.rb
ADDED
data/weibo_api.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'weibo_api/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'weibo_api'
|
7
|
+
spec.version = WeiboApi::VERSION
|
8
|
+
spec.authors = ['oren']
|
9
|
+
spec.email = ['oren.carta-lag@hotmail.fr']
|
10
|
+
|
11
|
+
spec.summary = 'A Ruby wrapper for the Weibo API v2.'
|
12
|
+
spec.description = 'A Ruby wrapper for the Weibo API v2.'
|
13
|
+
spec.homepage = 'http://rubygems.org/gems/weibo_api'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = 'exe'
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
24
|
+
spec.add_development_dependency 'hashie', '~> 0'
|
25
|
+
spec.add_development_dependency 'httparty', '~> 0'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: weibo_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- oren
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hashie
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httparty
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: A Ruby wrapper for the Weibo API v2.
|
70
|
+
email:
|
71
|
+
- oren.carta-lag@hotmail.fr
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- bin/console
|
82
|
+
- bin/setup
|
83
|
+
- lib/weibo_api.rb
|
84
|
+
- lib/weibo_api/configuration.rb
|
85
|
+
- lib/weibo_api/endpoint.rb
|
86
|
+
- lib/weibo_api/user.rb
|
87
|
+
- lib/weibo_api/version.rb
|
88
|
+
- weibo_api.gemspec
|
89
|
+
homepage: http://rubygems.org/gems/weibo_api
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.7.3
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: A Ruby wrapper for the Weibo API v2.
|
113
|
+
test_files: []
|