kf5_api 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 021bcb2f3706a298a1b08023f3940b9f9b2c78b0
4
- data.tar.gz: e0114920cfe089c8df3a2a71f2966d955f7b2de4
3
+ metadata.gz: 36977e52da8bba66c0448dd5735af2df9b0e750c
4
+ data.tar.gz: 02dcc9daabfe66b7c0ffbef52ff67c8e966acccc
5
5
  SHA512:
6
- metadata.gz: f76300e19a6190c30510f03221f53fdf239126f52d403205d98dfb1e44c61a348415fa1d3c87ef8deb3e057dc50bac5db9549461078efffd55a5386813d8696b
7
- data.tar.gz: b70113a6511e1bd9983cc2ae68d691616b20c0bfcbab7b9875d2f1fc9997b6ed5936292e19bacd7b3cd6407512e3960c85f41b7c3da4f35ee846edd7f9a05801
6
+ metadata.gz: 38caf766baf959535f2f2f59788ffd55662fe09e3ebbbe407b54871556ae5a274c03dd0f813aac6d2a86b57e082022619108c1e16c367e4058aa36a44e06f316
7
+ data.tar.gz: c68ba513a8a1b221291dece4d3cc5afbee92b7034fc805018fcbfda11325d3dc93b0890ff4a8620027573f6d888503ea5d7a34a45d7cbc5b7f4fbf15025bb43d
@@ -20,5 +20,9 @@ module Kf5Api
20
20
  def logger
21
21
  @logger ||= Logger.new(STDOUT)
22
22
  end
23
+
24
+ def server
25
+ "https://#{Kf5Api.config.sub_domain}.kf5.com"
26
+ end
23
27
  end
24
28
  end
@@ -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
- server = "https://#{Kf5Api.config.sub_domain}.kf5.com"
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Kf5Api
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
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.3
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-07-11 00:00:00.000000000 Z
11
+ date: 2017-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler