zendesk2 1.5.8 → 1.5.9

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: 14e4bd18323a6ea77bb0845c4eae76f0862420c6
4
- data.tar.gz: 3fe8e0f33eeee1bcb958a4ff01cb52277c062271
3
+ metadata.gz: 932c737ddfb693f7b5d9b36402067de02a6c1ee9
4
+ data.tar.gz: f458a0b38c54c48fa1562286f00e561dc24f6a06
5
5
  SHA512:
6
- metadata.gz: 379a06d552705727b5754663d45e20cd9c1b869ff64818131c746de554840a80257928ccad653ddb72f717d20b6c64ef91920fce84a009b3c987152446922da9
7
- data.tar.gz: 1951ff8492d005f325008cf320e1fdb3361c0d8623f91ff3884e6eceac252446927a197427ccde9a551e2760b28d52a54ea7c446ed9c52e642c50cf957260334
6
+ metadata.gz: c887dc3ba7857f7d02ab28f8c3221d111dd87707cc8049cd93e4440205340c12aeaa0a96f8d3ad880ea0644442d45dcad109523130d341c326d5424adaa4702f
7
+ data.tar.gz: c8a576b2f37895b66287d50496865a4023dd5dc2c2138bfc05d09ecd46bf85b11e553df8c8fa5750aca15ce083664e08364fdad6ef094481c538dcd3358ec54b
@@ -34,7 +34,13 @@ require 'zendesk2/client/models/audit_event'
34
34
  require_resource("category", plural: "categories")
35
35
  require_resource("forum")
36
36
  require_resource("group", and: ["get_assignable_groups"])
37
- require_resource("user", and: ["search_user", "get_current_user", "mark_user_identity_primary"])
37
+ require_resource("user", and: [
38
+ "search_user",
39
+ "get_current_user",
40
+ "mark_user_identity_primary",
41
+ "get_user_memberships",
42
+ "get_user_organizations",
43
+ ])
38
44
 
39
45
  require_resource("ticket", and: ["get_requested_tickets", "get_ccd_tickets"])
40
46
  require_resource("ticket_audit", except: [:create, :destroy, :update])
@@ -48,15 +54,7 @@ require_resource("organization", and: [
48
54
  "get_organization_by_external_id",
49
55
  "get_organization_memberships",
50
56
  "search_organization",
51
- "get_user_memberships",
52
57
  ])
53
58
  require_resource("user_field")
54
59
  require_resource("user_identity", plural: "user_identities")
55
-
56
- require "zendesk2/client/models/membership"
57
- require "zendesk2/client/collections/memberships"
58
-
59
- require "zendesk2/client/requests/create_membership"
60
- require "zendesk2/client/requests/destroy_membership"
61
- require "zendesk2/client/requests/get_membership"
62
- require "zendesk2/client/requests/mark_membership_default"
60
+ require_resource("membership", except: [:update], and: "mark_membership_default")
@@ -1,9 +1,14 @@
1
1
  class Zendesk2::Client::Organizations < Zendesk2::Client::Collection
2
2
  include Zendesk2::PagedCollection
3
3
  include Zendesk2::Searchable
4
+ extend Zendesk2::Attributes
4
5
 
5
6
  model Zendesk2::Client::Organization
6
7
 
8
+ attribute :user_id, type: :integer
9
+
10
+ assoc_accessor :user
11
+
7
12
  def find_by_external_id(external_id)
8
13
  body = service.get_organization_by_external_id("external_id" => external_id).body
9
14
  if data = body.delete("organizations")
@@ -19,4 +24,18 @@ class Zendesk2::Client::Organizations < Zendesk2::Client::Collection
19
24
  self.model_root = "organization"
20
25
  self.search_type = "organization"
21
26
  self.search_request = :search_organization
27
+
28
+ def collection_page(params={})
29
+ collection_method = if self.user_id
30
+ :get_user_organizations
31
+ else
32
+ :get_organizations
33
+ end
34
+
35
+ body = service.send(collection_method, Cistern::Hash.stringify_keys(self.attributes.merge(params))).body
36
+
37
+ self.load(body[collection_root])
38
+ self.merge_attributes(Cistern::Hash.slice(body, "count", "next_page", "previous_page"))
39
+ self
40
+ end
22
41
  end
@@ -1,11 +1,15 @@
1
1
  class Zendesk2::Client::Tickets < Zendesk2::Client::Collection
2
2
  include Zendesk2::PagedCollection
3
3
  include Zendesk2::Searchable
4
+ extend Zendesk2::Attributes
4
5
 
5
6
  model Zendesk2::Client::Ticket
6
7
 
7
- attribute :requester_id
8
- attribute :collaborator_id
8
+ attribute :requester_id, type: :integer
9
+ attribute :collaborator_id, type: :integer
10
+
11
+ assoc_accessor :requester
12
+ assoc_accessor :collaborator
9
13
 
10
14
  self.collection_root = "tickets"
11
15
  self.model_method = :get_ticket
@@ -23,7 +27,7 @@ class Zendesk2::Client::Tickets < Zendesk2::Client::Collection
23
27
 
24
28
  body = service.send(collection_method, Cistern::Hash.stringify_keys(self.attributes.merge(params))).body
25
29
 
26
- self.load(body[collection_root]) # 'results' is the key for paged seraches
30
+ self.load(body[collection_root]) # 'results' is the key for paged searches
27
31
  self.merge_attributes(Cistern::Hash.slice(body, "count", "next_page", "previous_page"))
28
32
  self
29
33
  end
@@ -183,4 +183,9 @@ class Zendesk2::Client::User < Zendesk2::Client::Model
183
183
  def memberships
184
184
  self.service.memberships(user: self)
185
185
  end
186
+
187
+ # @return [Zendesk2::Client::Organizations] the organizations of this user through memberships
188
+ def organizations
189
+ self.service.organizations(user: self)
190
+ end
186
191
  end
@@ -0,0 +1,10 @@
1
+ class Zendesk2::Client::GetMemberships < Zendesk2::Client::Request
2
+ request_method :get
3
+ request_path { |r| "/organization_memberships.json" }
4
+
5
+ page_params!
6
+
7
+ def mock
8
+ page(self.data[:memberships].values, root: "organization_memberships")
9
+ end
10
+ end
@@ -5,11 +5,14 @@ class Zendesk2::Client::GetOrganizationUsers < Zendesk2::Client::Request
5
5
  page_params!
6
6
 
7
7
  def organization_id
8
- params.fetch("organization").fetch("id")
8
+ params.fetch("organization").fetch("id").to_i
9
9
  end
10
10
 
11
11
  def mock
12
- users = self.data[:users].values.select { |u| u["organization_id"].to_i == organization_id.to_i }
12
+ users = self.data[:users].values.select { |u| u["organization_id"] == organization_id }
13
+ users += self.data[:memberships].values.select { |m|
14
+ m["organization_id"] == organization_id
15
+ }.map { |m| self.data[:users].fetch(m["user_id"]) }
13
16
 
14
17
  page(users, root: "users")
15
18
  end
@@ -0,0 +1,17 @@
1
+ class Zendesk2::Client::GetUserOrganizations < Zendesk2::Client::Request
2
+ request_method :get
3
+ request_path { |r| "/users/#{r.user_id}/organizations.json" }
4
+
5
+ page_params!
6
+
7
+ def user_id
8
+ params.fetch("user_id").to_i
9
+ end
10
+
11
+ def mock
12
+ memberships = self.data[:memberships].values.select { |m| m["user_id"] == user_id }
13
+ organizations = memberships.map { |m| self.data[:organizations].fetch(m["organization_id"]) }
14
+
15
+ page(organizations, root: "organizations")
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Zendesk2
2
- VERSION = "1.5.8"
2
+ VERSION = "1.5.9"
3
3
  end
@@ -55,6 +55,19 @@ describe "memberships" do
55
55
  expect(another_user.memberships.size).to eq(2)
56
56
  end
57
57
 
58
+ it "should get a user's organizations" do
59
+ another_user = client.users.create!(email: mock_email, name: mock_uuid, verified: true)
60
+ another_organization = client.organizations.create!(name: mock_uuid)
61
+
62
+ another_organization.memberships.create!(user: another_user)
63
+ another_organization.memberships.create!(user: user)
64
+ organization.memberships.create!(user: another_user)
65
+
66
+ expect(user.organizations.to_a).to contain_exactly(another_organization)
67
+ expect(another_organization.users.to_a).to contain_exactly(user, another_user)
68
+ expect(organization.users.to_a).to contain_exactly(another_user)
69
+ end
70
+
58
71
  describe "create_membership" do
59
72
  it "should error when organization does not exist" do
60
73
  expect {
data/spec/users_spec.rb CHANGED
@@ -61,15 +61,17 @@ describe "users" do
61
61
  end
62
62
  end
63
63
 
64
- describe "#save" do
64
+ context "with a user" do
65
65
  let!(:user) { client.users.create!(email: mock_email, name: mock_uuid) }
66
66
 
67
- it "should update organization" do
68
- user.organization = organization = client.organizations.create!(name: mock_uuid)
67
+ describe "#save" do
68
+ it "should update organization" do
69
+ user.organization = organization = client.organizations.create!(name: mock_uuid)
69
70
 
70
- user.save!
71
+ user.save!
71
72
 
72
- expect(user.organization).to eq(organization)
73
+ expect(user.organization).to eq(organization)
74
+ end
73
75
  end
74
76
 
75
77
  it "should get requested tickets" do
@@ -126,8 +128,8 @@ describe "users" do
126
128
  expect {
127
129
  initial_identity.destroy
128
130
  }.to change { user.identities.all }.
129
- from(a_collection_containing_exactly(initial_identity, new_identity)).
130
- to(a_collection_containing_exactly(new_identity))
131
+ from(a_collection_containing_exactly(initial_identity, new_identity)).
132
+ to(a_collection_containing_exactly(new_identity))
131
133
 
132
134
  expect(new_identity.reload.primary).to be_falsey
133
135
 
@@ -205,6 +207,5 @@ describe "users" do
205
207
  expect(query["email"]).to be_nil
206
208
  expect(query["jwt"]).not_to be_nil
207
209
  end
208
-
209
210
  end
210
211
  end
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.5.8
4
+ version: 1.5.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Lane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-27 00:00:00.000000000 Z
11
+ date: 2015-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cistern
@@ -179,6 +179,7 @@ files:
179
179
  - lib/zendesk2/client/requests/get_help_center_section.rb
180
180
  - lib/zendesk2/client/requests/get_help_center_sections.rb
181
181
  - lib/zendesk2/client/requests/get_membership.rb
182
+ - lib/zendesk2/client/requests/get_memberships.rb
182
183
  - lib/zendesk2/client/requests/get_organization.rb
183
184
  - lib/zendesk2/client/requests/get_organization_by_external_id.rb
184
185
  - lib/zendesk2/client/requests/get_organization_memberships.rb
@@ -205,6 +206,7 @@ files:
205
206
  - lib/zendesk2/client/requests/get_user_identities.rb
206
207
  - lib/zendesk2/client/requests/get_user_identity.rb
207
208
  - lib/zendesk2/client/requests/get_user_memberships.rb
209
+ - lib/zendesk2/client/requests/get_user_organizations.rb
208
210
  - lib/zendesk2/client/requests/get_users.rb
209
211
  - lib/zendesk2/client/requests/mark_membership_default.rb
210
212
  - lib/zendesk2/client/requests/mark_user_identity_primary.rb