bridge_api 0.1.19 → 0.1.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bridge_api/client/user.rb +35 -0
- data/lib/bridge_api/version.rb +1 -1
- data/spec/bridge_api/client/user_spec.rb +3 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bce329056305672b1df2fcdc6c87a60bdbc73202
|
4
|
+
data.tar.gz: f7c19e775975de6873784c6fe6ad283bc2004285
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1198ac3d96bb9dfc31eb30fddd422561f64af2fce5a4d9a92a800f99b105100d57dba1400a902fe213aaadd9cacf013b958f6948cacb299c10493fe290a6f76f
|
7
|
+
data.tar.gz: 9724c5b3ea3f44ce435f35f9797f9fb63b64110fb0ceb0efbd22a446161d4e960703818ab2c5f588eb56c7d58c78fe48d2ddae0d122ccc2e193793c8a0489842
|
@@ -18,10 +18,45 @@ module BridgeAPI
|
|
18
18
|
put("#{API_PATH}#{AUTHOR_PATH}#{USER_PATH}/#{user_id}", params)
|
19
19
|
end
|
20
20
|
|
21
|
+
# Used for easier handling of updating custom params. This method will handle the lookup
|
22
|
+
# of existing custom_field_value ids and insert them as needed.
|
23
|
+
# ++user_id++ Bridge user ID
|
24
|
+
# ++custom_params++ See ++build_custom_values_payload++ method for formatting.
|
25
|
+
# ++params++ any bridge allowed params to be updated on the user
|
26
|
+
def update_user_with_custom_values(user_id, custom_params, params = {})
|
27
|
+
params ||= {}
|
28
|
+
params['user'] ||= {}
|
29
|
+
params['user']['custom_field_values'] = build_custom_values_payload(user_id, custom_params)
|
30
|
+
update_user(user_id, params)
|
31
|
+
end
|
32
|
+
|
21
33
|
def get_all_users(params = {})
|
22
34
|
get("#{API_PATH}#{AUTHOR_PATH}#{USER_PATH}", params)
|
23
35
|
end
|
24
36
|
|
37
|
+
private
|
38
|
+
|
39
|
+
#++user_id++ Bridge user ID
|
40
|
+
#++custom_field_values++ Hash of custom field id with associated value
|
41
|
+
# {
|
42
|
+
# '1': 'My Custom Value To Be Updated',
|
43
|
+
# '2': 'Another Custom Value'
|
44
|
+
# }
|
45
|
+
def build_custom_values_payload(user_id, custom_field_values)
|
46
|
+
users = self.get_user(user_id, {'includes[]' => 'custom_fields'})
|
47
|
+
payload = []
|
48
|
+
return payload unless users.members.size > 0
|
49
|
+
existing_values = users.linked['custom_field_values']
|
50
|
+
custom_field_values.each do |field_id, value|
|
51
|
+
field_value_id = existing_values.find {|v|
|
52
|
+
v['links']['custom_field']['id'] == field_id.to_s rescue false
|
53
|
+
}['id'] rescue nil
|
54
|
+
payload << {'id' => field_value_id, 'custom_field_id' => field_id, 'value' => value}
|
55
|
+
end
|
56
|
+
payload
|
57
|
+
end
|
58
|
+
|
25
59
|
end
|
60
|
+
|
26
61
|
end
|
27
62
|
end
|
data/lib/bridge_api/version.rb
CHANGED
@@ -24,6 +24,9 @@ describe BridgeAPI::Client::User do
|
|
24
24
|
it 'should update a user' do
|
25
25
|
response = @client.update_user(1)
|
26
26
|
expect(response.first['id']).to(eq("10"))
|
27
|
+
|
28
|
+
response = @client.update_user_with_custom_values(1, {'1' => 'test'})
|
29
|
+
expect(response.first['id']).to(eq("10"))
|
27
30
|
end
|
28
31
|
|
29
32
|
it 'should get all users' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bridge_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jay Shaffer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -254,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
254
254
|
version: '0'
|
255
255
|
requirements: []
|
256
256
|
rubyforge_project:
|
257
|
-
rubygems_version: 2.
|
257
|
+
rubygems_version: 2.6.14
|
258
258
|
signing_key:
|
259
259
|
specification_version: 4
|
260
260
|
summary: Bridge API
|
@@ -290,3 +290,4 @@ test_files:
|
|
290
290
|
- spec/fixtures/users.json
|
291
291
|
- spec/support/fake_bridge.rb
|
292
292
|
- spec/test_helper.rb
|
293
|
+
has_rdoc:
|