kf5_api 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/kf5_api.rb +4 -0
- data/lib/kf5_api/base.rb +13 -2
- data/lib/kf5_api/user.rb +16 -1
- data/lib/kf5_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36977e52da8bba66c0448dd5735af2df9b0e750c
|
4
|
+
data.tar.gz: 02dcc9daabfe66b7c0ffbef52ff67c8e966acccc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38caf766baf959535f2f2f59788ffd55662fe09e3ebbbe407b54871556ae5a274c03dd0f813aac6d2a86b57e082022619108c1e16c367e4058aa36a44e06f316
|
7
|
+
data.tar.gz: c68ba513a8a1b221291dece4d3cc5afbee92b7034fc805018fcbfda11325d3dc93b0890ff4a8620027573f6d888503ea5d7a34a45d7cbc5b7f4fbf15025bb43d
|
data/lib/kf5_api.rb
CHANGED
data/lib/kf5_api/base.rb
CHANGED
@@ -2,9 +2,9 @@ require 'httparty'
|
|
2
2
|
|
3
3
|
module Kf5Api
|
4
4
|
module Base
|
5
|
+
|
5
6
|
def get(action, query_params = {})
|
6
|
-
|
7
|
-
url = server + action
|
7
|
+
url = Kf5Api.server + action
|
8
8
|
query_params = query_params.inject({}){ |memo, (k,v)| memo[k.to_s] = v; memo }
|
9
9
|
|
10
10
|
response = HTTParty.get(url, query: query_params, basic_auth: basic_auth, header: { 'Content-Type' => 'application/json' })
|
@@ -16,6 +16,17 @@ module Kf5Api
|
|
16
16
|
response
|
17
17
|
end
|
18
18
|
|
19
|
+
def put(action, body)
|
20
|
+
url = Kf5Api.server + action
|
21
|
+
response = HTTParty.put(url, body: body.to_json, basic_auth: basic_auth, header: { 'Content-Type' => 'application/json' })
|
22
|
+
|
23
|
+
unless response.code == 200
|
24
|
+
Kf5Api.logger.error "[Kf5Api] url: #{url}, status: #{response.code}, body: #{response.parsed_response}"
|
25
|
+
end
|
26
|
+
|
27
|
+
response
|
28
|
+
end
|
29
|
+
|
19
30
|
def basic_auth(user_name = nil, password = nil, use_password = false)
|
20
31
|
user_name ||= use_password ? Kf5Api.config.user_name : "#{Kf5Api.config.user_name}/token"
|
21
32
|
password ||= use_password ? Kf5Api.config.password : Kf5Api.config.token
|
data/lib/kf5_api/user.rb
CHANGED
@@ -5,7 +5,9 @@ module Kf5Api
|
|
5
5
|
# http://developer.kf5.com/restfulapi/core/users
|
6
6
|
|
7
7
|
ACTIONS_HASH = {
|
8
|
-
users_by_org: '/apiv2/organizations/%{id}/users'
|
8
|
+
users_by_org: '/apiv2/organizations/%{id}/users',
|
9
|
+
edit: '/apiv2/users/%{id}',
|
10
|
+
search: '/apiv2/users/search'
|
9
11
|
}
|
10
12
|
|
11
13
|
class << self
|
@@ -14,6 +16,19 @@ module Kf5Api
|
|
14
16
|
action = format(ACTIONS_HASH[:users_by_org], id: org_id)
|
15
17
|
get(action, query_params).parsed_response
|
16
18
|
end
|
19
|
+
|
20
|
+
# 修改用户信息
|
21
|
+
def edit(id, attributes = {})
|
22
|
+
action = format(ACTIONS_HASH[:edit], id: id)
|
23
|
+
put(action, attributes).parsed_response
|
24
|
+
end
|
25
|
+
|
26
|
+
# 查询用户信息
|
27
|
+
# query为查询参数,模糊搜索(名称,邮箱,手机号,微信openid)
|
28
|
+
def search(keyword)
|
29
|
+
action = format(ACTIONS_HASH[:search])
|
30
|
+
get(action, { query: keyword }).parsed_response
|
31
|
+
end
|
17
32
|
end
|
18
33
|
end
|
19
34
|
end
|
data/lib/kf5_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kf5_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wangrui
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|