zendesk2 1.5.17 → 1.6.1

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: 52ed002a3f7df6b685aa4ffdcfdbeb6cd340c4be
4
- data.tar.gz: 40af00481679a1a46dc7918799b0e53a5585a96e
3
+ metadata.gz: 0ab381ae9ac2abcdb319cb7485c1046957320739
4
+ data.tar.gz: 33c6c9c16c1b2dcef4de822d621f1b9d326b6c8c
5
5
  SHA512:
6
- metadata.gz: 7eeb1c7b41485340eee8a062677b8aeb79fe67a0420289bc9ac8d9b6a28fc2da6566c57b3b12f5e8bd6a70e4c68827e44dd5459e867cd11f4fcb962a94d05670
7
- data.tar.gz: cffdca2347b876fe1a787879b78d74b7fb3a742d36bc3ad192065b7a8f50fb2964388933bd72c2cc19acb7b6ebe5f9f78e5f3a9d302c9f6f7a1ebaf7655ef523
6
+ metadata.gz: b6aab81be23583b46b17345738dab3d3fcbec5723be5014fb2ec9058ca8a3de7dd58de77f86e09c7a6e1274b2f4e0f536b703b1cf8ee76758ab31f31d91c5aa4
7
+ data.tar.gz: 70d741ec4a91b0803e1f1dba2541d23a1f6e78bfb984314b53153e281a0091f7dd8e3905b731e64b0075e003e610e0d2941d0c6184b3d5f386a0be61bea6ddfb
@@ -61,7 +61,7 @@ class Zendesk2::Client::Collection
61
61
  # @raise [Zendesk2::Error] if the record cannot be found or other request error
62
62
  # @return [Zendesk2::Model] fetched resource corresponding to value of {Zendesk2::Collection#model}
63
63
  def get!(identity_or_hash)
64
- scoped_attributes = self.class.scopes.inject({}){|r,k| r.merge(k.to_s => send(k))}
64
+ scoped_attributes = self.class.scopes.inject({}) { |r,k| r.merge(k.to_s => send(k)) }
65
65
 
66
66
  if identity_or_hash.is_a?(Hash)
67
67
  scoped_attributes.merge!(identity_or_hash)
@@ -85,4 +85,8 @@ class Zendesk2::Client::Collection
85
85
  rescue Zendesk2::Error
86
86
  nil
87
87
  end
88
+
89
+ def new(attributes={})
90
+ super(self.attributes.merge(attributes))
91
+ end
88
92
  end
@@ -11,4 +11,26 @@ class Zendesk2::Client::HelpCenter::Articles < Zendesk2::Client::Collection
11
11
  self.search_type = nil
12
12
  self.search_request = :search_help_center_articles
13
13
 
14
+ attribute :section_id, type: :integer
15
+ attribute :category_id, type: :integer
16
+
17
+ scopes << :section_id
18
+ scopes << :category_id
19
+
20
+ def collection_page(params={})
21
+ collection_method = if category_id
22
+ :get_help_center_categories_articles
23
+ elsif section_id
24
+ :get_help_center_sections_articles
25
+ else
26
+ :get_help_center_articles
27
+ end
28
+
29
+ body = service.send(collection_method, Cistern::Hash.stringify_keys(self.attributes.merge(params))).body
30
+
31
+ self.load(body[collection_root]) # 'results' is the key for paged searches
32
+ self.merge_attributes(Cistern::Hash.slice(body, "count", "next_page", "previous_page"))
33
+ self
34
+ end
35
+
14
36
  end
@@ -8,4 +8,22 @@ class Zendesk2::Client::HelpCenter::Sections < Zendesk2::Client::Collection
8
8
  self.collection_root = "sections"
9
9
  self.model_method = :get_help_center_section
10
10
  self.model_root = "section"
11
+
12
+ attribute :category_id, type: :integer
13
+
14
+ scopes << :category_id
15
+
16
+ def collection_page(params={})
17
+ collection_method = if category_id
18
+ :get_help_center_categories_sections
19
+ else
20
+ :get_help_center_sections
21
+ end
22
+
23
+ body = service.send(collection_method, Cistern::Hash.stringify_keys(self.attributes.merge(params))).body
24
+
25
+ self.load(body[collection_root]) # 'results' is the key for paged searches
26
+ self.merge_attributes(Cistern::Hash.slice(body, "count", "next_page", "previous_page"))
27
+ self
28
+ end
11
29
  end
@@ -27,6 +27,24 @@ class Zendesk2::Client::HelpCenter::Category < Zendesk2::Client::Model
27
27
  # @return [String] The API url of this category
28
28
  attribute :url, type: :string # ro:yes required:no
29
29
 
30
+ def articles
31
+ requires :identity
32
+
33
+ service.help_center_articles(category_id: self.identity)
34
+ end
35
+
36
+ def destroy!
37
+ requires :identity
38
+
39
+ service.destroy_help_center_category("category" => { "id" => self.identity })
40
+ end
41
+
42
+ def sections
43
+ requires :identity
44
+
45
+ service.help_center_sections(category_id: self.identity)
46
+ end
47
+
30
48
  def save!
31
49
  response = if new_record?
32
50
  requires :name, :locale
@@ -40,10 +58,4 @@ class Zendesk2::Client::HelpCenter::Category < Zendesk2::Client::Model
40
58
 
41
59
  merge_attributes(response.body["category"])
42
60
  end
43
-
44
- def destroy!
45
- requires :identity
46
-
47
- service.destroy_help_center_category("category" => { "id" => self.identity })
48
- end
49
61
  end
@@ -34,6 +34,12 @@ class Zendesk2::Client::HelpCenter::Section < Zendesk2::Client::Model
34
34
  # @return [Zendesk2::Client::HelpCenter::Category] category containing this section
35
35
  assoc_accessor :category, collection: :help_center_categories
36
36
 
37
+ def destroy!
38
+ requires :identity
39
+
40
+ service.destroy_help_center_section("section" => { "id" => self.identity })
41
+ end
42
+
37
43
  def save!
38
44
  response = if new_record?
39
45
  requires :name, :locale, :category_id
@@ -48,9 +54,10 @@ class Zendesk2::Client::HelpCenter::Section < Zendesk2::Client::Model
48
54
  merge_attributes(response.body["section"])
49
55
  end
50
56
 
51
- def destroy!
57
+ def articles
52
58
  requires :identity
53
59
 
54
- service.destroy_help_center_section("section" => { "id" => self.identity })
60
+ service.help_center_articles(section_id: self.identity)
55
61
  end
62
+
56
63
  end
@@ -0,0 +1,21 @@
1
+ class Zendesk2::Client::GetHelpCenterCategoriesArticles < Zendesk2::Client::Request
2
+ request_path { |r|
3
+ "/help_center/categories/#{r.category_id}/articles.json"
4
+ }
5
+
6
+ page_params!
7
+
8
+ def category_id
9
+ Integer(
10
+ params.fetch("category_id")
11
+ )
12
+ end
13
+
14
+ def mock
15
+ self.find!(:help_center_categories, category_id)
16
+
17
+ mock_response("articles" => self.data[:help_center_articles].values.select { |s|
18
+ self.data[:help_center_sections].fetch(s["section_id"])["category_id"] == category_id
19
+ })
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ class Zendesk2::Client::GetHelpCenterCategoriesSections < Zendesk2::Client::Request
2
+ request_path { |r|
3
+ "/help_center/categories/#{r.category_id}/sections.json"
4
+ }
5
+
6
+ page_params!
7
+
8
+ def category_id
9
+ Integer(
10
+ params.fetch("category_id")
11
+ )
12
+ end
13
+
14
+ def mock
15
+ self.find!(:help_center_categories, category_id)
16
+
17
+ mock_response("sections" => self.data[:help_center_sections].values.select { |s| s["category_id"] == category_id })
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ class Zendesk2::Client::GetHelpCenterSectionsArticles < Zendesk2::Client::Request
2
+ request_path { |r|
3
+ "/help_center/sections/#{r.section_id}/articles.json"
4
+ }
5
+
6
+ page_params!
7
+
8
+ def section_id
9
+ Integer(
10
+ params.fetch("section_id")
11
+ )
12
+ end
13
+
14
+ def mock
15
+ self.find!(:help_center_sections, section_id)
16
+
17
+ mock_response("articles" => self.data[:help_center_articles].values.select { |s| s["section_id"] == section_id })
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Zendesk2
2
- VERSION = "1.5.17"
2
+ VERSION = "1.6.1"
3
3
  end
@@ -9,4 +9,23 @@ describe "help_center/categories" do
9
9
  :update_params => lambda { { name: mock_uuid } },
10
10
  :search => false,
11
11
  }
12
+
13
+ context "with a category, sections, and articles" do
14
+ let!(:category) { client.help_center_categories.create!(name: mock_uuid, locale: "en-us") }
15
+ let!(:section) { category.sections.create!(name: mock_uuid, locale: "en-us") }
16
+ let!(:articles) { 2.times.map { section.articles.create(title: mock_uuid, locale: "en-us") } }
17
+
18
+ before {
19
+ client.help_center_categories.create!(name: mock_uuid, locale: "en-us").
20
+ sections.create!(name: mock_uuid, locale: "en-us").articles.create!(title: mock_uuid, locale: "en-us")
21
+ }
22
+
23
+ it "lists sections within a category" do
24
+ expect(category.sections.all).to contain_exactly(section)
25
+ end
26
+
27
+ it "lists articles within a category" do
28
+ expect(category.articles.all).to match_array(articles)
29
+ end
30
+ end
12
31
  end
@@ -3,9 +3,10 @@ require 'spec_helper'
3
3
  describe "help_center/sections" do
4
4
  let(:client) { create_client }
5
5
  let!(:category) do
6
- client.help_center_categories.create!(name: mock_uuid,
7
- locale: "en-us",
8
- )
6
+ client.help_center_categories.create!(
7
+ name: mock_uuid,
8
+ locale: "en-us",
9
+ )
9
10
  end
10
11
 
11
12
  include_examples "zendesk resource", {
@@ -14,4 +15,19 @@ describe "help_center/sections" do
14
15
  :update_params => lambda { { name: mock_uuid } },
15
16
  :search => false,
16
17
  }
18
+
19
+ context "with a category, sections, and articles" do
20
+ let!(:category) { client.help_center_categories.create!(name: mock_uuid, locale: "en-us") }
21
+ let!(:section) { category.sections.create!(name: mock_uuid, locale: "en-us") }
22
+ let!(:articles) { 2.times.map { section.articles.create(title: mock_uuid, locale: "en-us") } }
23
+
24
+ before {
25
+ client.help_center_categories.create!(name: mock_uuid, locale: "en-us").
26
+ sections.create!(name: mock_uuid, locale: "en-us").articles.create!(title: mock_uuid, locale: "en-us")
27
+ }
28
+
29
+ it "lists articles within a section" do
30
+ expect(section.articles.all).to match_array(articles)
31
+ end
32
+ end
17
33
  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.17
4
+ version: 1.6.1
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-06-08 00:00:00.000000000 Z
11
+ date: 2015-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cistern
@@ -175,9 +175,12 @@ files:
175
175
  - lib/zendesk2/client/requests/get_help_center_article.rb
176
176
  - lib/zendesk2/client/requests/get_help_center_articles.rb
177
177
  - lib/zendesk2/client/requests/get_help_center_categories.rb
178
+ - lib/zendesk2/client/requests/get_help_center_categories_articles.rb
179
+ - lib/zendesk2/client/requests/get_help_center_categories_sections.rb
178
180
  - lib/zendesk2/client/requests/get_help_center_category.rb
179
181
  - lib/zendesk2/client/requests/get_help_center_section.rb
180
182
  - lib/zendesk2/client/requests/get_help_center_sections.rb
183
+ - lib/zendesk2/client/requests/get_help_center_sections_articles.rb
181
184
  - lib/zendesk2/client/requests/get_membership.rb
182
185
  - lib/zendesk2/client/requests/get_memberships.rb
183
186
  - lib/zendesk2/client/requests/get_organization.rb
@@ -276,7 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
276
279
  version: '0'
277
280
  requirements: []
278
281
  rubyforge_project:
279
- rubygems_version: 2.2.2
282
+ rubygems_version: 2.4.5
280
283
  signing_key:
281
284
  specification_version: 4
282
285
  summary: Zendesk V2 API client
@@ -302,4 +305,3 @@ test_files:
302
305
  - spec/user_fields_spec.rb
303
306
  - spec/user_identities_spec.rb
304
307
  - spec/users_spec.rb
305
- has_rdoc: