Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rails_dingtalk
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
other
rails_dingtalk
Commits
b5f2d6d4
Commit
b5f2d6d4
authored
Sep 05, 2021
by
mingyuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new api acces in header
parent
a48066c3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
2 deletions
+30
-2
new.rb
app/apis/dingtalk/api/new.rb
+28
-0
http_client.rb
app/apis/dingtalk/http_client.rb
+2
-2
No files found.
app/apis/dingtalk/api/new.rb
View file @
b5f2d6d4
...
@@ -19,5 +19,33 @@ module Dingtalk::Api
...
@@ -19,5 +19,33 @@ module Dingtalk::Api
BASE
BASE
end
end
def
get
(
path
,
params:
{},
headers:
{},
base:
base_host
,
as:
nil
)
with_access_token
(
headers
)
do
|
with_token_headers
|
@client
.
get
path
,
headers:
with_token_headers
,
params:
params
,
base:
base
,
as:
as
end
end
def
post
(
path
,
params:
{},
headers:
{},
base:
base_host
,
**
payload
)
with_access_token
(
headers
)
do
|
with_token_headers
|
@client
.
post
path
,
payload
.
to_json
,
headers:
with_token_headers
,
params:
params
,
base:
base
end
end
def
post_file
(
path
,
file
,
params:
{},
headers:
{},
base:
base_host
)
with_access_token
(
headers
)
do
|
with_token_headers
|
@client
.
post_file
path
,
file
,
headers:
with_token_headers
,
params:
params
,
base:
base
end
end
protected
def
with_access_token
(
headers
=
{},
tries
=
2
)
app
.
refresh_access_token
unless
app
.
access_token_valid?
yield
headers
.
merge!
(
Authorization
:
"Bearer
#{
app
.
access_token
}
"
)
rescue
=>
e
Rails
.
logger
.
debug
e
.
full_message
app
.
refresh_access_token
retry
unless
(
tries
-=
1
).
zero?
end
end
end
end
end
app/apis/dingtalk/http_client.rb
View file @
b5f2d6d4
...
@@ -70,11 +70,11 @@ module Dingtalk
...
@@ -70,11 +70,11 @@ module Dingtalk
# 40001, invalid credential, access_token is invalid or not latest hint
# 40001, invalid credential, access_token is invalid or not latest hint
# 48001, api unauthorized hint, should not handle here # GH-230
# 48001, api unauthorized hint, should not handle here # GH-230
when
42001
,
40014
,
40001
,
41001
when
42001
,
40014
,
40001
,
41001
raise
Wechat
::
AccessTokenExpiredError
raise
Dingtalk
::
AccessTokenExpiredError
# 40029, invalid code for mp # GH-225
# 40029, invalid code for mp # GH-225
# 43004, require subscribe hint # GH-214
# 43004, require subscribe hint # GH-214
when
2
when
2
raise
Wechat
::
ResponseError
.
new
(
data
[
'errcode'
],
data
[
'errmsg'
])
raise
Dingtalk
::
ResponseError
.
new
(
data
[
'errcode'
],
data
[
'errmsg'
])
else
else
data
data
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment