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
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module WeiboOAuth2
|
|
2
|
+
module Config
|
|
3
|
+
|
|
4
|
+
def self.api_key=(val)
|
|
5
|
+
@@api_key = val
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def self.api_key
|
|
9
|
+
@@api_key ||= nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.api_secret=(val)
|
|
13
|
+
@@api_secret = val
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.api_secret
|
|
17
|
+
@@api_secret ||= nil
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.redirect_uri=(val)
|
|
21
|
+
@@redirect_uri = val
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.redirect_uri
|
|
25
|
+
@@redirect_uri ||= nil
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module WeiboOAuth2
|
|
2
|
+
module Errors
|
|
3
|
+
class WeiboError < StandardError
|
|
4
|
+
attr_reader :data
|
|
5
|
+
def initialize(data)
|
|
6
|
+
@data = data
|
|
7
|
+
super
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class GeneralError < WeiboError
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class RateLimitedError < WeiboError
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class UnauthorizedError < WeiboError
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module WeiboOAuth2
|
|
2
|
+
module Strategy
|
|
3
|
+
class AuthCode < OAuth2::Strategy::AuthCode
|
|
4
|
+
def get_token(code, params={}, opts={})
|
|
5
|
+
params = {'grant_type' => 'authorization_code',
|
|
6
|
+
'code' => code,
|
|
7
|
+
'redirect_uri' => WeiboOAuth2::Config.redirect_uri.to_s}.merge(client_params).merge(params)
|
|
8
|
+
@client.get_and_restore_token(params, opts)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module WeiboOAuth2
|
|
2
|
+
|
|
3
|
+
class Version
|
|
4
|
+
MAJOR = 0 unless defined? MAJOR
|
|
5
|
+
MINOR = 1 unless defined? MINOR
|
|
6
|
+
PATCH = 7 unless defined? PATCH
|
|
7
|
+
PRE = nil unless defined? PRE
|
|
8
|
+
|
|
9
|
+
class << self
|
|
10
|
+
|
|
11
|
+
# @return [String]
|
|
12
|
+
def to_s
|
|
13
|
+
[MAJOR, MINOR, PATCH, PRE].compact.join('.')
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/weibo_2.rb
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require "weibo_2/version"
|
|
2
|
+
require "weibo_2/config"
|
|
3
|
+
require "weibo_2/base"
|
|
4
|
+
require "weibo_2/client"
|
|
5
|
+
require "weibo_2/errors"
|
|
6
|
+
require "weibo_2/access_token"
|
|
7
|
+
require "weibo_2/api/v2/base"
|
|
8
|
+
require "weibo_2/api/v2/statuses"
|
|
9
|
+
require "weibo_2/api/v2/users"
|
|
10
|
+
require "weibo_2/api/v2/comments"
|
|
11
|
+
require "weibo_2/api/v2/friendships"
|
|
12
|
+
require "weibo_2/api/v2/account"
|
|
13
|
+
require "weibo_2/api/v2/favorites"
|
|
14
|
+
require "weibo_2/api/v2/trends"
|
|
15
|
+
require "weibo_2/api/v2/tags"
|
|
16
|
+
require "weibo_2/api/v2/register"
|
|
17
|
+
require "weibo_2/api/v2/search"
|
|
18
|
+
require "weibo_2/api/v2/short_url"
|
|
19
|
+
require "weibo_2/api/v2/suggestions"
|
|
20
|
+
require "weibo_2/api/v2/remind"
|
|
21
|
+
require "weibo_2/api/v2/place"
|
|
22
|
+
require "weibo_2/api/v2/location"
|
|
23
|
+
require "weibo_2/strategy/auth_code"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
if defined?(Rails)
|
|
27
|
+
module WeiboOAuth2
|
|
28
|
+
class Railtie < Rails::Railtie
|
|
29
|
+
initializer "weibo_oauth2" do
|
|
30
|
+
ActiveSupport.on_load :action_controller do
|
|
31
|
+
if Object.const_defined?("Devise") && Devise.omniauth_configs[:weibo]
|
|
32
|
+
WeiboOAuth2::Config.api_key = Devise.omniauth_configs[:weibo].args[0]
|
|
33
|
+
WeiboOAuth2::Config.api_secret = Devise.omniauth_configs[:weibo].args[1]
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
data/spec/client_spec.rb
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'weibo_2'
|
|
2
|
+
|
|
3
|
+
WeiboOAuth2::Config.api_key = 'abc'
|
|
4
|
+
WeiboOAuth2::Config.api_secret = 'def'
|
|
5
|
+
WeiboOAuth2::Config.redirect_uri = 'https://example.com/callback'
|
|
6
|
+
|
|
7
|
+
describe WeiboOAuth2::Client do
|
|
8
|
+
it 'should assign id and secret from config' do
|
|
9
|
+
subject.id.should == 'abc'
|
|
10
|
+
subject.secret.should == 'def'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'should assign site from default' do
|
|
14
|
+
subject.site.should == 'https://api.weibo.com/2/'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'should get authorize_url' do
|
|
18
|
+
authorize_url = 'https://api.weibo.com/oauth2/authorize?client_id=abc&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&response_type=code'
|
|
19
|
+
subject.authorize_url.should == authorize_url
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'should leave Faraday::Connection#ssl unset' do
|
|
23
|
+
subject.connection.ssl.empty?.should be_truthy
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "defaults raise_errors to true" do
|
|
27
|
+
subject.options[:raise_errors].should be_truthy
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "allows true/false for raise_errors option" do
|
|
31
|
+
client = OAuth2::Client.new('abc', 'def', :site => 'https://api.example.com', :raise_errors => false)
|
|
32
|
+
client.options[:raise_errors].should be_falsey
|
|
33
|
+
client = OAuth2::Client.new('abc', 'def', :site => 'https://api.example.com', :raise_errors => true)
|
|
34
|
+
client.options[:raise_errors].should be_truthy
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "allows get/post for access_token_method option" do
|
|
38
|
+
client = OAuth2::Client.new('abc', 'def', :site => 'https://api.example.com', :access_token_method => :get)
|
|
39
|
+
client.options[:access_token_method].should == :get
|
|
40
|
+
client = OAuth2::Client.new('abc', 'def', :site => 'https://api.example.com', :access_token_method => :post)
|
|
41
|
+
client.options[:access_token_method].should == :post
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
data/weibo_2.gemspec
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require File.expand_path('../lib/weibo_2/version', __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |gem|
|
|
5
|
+
gem.authors = ["simsicon"]
|
|
6
|
+
gem.email = ["simsicon@gmail.com"]
|
|
7
|
+
gem.description = %q{WeioOAuth2 is a Ruby gem that provides a wrapper for interacting with sina weibo's v2 API,
|
|
8
|
+
which is currently the latest version. The output data format is Hashie::Mash}
|
|
9
|
+
gem.summary = "A oauth2 gem for weibo"
|
|
10
|
+
gem.homepage = "https://github.com/shixiancom/weibo_2"
|
|
11
|
+
|
|
12
|
+
gem.files = `git ls-files`.split($\)
|
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
15
|
+
gem.name = "shixian_weibo_2"
|
|
16
|
+
gem.require_paths = ["lib"]
|
|
17
|
+
gem.version = WeiboOAuth2::Version
|
|
18
|
+
|
|
19
|
+
gem.add_development_dependency "rspec", "~> 2.6"
|
|
20
|
+
|
|
21
|
+
gem.add_runtime_dependency 'oauth2', "~> 1.3.1"
|
|
22
|
+
gem.add_runtime_dependency 'hashie', "~> 3.5.5"
|
|
23
|
+
gem.add_runtime_dependency 'multi_json' , "~> 1"
|
|
24
|
+
gem.add_runtime_dependency 'rest-client', "~> 2.0.2"
|
|
25
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: shixian_weibo_2
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.7
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- simsicon
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2025-07-06 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rspec
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '2.6'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2.6'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: oauth2
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 1.3.1
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 1.3.1
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: hashie
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 3.5.5
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 3.5.5
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: multi_json
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rest-client
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: 2.0.2
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: 2.0.2
|
|
83
|
+
description: |-
|
|
84
|
+
WeioOAuth2 is a Ruby gem that provides a wrapper for interacting with sina weibo's v2 API,
|
|
85
|
+
which is currently the latest version. The output data format is Hashie::Mash
|
|
86
|
+
email:
|
|
87
|
+
- simsicon@gmail.com
|
|
88
|
+
executables: []
|
|
89
|
+
extensions: []
|
|
90
|
+
extra_rdoc_files: []
|
|
91
|
+
files:
|
|
92
|
+
- ".gitignore"
|
|
93
|
+
- Gemfile
|
|
94
|
+
- LICENSE
|
|
95
|
+
- README.md
|
|
96
|
+
- Rakefile
|
|
97
|
+
- lib/weibo_2.rb
|
|
98
|
+
- lib/weibo_2/access_token.rb
|
|
99
|
+
- lib/weibo_2/api/v2/account.rb
|
|
100
|
+
- lib/weibo_2/api/v2/base.rb
|
|
101
|
+
- lib/weibo_2/api/v2/comments.rb
|
|
102
|
+
- lib/weibo_2/api/v2/common.rb
|
|
103
|
+
- lib/weibo_2/api/v2/favorites.rb
|
|
104
|
+
- lib/weibo_2/api/v2/friendships.rb
|
|
105
|
+
- lib/weibo_2/api/v2/location.rb
|
|
106
|
+
- lib/weibo_2/api/v2/notification.rb
|
|
107
|
+
- lib/weibo_2/api/v2/place.rb
|
|
108
|
+
- lib/weibo_2/api/v2/register.rb
|
|
109
|
+
- lib/weibo_2/api/v2/remind.rb
|
|
110
|
+
- lib/weibo_2/api/v2/search.rb
|
|
111
|
+
- lib/weibo_2/api/v2/short_url.rb
|
|
112
|
+
- lib/weibo_2/api/v2/statuses.rb
|
|
113
|
+
- lib/weibo_2/api/v2/suggestions.rb
|
|
114
|
+
- lib/weibo_2/api/v2/tags.rb
|
|
115
|
+
- lib/weibo_2/api/v2/trends.rb
|
|
116
|
+
- lib/weibo_2/api/v2/users.rb
|
|
117
|
+
- lib/weibo_2/base.rb
|
|
118
|
+
- lib/weibo_2/client.rb
|
|
119
|
+
- lib/weibo_2/config.rb
|
|
120
|
+
- lib/weibo_2/errors.rb
|
|
121
|
+
- lib/weibo_2/oauth.rb
|
|
122
|
+
- lib/weibo_2/strategy/auth_code.rb
|
|
123
|
+
- lib/weibo_2/version.rb
|
|
124
|
+
- spec/client_spec.rb
|
|
125
|
+
- weibo_2.gemspec
|
|
126
|
+
homepage: https://github.com/shixiancom/weibo_2
|
|
127
|
+
licenses: []
|
|
128
|
+
metadata: {}
|
|
129
|
+
post_install_message:
|
|
130
|
+
rdoc_options: []
|
|
131
|
+
require_paths:
|
|
132
|
+
- lib
|
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '0'
|
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
|
+
requirements:
|
|
140
|
+
- - ">="
|
|
141
|
+
- !ruby/object:Gem::Version
|
|
142
|
+
version: '0'
|
|
143
|
+
requirements: []
|
|
144
|
+
rubygems_version: 3.5.18
|
|
145
|
+
signing_key:
|
|
146
|
+
specification_version: 4
|
|
147
|
+
summary: A oauth2 gem for weibo
|
|
148
|
+
test_files:
|
|
149
|
+
- spec/client_spec.rb
|