zendesk2 1.2.1 → 1.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da53e74ee09d2c85abc260d39f02878a346d769e
4
- data.tar.gz: 255c672c805f8bfd51b8bd3ee682fa6f5de1d30d
3
+ metadata.gz: 81bba9f58f738ec52054105fc508707dd9a7223b
4
+ data.tar.gz: 017e53e26dd7ba508aacd23094f96f966da76136
5
5
  SHA512:
6
- metadata.gz: 35529ac971be807243949d67d763a07192dd27491f8e16822ec0a2d27056c163bf5dbb2a590815c63d178ca2fffe82c4c2a5b5444ab9d22f9472a4a6823dffc9
7
- data.tar.gz: 53945ba5705d696416c9d7e073d3e9bdeb85b2143ee592f8e5874f6cdcb62940c97ae6c1493e0ce9fa77a99a84fa1dde864da810d262a2f4a85e85fa2341257c
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
- results = collection.select { |v| terms.all?{ |term, condition| v[term.to_s].to_s == condition.to_s } }
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",
@@ -1,3 +1,3 @@
1
1
  module Zendesk2
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  end
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.1
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-23 00:00:00.000000000 Z
11
+ date: 2014-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable