wework 0.3.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +0 -1
  3. data/README.md +7 -0
  4. data/lib/wework.rb +15 -10
  5. data/lib/wework/api/agent.rb +15 -79
  6. data/lib/wework/api/base.rb +24 -32
  7. data/lib/wework/api/contact.rb +1 -75
  8. data/lib/wework/api/corp.rb +29 -0
  9. data/lib/wework/api/methods/agent.rb +49 -0
  10. data/lib/wework/api/methods/approval.rb +16 -0
  11. data/lib/wework/api/methods/batch.rb +34 -0
  12. data/lib/wework/api/methods/checkin.rb +19 -0
  13. data/lib/wework/api/methods/department.rb +27 -0
  14. data/lib/wework/api/methods/media.rb +20 -0
  15. data/lib/wework/api/methods/menu.rb +21 -0
  16. data/lib/wework/api/methods/message.rb +52 -0
  17. data/lib/wework/api/methods/provider.rb +16 -0
  18. data/lib/wework/api/methods/suite.rb +53 -0
  19. data/lib/wework/api/methods/user.rb +35 -0
  20. data/lib/wework/api/provider.rb +13 -0
  21. data/lib/wework/api/suite.rb +72 -0
  22. data/lib/wework/cipher.rb +3 -0
  23. data/lib/wework/mock_api.rb +34 -0
  24. data/lib/wework/request.rb +3 -1
  25. data/lib/wework/token/app_token.rb +21 -0
  26. data/lib/wework/token/base.rb +59 -0
  27. data/lib/wework/token/corp_token.rb +20 -0
  28. data/lib/wework/token/js_ticket.rb +25 -0
  29. data/lib/wework/token/provider_token.rb +21 -0
  30. data/lib/wework/token/suite_token.rb +21 -0
  31. data/lib/wework/version.rb +1 -1
  32. data/mock_responses/agent/get.json +29 -0
  33. data/mock_responses/agent/list.json +16 -0
  34. data/mock_responses/agent/set.json +4 -0
  35. data/mock_responses/batch/getresult.json +8 -0
  36. data/mock_responses/department/list.json +24 -0
  37. data/mock_responses/error.json +4 -0
  38. data/mock_responses/files/party.csv +12 -0
  39. data/mock_responses/files/sample.amr +0 -0
  40. data/mock_responses/files/sample.mp4 +0 -0
  41. data/mock_responses/files/sample.txt +1 -0
  42. data/mock_responses/files/user.csv +2 -0
  43. data/mock_responses/files/zhiren.png +0 -0
  44. data/mock_responses/get_jsapi_ticket.json +6 -0
  45. data/mock_responses/gettoken.json +6 -0
  46. data/mock_responses/menu/get.json +24 -0
  47. data/mock_responses/service/get.json +0 -0
  48. data/mock_responses/service/get_corp_token.json +4 -0
  49. data/mock_responses/service/get_login_info.json +34 -0
  50. data/mock_responses/service/get_permanent_code.json +54 -0
  51. data/mock_responses/service/get_pre_auth_code.json +6 -0
  52. data/mock_responses/service/get_provider_token.json +4 -0
  53. data/mock_responses/service/get_suite_token.json +4 -0
  54. data/mock_responses/success.json +4 -0
  55. data/mock_responses/user/convert_to_openid.json +6 -0
  56. data/mock_responses/user/convert_to_userid.json +5 -0
  57. data/mock_responses/user/get.json +18 -0
  58. data/mock_responses/user/getuserdetail.json +10 -0
  59. data/mock_responses/user/getuserinfo.json +8 -0
  60. data/mock_responses/user/list.json +22 -0
  61. data/mock_responses/user/simplelist.json +11 -0
  62. data/wework.gemspec +6 -2
  63. metadata +114 -19
  64. data/lib/wework/engine.rb +0 -31
  65. data/lib/wework/js_ticket/redis_store.rb +0 -41
  66. data/lib/wework/js_ticket/store.rb +0 -36
  67. data/lib/wework/provider.rb +0 -39
  68. data/lib/wework/token/redis_store.rb +0 -41
  69. data/lib/wework/token/store.rb +0 -36
@@ -1,39 +0,0 @@
1
- module Wework
2
- class Provider
3
- include Wework::Cipher
4
-
5
- attr_accessor :corp_id, :provider_secret, :encoding_aes_key, :token
6
-
7
- def initialize(options={})
8
- @corp_id = options[:corp_id]
9
- @provider_secret = options[:provider_secret]
10
- @encoding_aes_key = options[:encoding_aes_key]
11
- @token = options[:token]
12
- end
13
-
14
- def msg_decrypt msg
15
- unpack(decrypt(Base64.decode64(msg), self.encoding_aes_key))[0]
16
- end
17
-
18
- def msg_encrypt msg
19
- Base64.strict_encode64(encrypt(pack(msg, self.corp_id), self.encoding_aes_key))
20
- end
21
-
22
- def signature(timestamp, nonce, encrypt)
23
- array = [self.token, timestamp, nonce]
24
- array << encrypt unless encrypt.nil?
25
- dev_msg_signature = array.compact.collect(&:to_s).sort.join
26
- Digest::SHA1.hexdigest(dev_msg_signature)
27
- end
28
-
29
- def generate_xml(msg, timestamp, nonce)
30
- encrypt = msg_encrypt(msg)
31
- {
32
- Encrypt: encrypt,
33
- MsgSignature: signature(timestamp, nonce, encrypt),
34
- TimeStamp: timestamp,
35
- Nonce: nonce
36
- }.to_xml(root: 'xml', children: 'item', skip_instruct: true, skip_types: true)
37
- end
38
- end
39
- end
@@ -1,41 +0,0 @@
1
- module Wework
2
- module Token
3
- class RedisStore < Store
4
-
5
- def initialize(agent)
6
- raise RedisNotConfigException if redis.nil?
7
- super
8
- end
9
-
10
- def access_token
11
- super
12
- redis.hget(key, "access_token")
13
- end
14
-
15
- def expired?
16
- redis.hvals(key).empty? || redis.hget(key, "expires_at").to_i <= Time.now.to_i
17
- end
18
-
19
- def refresh_token
20
- result = super
21
- unless result.access_token.nil?
22
- expires_at = Time.now.to_i + result.expires_in.to_i - Wework.expired_shift_seconds
23
- redis.hmset(
24
- key,
25
- "access_token", result.access_token,
26
- "expires_at", expires_at
27
- )
28
-
29
- redis.expireat(key, expires_at)
30
- end
31
- end
32
-
33
- private
34
-
35
- def redis
36
- Wework.redis
37
- end
38
-
39
- end
40
- end
41
- end
@@ -1,36 +0,0 @@
1
- module Wework
2
- module Token
3
- class Store
4
-
5
- attr_accessor :app
6
-
7
- def initialize(app)
8
- @app = app
9
- end
10
-
11
- def access_token
12
- refresh_token if expired?
13
- end
14
-
15
- def expired?
16
- raise NotImplementedError, "Subclasses must implement a token_expired? method"
17
- end
18
-
19
- def refresh_token
20
- result = app.request.get 'gettoken', params: {corpid: app.corp_id, corpsecret: app.app_secret}
21
- if defined?(Rails)
22
- Rails.logger.warn "[WEWORK] refresh Token(#{app.corp_id}): #{result.inspect}"
23
- end
24
-
25
- result
26
- end
27
-
28
- private
29
-
30
- def key
31
- @key ||= Digest::MD5.hexdigest("#{ACCESS_TOKEN_PREFIX}_#{app.app_id}_#{app.app_secret}")
32
- end
33
-
34
- end
35
- end
36
- end