From 55c72892a6ac4e27d68fa8c79af66c23e5d9e103 Mon Sep 17 00:00:00 2001 From: Jeff Lai Date: Mon, 29 Feb 2016 14:43:19 +0800 Subject: [PATCH] Add basic suite api --- lib/dingtalk.rb | 1 + lib/dingtalk/api/base.rb | 30 ++++++++++++++++++++++++++++++ lib/dingtalk/api/suite.rb | 40 ++++++++++++++++++++++++++++++++++++++++ lib/dingtalk/suite.rb | 4 ++++ 4 files changed, 75 insertions(+), 0 deletions(-) create mode 100644 lib/dingtalk/api/base.rb create mode 100644 lib/dingtalk/api/suite.rb create mode 100644 lib/dingtalk/suite.rb diff --git a/lib/dingtalk.rb b/lib/dingtalk.rb index 55dd029..21695f6 100644 --- a/lib/dingtalk.rb +++ b/lib/dingtalk.rb @@ -3,5 +3,6 @@ require "dingtalk/pkcs7_encoder" require "dingtalk/prpcrypt" module Dingtalk + ENDPOINT = "https://oapi.dingtalk.com" # Your code goes here... end diff --git a/lib/dingtalk/api/base.rb b/lib/dingtalk/api/base.rb new file mode 100644 index 0000000..6d82625 --- /dev/null +++ b/lib/dingtalk/api/base.rb @@ -0,0 +1,30 @@ +module Dingtalk + module Api + class Base + attr_accessor :corp_id + + def initialize(corp_id = nil) + @corp_id = corp_id + end + + private + def http_get(url, params = {}) + res = RestClient.get(request_url(url), params.to_json, content_type: :json) + JSON.parse(res) + end + + def http_post + res = RestClient.post(request_url(url), params.to_json, content_type: :json) + JSON.parse(res) + end + + def base_url + '' + end + + def request_url(url) + "#{ENDPOINT}/#{base_url}/#{url}" + end + end + end +end diff --git a/lib/dingtalk/api/suite.rb b/lib/dingtalk/api/suite.rb new file mode 100644 index 0000000..1b61219 --- /dev/null +++ b/lib/dingtalk/api/suite.rb @@ -0,0 +1,40 @@ +module Dingtalk + module Api + class Suite < Base + def initialize(suite_key, suite_secret, suite_ticket, suite_access_token) + @suite_key = suite_key + # put suite ticket to redis + @suite_ticket = suite_ticket + # put suite access token to redis + @suite_access_token = suite_access_token + end + + def get_permanent_code(tmp_auth_code) + params = { + suite_access_token: @suite_access_token, + tmp_auth_code: tmp_auth_code + } + http_get('get_permanent_code', params) + end + + def suite_access_token + # get from redis or set it + end + + def set_suite_access_token + params = { + suite_key: @suite_key, + suite_secret: @suite_secret, + suite_ticket: @suite_ticket + } + http_post(request_url(get_suite_token), params) + # set suite_access_token to redis + end + + private + def base_url + 'service' + end + end + end +end diff --git a/lib/dingtalk/suite.rb b/lib/dingtalk/suite.rb new file mode 100644 index 0000000..7d914f1 --- /dev/null +++ b/lib/dingtalk/suite.rb @@ -0,0 +1,4 @@ +module Dingtalk + class Suite + end +end -- libgit2 0.21.0