Commit 55c72892a6ac4e27d68fa8c79af66c23e5d9e103
1 parent
55a7562f
Exists in
master
Add basic suite api
Showing
4 changed files
with
75 additions
and
0 deletions
Show diff stats
lib/dingtalk.rb
... | ... | @@ -0,0 +1,30 @@ |
1 | +module Dingtalk | |
2 | + module Api | |
3 | + class Base | |
4 | + attr_accessor :corp_id | |
5 | + | |
6 | + def initialize(corp_id = nil) | |
7 | + @corp_id = corp_id | |
8 | + end | |
9 | + | |
10 | + private | |
11 | + def http_get(url, params = {}) | |
12 | + res = RestClient.get(request_url(url), params.to_json, content_type: :json) | |
13 | + JSON.parse(res) | |
14 | + end | |
15 | + | |
16 | + def http_post | |
17 | + res = RestClient.post(request_url(url), params.to_json, content_type: :json) | |
18 | + JSON.parse(res) | |
19 | + end | |
20 | + | |
21 | + def base_url | |
22 | + '' | |
23 | + end | |
24 | + | |
25 | + def request_url(url) | |
26 | + "#{ENDPOINT}/#{base_url}/#{url}" | |
27 | + end | |
28 | + end | |
29 | + end | |
30 | +end | ... | ... |
... | ... | @@ -0,0 +1,40 @@ |
1 | +module Dingtalk | |
2 | + module Api | |
3 | + class Suite < Base | |
4 | + def initialize(suite_key, suite_secret, suite_ticket, suite_access_token) | |
5 | + @suite_key = suite_key | |
6 | + # put suite ticket to redis | |
7 | + @suite_ticket = suite_ticket | |
8 | + # put suite access token to redis | |
9 | + @suite_access_token = suite_access_token | |
10 | + end | |
11 | + | |
12 | + def get_permanent_code(tmp_auth_code) | |
13 | + params = { | |
14 | + suite_access_token: @suite_access_token, | |
15 | + tmp_auth_code: tmp_auth_code | |
16 | + } | |
17 | + http_get('get_permanent_code', params) | |
18 | + end | |
19 | + | |
20 | + def suite_access_token | |
21 | + # get from redis or set it | |
22 | + end | |
23 | + | |
24 | + def set_suite_access_token | |
25 | + params = { | |
26 | + suite_key: @suite_key, | |
27 | + suite_secret: @suite_secret, | |
28 | + suite_ticket: @suite_ticket | |
29 | + } | |
30 | + http_post(request_url(get_suite_token), params) | |
31 | + # set suite_access_token to redis | |
32 | + end | |
33 | + | |
34 | + private | |
35 | + def base_url | |
36 | + 'service' | |
37 | + end | |
38 | + end | |
39 | + end | |
40 | +end | ... | ... |