fakesite-wechat 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 +9 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +50 -0
- data/Rakefile +6 -0
- data/fakesite-wechat.gemspec +27 -0
- data/lib/fakesite/wechat.rb +12 -0
- data/lib/fakesite/wechat/base.rb +78 -0
- data/lib/fakesite/wechat/version.rb +5 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4319efd89f273702c31a2ecd19e95964e485a3ca
|
4
|
+
data.tar.gz: 52435c785d989d441bc36fb6315b57091714378d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cfb88162ba20e702fbf5f2882cffbf1b2f0ff93fc3db9a319d2fa1bce7fbff6ec2a9ab244b43213f0d195a50e09dd0fa5f7e38a7768672a79ecabc02c661df53
|
7
|
+
data.tar.gz: 975a54f64483b40336347fe39f0c5c95973000adcf672ac530a1b3af7e1bda0b80cf6acd709623b14700f242f5bbdbf5dbea0652cf2f4409adf400b7ebf2ae6f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Chen Yi-Cyuan
|
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,50 @@
|
|
1
|
+
# fakesite-wechat
|
2
|
+
|
3
|
+
[![Build Status](https://api.travis-ci.org/emn178/fakesite-wechat.png)](https://travis-ci.org/emn178/fakesite-wechat)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/emn178/fakesite-wechat/badge.svg?branch=master)](https://coveralls.io/r/emn178/fakesite-wechat?branch=master)
|
5
|
+
|
6
|
+
A [fakesite](https://github.com/emn178/fakesite) plugin that provides a stub method for wechat. It's useful to bypass oauth flow in develpment environment.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'fakesite-wechat', group: :development
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
### Route
|
21
|
+
Make sure that you have added fakesite route in your `config/route.rb`
|
22
|
+
```Ruby
|
23
|
+
mount Fakesite::Engine => "/fakesite" if Rails.env.development?
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
Add registration to `config/initializers/fakesite.rb`
|
28
|
+
```Ruby
|
29
|
+
if Rails.env.development?
|
30
|
+
WebMock.allow_net_connect!
|
31
|
+
# fill data from devise current_user, you can change this to get correct data automatically
|
32
|
+
options = {
|
33
|
+
# :nickname => :nickname,
|
34
|
+
# :sex => :sex,
|
35
|
+
# :province => :province,
|
36
|
+
# :city => :city,
|
37
|
+
# :country => :country,
|
38
|
+
# :headimgurl => :headimgurl
|
39
|
+
}
|
40
|
+
Fakesite.register :wechat, Fakesite::Wechat::Base, options
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
47
|
+
|
48
|
+
## Contact
|
49
|
+
The project's website is located at https://github.com/emn178/fakesite-wechat
|
50
|
+
Author: emn178@gmail.com
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fakesite/wechat/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fakesite-wechat"
|
8
|
+
spec.version = Fakesite::Wechat::VERSION
|
9
|
+
spec.authors = ["Chen Yi-Cyuan"]
|
10
|
+
spec.email = ["emn178@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A fakesite plugin that provides a stub method for wechat.}
|
13
|
+
spec.description = %q{A fakesite plugin that provides a stub method for wechat.}
|
14
|
+
spec.homepage = "https://github.com/emn178/fakesite-wechat"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "fakesite", ">= 0.2.3"
|
21
|
+
spec.add_dependency "webmock"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "rspec-its"
|
27
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Fakesite
|
2
|
+
module Wechat
|
3
|
+
class Base < Fakesite::Base
|
4
|
+
include WebMock::API
|
5
|
+
|
6
|
+
def parameters
|
7
|
+
now = Time.now.to_i.to_s
|
8
|
+
{
|
9
|
+
"code" => now,
|
10
|
+
"state" => external_params["state"],
|
11
|
+
"openid" => openid.to_s,
|
12
|
+
"access_token" => "T#{now}",
|
13
|
+
"refresh_token" => "R#{now}",
|
14
|
+
"scope" => external_params["scope"],
|
15
|
+
"nickname" => nickname,
|
16
|
+
"sex" => sex,
|
17
|
+
"province" => province,
|
18
|
+
"city" => city,
|
19
|
+
"country" => country,
|
20
|
+
"headimgurl" => headimgurl
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def return_parameters
|
25
|
+
openid = params["openid"]
|
26
|
+
|
27
|
+
body = {}
|
28
|
+
["openid", "access_token", "refresh_token", "scope"].each do |key|
|
29
|
+
body[key] = params[key]
|
30
|
+
params.delete(key)
|
31
|
+
end
|
32
|
+
body["expires_in"] = 7200
|
33
|
+
|
34
|
+
stub_request(:get, "https://#{ApiHost}/sns/oauth2/access_token")
|
35
|
+
.with(:query => hash_including({:code => params["code"]}))
|
36
|
+
.to_return(:status => 200, :body => body.to_json)
|
37
|
+
|
38
|
+
body = {}
|
39
|
+
["nickname", "sex", "province", "city", "country", "headimgurl"].each do |key|
|
40
|
+
body[key] = params[key]
|
41
|
+
params.delete(key)
|
42
|
+
end
|
43
|
+
|
44
|
+
stub_request(:get, "https://#{ApiHost}/sns/userinfo")
|
45
|
+
.with(:query => hash_including({:openid => openid}))
|
46
|
+
.to_return(:status => 200, :body => body.to_json)
|
47
|
+
|
48
|
+
return params
|
49
|
+
end
|
50
|
+
|
51
|
+
def return_url
|
52
|
+
external_params["redirect_uri"]
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.match(external_uri)
|
56
|
+
external_uri.host == Host
|
57
|
+
end
|
58
|
+
|
59
|
+
protected
|
60
|
+
|
61
|
+
def get_value(obj, attr_name)
|
62
|
+
!obj.nil? && obj.respond_to?(attr_name) ? obj.send(attr_name) : nil
|
63
|
+
end
|
64
|
+
|
65
|
+
def openid
|
66
|
+
get_value(user, :id)
|
67
|
+
end
|
68
|
+
|
69
|
+
[:nickname, :sex, :province, :city, :country, :headimgurl].each do |key|
|
70
|
+
name = key
|
71
|
+
define_method(name) do
|
72
|
+
attr_name = options[name] || name
|
73
|
+
get_value(user, attr_name)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fakesite-wechat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chen Yi-Cyuan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fakesite
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: webmock
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.10'
|
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
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-its
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: A fakesite plugin that provides a stub method for wechat.
|
98
|
+
email:
|
99
|
+
- emn178@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- CHANGELOG.md
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- fakesite-wechat.gemspec
|
113
|
+
- lib/fakesite/wechat.rb
|
114
|
+
- lib/fakesite/wechat/base.rb
|
115
|
+
- lib/fakesite/wechat/version.rb
|
116
|
+
homepage: https://github.com/emn178/fakesite-wechat
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.4.5
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: A fakesite plugin that provides a stub method for wechat.
|
140
|
+
test_files: []
|