zendesk2 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zendesk2/client/requests/search_user.rb +30 -1
- data/lib/zendesk2/version.rb +1 -1
- data/spec/spec_helper.rb +2 -1
- data/spec/users_spec.rb +17 -0
- 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: 81bba9f58f738ec52054105fc508707dd9a7223b
|
4
|
+
data.tar.gz: 017e53e26dd7ba508aacd23094f96f966da76136
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab3815ee90b96f12fce67acf78a7aeed1fb90a98e52bf88d9dc246ecc085228b4dd587d2216b844107fb67ecdbe18979eae2e8658aabd46364ebd39d2bd459f5
|
7
|
+
data.tar.gz: dc2b8a2b14a1fac2179beb6b941aedae05b05289dd9cfa4ac984889f0ec68a7ece263e5130805ef53083e6d0295474efd0d3b460de9628ab3ed853006eea4bf4
|
@@ -9,13 +9,42 @@ class Zendesk2::Client
|
|
9
9
|
terms.delete("type") # context already provided
|
10
10
|
|
11
11
|
collection = self.data[:users].values
|
12
|
+
|
13
|
+
# create a copy of each user mapped to a specific user identity
|
12
14
|
collection = collection.map do |user|
|
13
15
|
self.data[:identities].values.select{|i| i["type"] == "email" && i["user_id"] == user["id"]}.map do |identity|
|
14
16
|
user.merge("email" => identity["value"])
|
15
17
|
end
|
16
18
|
end.flatten
|
17
19
|
|
18
|
-
|
20
|
+
# allow searching by organization name
|
21
|
+
collection = collection.map do |user|
|
22
|
+
if organization = self.data[:organizations][user["organization_id"]]
|
23
|
+
user.merge("organization" => organization["name"])
|
24
|
+
else
|
25
|
+
user
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# organization name is fuzzy matched
|
30
|
+
if organization_name = terms.delete("organization")
|
31
|
+
terms.merge!("organization" => "*#{organization_name}*")
|
32
|
+
end
|
33
|
+
|
34
|
+
compiled_terms = terms.inject({}) do |r,(term, raw_condition)|
|
35
|
+
condition = if raw_condition.include?("*")
|
36
|
+
Regexp.compile(raw_condition.gsub("*", ".*"), Regexp::IGNORECASE)
|
37
|
+
else
|
38
|
+
raw_condition
|
39
|
+
end
|
40
|
+
r.merge(term => condition)
|
41
|
+
end
|
42
|
+
|
43
|
+
results = collection.select do |v|
|
44
|
+
compiled_terms.all? do |term, condition|
|
45
|
+
condition.is_a?(Regexp) ? condition.match(v[term.to_s]) : v[term.to_s].to_s == condition.to_s
|
46
|
+
end
|
47
|
+
end
|
19
48
|
|
20
49
|
response(
|
21
50
|
:path => "/search.json",
|
data/lib/zendesk2/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -15,8 +15,9 @@ Cistern.formatter = Cistern::Formatter::AwesomePrint
|
|
15
15
|
RSpec.configure do |config|
|
16
16
|
if Zendesk2::Client.mocking?
|
17
17
|
config.before(:each) { Zendesk2::Client.reset! }
|
18
|
+
else
|
19
|
+
config.filter_run_excluding(mock_only: true)
|
18
20
|
end
|
19
21
|
|
20
22
|
config.order = "random"
|
21
|
-
config.filter_run_excluding(mock_only: true) unless Zendesk2::Client.mocking?
|
22
23
|
end
|
data/spec/users_spec.rb
CHANGED
@@ -14,6 +14,23 @@ describe "users" do
|
|
14
14
|
expect(current_user.email).to eq(client.username)
|
15
15
|
end
|
16
16
|
|
17
|
+
describe "#search" do
|
18
|
+
it "should find a user based on details criteria with wildcards and by organization name", mock_only: true do
|
19
|
+
# detached user
|
20
|
+
client.users.create!(email: "zendesk2+#{Zendesk2.uuid}@example.org", name: Zendesk2.uuid)
|
21
|
+
|
22
|
+
# possible match
|
23
|
+
bad_org = client.organizations.create!(name: Zendesk2.uuid)
|
24
|
+
client.users.create!(email: "zendesk2+#{Zendesk2.uuid}@example.org", name: Zendesk2.uuid, organization: bad_org)
|
25
|
+
|
26
|
+
org = client.organizations.create!(name: Zendesk2.uuid)
|
27
|
+
user = client.users.create!(email: "zendesk2+#{Zendesk2.uuid}@example.org", name: Zendesk2.uuid, organization: org, details: "anything_hello-something-michelle")
|
28
|
+
|
29
|
+
expect(client.users.search(details: "*michelle*", organization: org.name)).to contain_exactly(user)
|
30
|
+
expect(client.users.search(details: "*michelle*", organization: org.name[0..6])).to include(user)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
17
34
|
describe do
|
18
35
|
before(:each) do
|
19
36
|
@user = client.users.create!(email: "zendesk2+#{Zendesk2.uuid}@example.org", name: Zendesk2.uuid)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zendesk2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Lane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|