Class: Fakesite::Wechat::Base
- Inherits:
-
Base
- Object
- Base
- Fakesite::Wechat::Base
- Includes:
- WebMock::API
- Defined in:
- lib/fakesite/wechat/base.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.match(external_uri) ⇒ Object
55 56 57 |
# File 'lib/fakesite/wechat/base.rb', line 55 def self.match(external_uri) external_uri.host == Host end |
Instance Method Details
#parameters ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fakesite/wechat/base.rb', line 6 def parameters now = Time.now.to_i.to_s { "code" => now, "state" => external_params["state"], "openid" => openid.to_s, "access_token" => "T#{now}", "refresh_token" => "R#{now}", "scope" => external_params["scope"], "nickname" => nickname, "sex" => sex, "province" => province, "city" => city, "country" => country, "headimgurl" => headimgurl } end |
#return_parameters ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fakesite/wechat/base.rb', line 24 def return_parameters openid = params["openid"] body = {} ["openid", "access_token", "refresh_token", "scope"].each do |key| body[key] = params[key] params.delete(key) end body["expires_in"] = 7200 stub_request(:get, "https://#{ApiHost}/sns/oauth2/access_token") .with(:query => hash_including({:code => params["code"]})) .to_return(:status => 200, :body => body.to_json) body = {} ["nickname", "sex", "province", "city", "country", "headimgurl"].each do |key| body[key] = params[key] params.delete(key) end stub_request(:get, "https://#{ApiHost}/sns/userinfo") .with(:query => hash_including({:openid => openid})) .to_return(:status => 200, :body => body.to_json) return params end |
#return_url ⇒ Object
51 52 53 |
# File 'lib/fakesite/wechat/base.rb', line 51 def return_url external_params["redirect_uri"] end |