zendesk2 0.2.3 → 0.2.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.
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.3
@@ -3,6 +3,15 @@ class Zendesk2::Client::Organizations < Zendesk2::Collection
3
3
 
4
4
  model Zendesk2::Client::Organization
5
5
 
6
+ def find_by_external_id(external_id)
7
+ body = connection.get_organization_by_external_id(external_id).body
8
+ if data = body.delete("organizations")
9
+ collection = self.clone.load(data)
10
+ collection.merge_attributes(Cistern::Hash.slice(body, "count", "next_page", "previous_page"))
11
+ collection
12
+ end
13
+ end
14
+
6
15
  self.collection_method = :get_organizations
7
16
  self.collection_root = "organizations"
8
17
  self.model_method = :get_organization
@@ -0,0 +1,24 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def get_organization_by_external_id(external_id)
4
+ request(
5
+ :method => :get,
6
+ :params => {external_id: external_id},
7
+ :path => "/organizations/search.json",
8
+ )
9
+ end
10
+ end # Real
11
+
12
+ class Mock
13
+ def get_organization_by_external_id(external_id)
14
+ collection = self.data[:organizations]
15
+
16
+ results = collection.select{|k,v| v["external_id"] == external_id}.values
17
+
18
+ response(
19
+ :path => "/organizations/search.json",
20
+ :body => {"organizations" => results},
21
+ )
22
+ end
23
+ end # Mock
24
+ end
@@ -62,6 +62,7 @@ class Zendesk2::Client < Cistern::Service
62
62
  request :get_group
63
63
  request :get_groups
64
64
  request :get_organization
65
+ request :get_organization_by_external_id
65
66
  request :get_organization_tickets
66
67
  request :get_organization_users
67
68
  request :get_organizations
@@ -1,3 +1,3 @@
1
1
  module Zendesk2
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
@@ -8,7 +8,6 @@ describe "organizations" do
8
8
 
9
9
  describe "with an organization" do
10
10
  let(:organization) { client.organizations.create(name: Zendesk2.uuid) }
11
-
12
11
  it "should get #users" do
13
12
  user = client.users.create(email: "#{Zendesk2.uuid}@example.org", name: Zendesk2.uuid, organization: organization)
14
13
  organization.users.should include user
@@ -25,5 +24,15 @@ describe "organizations" do
25
24
  model = client.organizations.create(name: organization.name)
26
25
  model.errors.should == {"name" => ["Name has already been taken"]}
27
26
  end
27
+
28
+ it "should be able to find organizations by external id" do
29
+ o = organization
30
+ external_id = o.name + "_foo"
31
+ o.external_id = external_id
32
+ o.save
33
+ found = client.organizations.find_by_external_id(external_id).first
34
+ found.should === o
35
+ end
36
+
28
37
  end
29
38
  end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: zendesk2
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.3
5
+ version: 0.2.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Josh Lane
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-09 00:00:00.000000000 Z
12
+ date: 2013-05-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cistern
@@ -83,6 +83,7 @@ extensions: []
83
83
  extra_rdoc_files: []
84
84
  files:
85
85
  - .gitignore
86
+ - .rvmrc
86
87
  - .travis.yml
87
88
  - Gemfile
88
89
  - Guardfile
@@ -149,6 +150,7 @@ files:
149
150
  - lib/zendesk2/client/requests/get_group.rb
150
151
  - lib/zendesk2/client/requests/get_groups.rb
151
152
  - lib/zendesk2/client/requests/get_organization.rb
153
+ - lib/zendesk2/client/requests/get_organization_by_external_id.rb
152
154
  - lib/zendesk2/client/requests/get_organization_tickets.rb
153
155
  - lib/zendesk2/client/requests/get_organization_users.rb
154
156
  - lib/zendesk2/client/requests/get_organizations.rb