Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
weixin_authorize
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
weixin_authorize
Commits
46c2f71b
Commit
46c2f71b
authored
Feb 11, 2015
by
lanrion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add more rest_client options config
parent
7c07e087
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
5 deletions
+16
-5
lib/weixin_authorize.rb
+6
-2
lib/weixin_authorize/config.rb
+9
-3
spec/spec_helper.rb
+1
-0
No files found.
lib/weixin_authorize.rb
View file @
46c2f71b
...
@@ -31,13 +31,17 @@ module WeixinAuthorize
...
@@ -31,13 +31,17 @@ module WeixinAuthorize
def
http_get_without_token
(
url
,
headers
=
{},
endpoint
=
"plain"
)
def
http_get_without_token
(
url
,
headers
=
{},
endpoint
=
"plain"
)
get_api_url
=
endpoint_url
(
endpoint
,
url
)
get_api_url
=
endpoint_url
(
endpoint
,
url
)
load_json
(
RestClient
.
get
(
get_api_url
,
:params
=>
headers
))
load_json
(
resource
(
get_api_url
).
get
(
params:
headers
))
end
end
def
http_post_without_token
(
url
,
payload
=
{},
headers
=
{},
endpoint
=
"plain"
)
def
http_post_without_token
(
url
,
payload
=
{},
headers
=
{},
endpoint
=
"plain"
)
post_api_url
=
endpoint_url
(
endpoint
,
url
)
post_api_url
=
endpoint_url
(
endpoint
,
url
)
payload
=
JSON
.
dump
(
payload
)
if
endpoint
==
"plain"
# to json if invoke "plain"
payload
=
JSON
.
dump
(
payload
)
if
endpoint
==
"plain"
# to json if invoke "plain"
load_json
(
RestClient
.
post
(
post_api_url
,
payload
,
:params
=>
headers
))
load_json
(
resource
(
post_api_url
).
post
(
payload
,
params:
headers
))
end
def
resource
(
url
)
RestClient
::
Resource
.
new
(
url
,
rest_client_options
)
end
end
# return hash
# return hash
...
...
lib/weixin_authorize/config.rb
View file @
46c2f71b
...
@@ -9,12 +9,18 @@ module WeixinAuthorize
...
@@ -9,12 +9,18 @@ module WeixinAuthorize
end
end
def
weixin_redis
def
weixin_redis
return
nil
if
WeixinAuthorize
.
config
.
nil?
return
nil
if
config
.
nil?
@redis
||=
WeixinAuthorize
.
config
.
redis
@redis
||=
config
.
redis
end
# 可选配置: RestClient timeout, etc.
# key 必须是符号
def
rest_client_options
config
.
rest_client_options
||
{
timeout:
2
,
open_timeout:
3
,
verify_ssl:
true
}
end
end
end
end
class
Config
class
Config
attr_accessor
:redis
attr_accessor
:redis
,
:rest_client_options
end
end
end
end
spec/spec_helper.rb
View file @
46c2f71b
...
@@ -55,6 +55,7 @@ redis_with_ns = Redis::Namespace.new("#{namespace}", :redis => redis)
...
@@ -55,6 +55,7 @@ redis_with_ns = Redis::Namespace.new("#{namespace}", :redis => redis)
WeixinAuthorize
.
configure
do
|
config
|
WeixinAuthorize
.
configure
do
|
config
|
config
.
redis
=
redis_with_ns
config
.
redis
=
redis_with_ns
config
.
rest_client_options
=
{
timeout:
1
,
open_timeout:
1
,
verify_ssl:
true
}
end
end
$client
=
WeixinAuthorize
::
Client
.
new
(
ENV
[
"APPID"
],
ENV
[
"APPSECRET"
])
$client
=
WeixinAuthorize
::
Client
.
new
(
ENV
[
"APPID"
],
ENV
[
"APPSECRET"
])
...
...
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