weixin_js_sdk 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a7c77eb5bf4e109a1ceb2cdca6e42f737978da3
4
- data.tar.gz: c3b3100872590b03b809bd0901161e9c69d71a97
3
+ metadata.gz: ec9759260f854f08d5fc61c89030156e39216add
4
+ data.tar.gz: 7531d01eb33b517e15754fc90747b474596ee447
5
5
  SHA512:
6
- metadata.gz: 0b383adf3263554e16055152360c9002979d4a6c8ab6ab8e1486554ed55056410e436ad77159d5d63fc89ee8404d6ba104f424051df03701f0a4f92afc2ec897
7
- data.tar.gz: 0ed647af36e5e34ca666742d06e800c8eff3683048ff4b9ec7212f452712526079ddbe97cbc78086f827df6c5d0c841d8556ff51de5d5d23ed669007bedb237a
6
+ metadata.gz: e47835f4c5e060ba8b292a00438bb07ff8a4b12cd0214b46b85858cbc10c40c8000c392ab300ece5a4d9aa00e659076a453cfb69eb5effb4e642bb972ef39146
7
+ data.tar.gz: 9748612a4ba156f49715fd446df638d308ffd74540fb8f912971218cb33b6ca15f2877bb5ae5fd7e99f1de250b670d00d98648ddf4d69fa2153086c3a0e4d787
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## v0.0.2
6
+
7
+ * Deprecated `fetch`
8
+ * Add `token` and `expires_in` to WeixinJsSDK::AccessToken
9
+ * Add `token` and `expires_in` to WeixinJsSDK::Ticket
10
+
5
11
  ## v0.0.1
6
12
 
7
13
  * Initial release
data/README.md CHANGED
@@ -30,22 +30,30 @@ Or install it yourself as:
30
30
  access_token = WeixinJsSDK::AccessToken.new(
31
31
  app_id: ENV['WEIXIN_APP_ID'],
32
32
  app_secret: ENV['WEIXIN_APP_SECRET']
33
- ).fetch
33
+ )
34
+ #=> #<WeixinJsSDK::AccessToken:0x007ff9c488a111>
35
+ access_token.token
34
36
  #=> xxx
37
+ access_token.expires_in
38
+ #=> 7200
35
39
  ```
36
40
 
37
41
  * Fetch Ticket
38
42
 
39
43
  ```ruby
40
- ticket = WeixinJsSDK::Ticket.new(access_token: access_token).fetch
44
+ ticket = WeixinJsSDK::Ticket.new(access_token: access_token.token)
45
+ #=> #<WeixinJsSDK::Ticket:0x007fe62d133c68>
46
+ ticket.token
41
47
  #=> xxx
48
+ ticket.expires_in
49
+ #=> 7200
42
50
  ```
43
51
 
44
52
  * Generate Signature
45
53
 
46
54
  ```ruby
47
55
  signature = WeixinJsSDK::Signature.new(
48
- ticket: ticket,
56
+ ticket: ticket.token,
49
57
  nonce_str: 'Wm3WZYTPz0wzccnW',
50
58
  timestamp: '1414587457',
51
59
  url: 'http://mp.weixin.qq.com'
@@ -2,23 +2,26 @@ module WeixinJsSDK
2
2
  class AccessToken
3
3
  URI_TEMPLATE = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%{app_id}&secret=%{app_secret}'.freeze
4
4
 
5
- def initialize(app_id:, app_secret:)
6
- @app_id = app_id
7
- @app_secret = app_secret
8
- end
5
+ attr_reader :token, :expires_in
9
6
 
10
- def fetch
7
+ def initialize(app_id: '', app_secret: '')
11
8
  url = URI_TEMPLATE % {
12
- app_id: @app_id,
13
- app_secret: @app_secret
9
+ app_id: app_id,
10
+ app_secret: app_secret
14
11
  }
15
12
 
16
13
  json = Util.get_json(url)
17
14
 
18
- access_token = json['access_token']
19
- expires_in = json['expires_in']
15
+ @token = json['access_token']
16
+ @expires_in = json['expires_in']
17
+ end
20
18
 
21
- access_token
19
+ # <b>DEPRECATED:</b> Please use <tt>token</tt> instead.
20
+ def fetch
21
+ warn "[DEPRECATION] `fetch` is deprecated. Please use `token` instead."
22
+ token
22
23
  end
24
+
25
+ alias_method :access_token, :token
23
26
  end
24
27
  end
@@ -5,7 +5,7 @@ module WeixinJsSDK
5
5
  class InvalidRequest < Standard
6
6
  DOC_URI = 'http://mp.weixin.qq.com/wiki/17/fa4e1434e57290788bde25603fa2fcbd.html'.freeze
7
7
 
8
- def initialize(error_code:, message:)
8
+ def initialize(error_code: '', message: '')
9
9
  @error_code = error_code
10
10
  @message = message
11
11
  end
@@ -4,7 +4,7 @@ module WeixinJsSDK
4
4
  class Signature
5
5
  TEMPLATE = 'jsapi_ticket=%{jsapi_ticket}&noncestr=%{nonce_str}&timestamp=%{timestamp}&url=%{url}'.freeze
6
6
 
7
- def initialize(ticket:, nonce_str:, timestamp:, url:)
7
+ def initialize(ticket: '', nonce_str: '', timestamp: '', url: '')
8
8
  @ticket = ticket
9
9
  @nonce_str = nonce_str
10
10
  @timestamp = timestamp
@@ -19,8 +19,6 @@ module WeixinJsSDK
19
19
  url: @url
20
20
  }
21
21
 
22
- puts str
23
-
24
22
  Digest::SHA1.hexdigest(str)
25
23
  end
26
24
  end
@@ -2,21 +2,25 @@ module WeixinJsSDK
2
2
  class Ticket
3
3
  URI_TEMPLATE = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%{access_token}&type=jsapi'.freeze
4
4
 
5
- def initialize(access_token:)
6
- @access_token = access_token
7
- end
5
+ attr_reader :token, :expires_in
8
6
 
9
- def fetch
7
+ def initialize(access_token: '')
10
8
  url = URI_TEMPLATE % {
11
- access_token: @access_token
9
+ access_token: access_token
12
10
  }
13
11
 
14
- json = Util.get_json(url)
12
+ json = Util.get_json(url) rescue {}
15
13
 
16
- ticket = json['ticket']
17
- expires_in = json['expires_in']
14
+ @token = json['ticket']
15
+ @expires_in = json['expires_in']
16
+ end
18
17
 
19
- ticket
18
+ # <b>DEPRECATED:</b> Please use <tt>token</tt> instead.
19
+ def fetch
20
+ warn "[DEPRECATION] `fetch` is deprecated. Please use `token` instead."
21
+ token
20
22
  end
23
+
24
+ alias_method :ticket, :token
21
25
  end
22
26
  end
@@ -1,3 +1,3 @@
1
1
  module WeixinJsSdk
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weixin_js_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jun Lin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-27 00:00:00.000000000 Z
11
+ date: 2015-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  version: '0'
108
108
  requirements: []
109
109
  rubyforge_project:
110
- rubygems_version: 2.2.2
110
+ rubygems_version: 2.4.5
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: A Weixin JS-SDK toolkit.