zendesk2 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/zendesk2/client/collections/help_center/articles.rb +13 -0
  4. data/lib/zendesk2/client/collections/help_center/categories.rb +10 -0
  5. data/lib/zendesk2/client/collections/help_center/sections.rb +10 -0
  6. data/lib/zendesk2/client/help_center.rb +1 -0
  7. data/lib/zendesk2/client/mock.rb +22 -15
  8. data/lib/zendesk2/client/models/help_center/article.rb +69 -0
  9. data/lib/zendesk2/client/models/help_center/category.rb +53 -0
  10. data/lib/zendesk2/client/models/help_center/section.rb +60 -0
  11. data/lib/zendesk2/client/requests/create_help_center_article.rb +61 -0
  12. data/lib/zendesk2/client/requests/create_help_center_category.rb +47 -0
  13. data/lib/zendesk2/client/requests/create_help_center_section.rb +55 -0
  14. data/lib/zendesk2/client/requests/destroy_help_center_article.rb +22 -0
  15. data/lib/zendesk2/client/requests/destroy_help_center_category.rb +22 -0
  16. data/lib/zendesk2/client/requests/destroy_help_center_section.rb +22 -0
  17. data/lib/zendesk2/client/requests/get_help_center_article.rb +41 -0
  18. data/lib/zendesk2/client/requests/get_help_center_articles.rb +18 -0
  19. data/lib/zendesk2/client/requests/get_help_center_categories.rb +18 -0
  20. data/lib/zendesk2/client/requests/get_help_center_category.rb +41 -0
  21. data/lib/zendesk2/client/requests/get_help_center_section.rb +41 -0
  22. data/lib/zendesk2/client/requests/get_help_center_sections.rb +18 -0
  23. data/lib/zendesk2/client/requests/search_help_center_articles.rb +26 -0
  24. data/lib/zendesk2/client/requests/update_help_center_article.rb +48 -0
  25. data/lib/zendesk2/client/requests/update_help_center_category.rb +48 -0
  26. data/lib/zendesk2/client/requests/update_help_center_section.rb +48 -0
  27. data/lib/zendesk2/client.rb +10 -4
  28. data/lib/zendesk2/model.rb +1 -1
  29. data/lib/zendesk2/searchable.rb +4 -3
  30. data/lib/zendesk2/version.rb +1 -1
  31. data/spec/help_center/articles_spec.rb +22 -0
  32. data/spec/help_center/categories_spec.rb +12 -0
  33. data/spec/help_center/sections_spec.rb +17 -0
  34. data/spec/shared/zendesk_resource.rb +1 -1
  35. data/zendesk2.gemspec +1 -1
  36. metadata +33 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 279574410b23569961ce3ebf883b5b34cbe2010f
4
- data.tar.gz: 586cea4bcc15a218d53fa0e0422e32c04734431f
3
+ metadata.gz: d6b82a5a48123f485de6ede8d43e13a302538888
4
+ data.tar.gz: 6e1df0272327038e7b5b476ee56611e580324a05
5
5
  SHA512:
6
- metadata.gz: 69d5003ad442219c61c602a412c7a983ebbace73c9d43d73b479f8c76f54c51cb74912c40fec279523388a8b35139360e79ed7a50b48806339db0823d846d1b5
7
- data.tar.gz: 75e9f81026df83afdcbe0bf588490e3b5fcea9ec99200b9762e2a9f1763ec09300879a1d9a460a770b43cad877c21b876f39dcc189b437615ff7858a3c56e779
6
+ metadata.gz: 986b90b437821c2b751d66f31c6e74736e0bfe603bb4cb05e40a9f64a170ade9df31f38cf937e99871a7248c7a363c85c3ec010e23295f74d98edb837b7a57bc
7
+ data.tar.gz: 94f4606077f53d047ba69058a34e414727399e91e7ac074890afef445d846efe2e52b9b40e22b80045a637911e3a3fb646d42f50393d402d3015be3dc9570905
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Zendesk2
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/lanej/zendesk2.png)](http://travis-ci.org/lanej/zendesk2)
3
+ [![Build Status](https://travis-ci.org/lanej/zendesk2.svg?branch=master)](http://travis-ci.org/lanej/zendesk2)
4
4
  [![Gem Version](https://fury-badge.herokuapp.com/rb/zendesk2.png)](http://badge.fury.io/rb/zendesk2)
5
5
  [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/lanej/zendesk2)
6
6
  [![Dependency Status](https://gemnasium.com/lanej/zendesk2.png)](https://gemnasium.com/lanej/zendesk2)
@@ -0,0 +1,13 @@
1
+ class Zendesk2::Client::HelpCenter::Articles < Zendesk2::PagedCollection
2
+ include Zendesk2::Searchable
3
+
4
+ model Zendesk2::Client::HelpCenter::Article
5
+
6
+ self.collection_method = :get_help_center_articles
7
+ self.collection_root = "articles"
8
+ self.model_method = :get_help_center_article
9
+ self.model_root = "article"
10
+ self.search_type = nil
11
+ self.search_request = :search_help_center_articles
12
+
13
+ end
@@ -0,0 +1,10 @@
1
+ class Zendesk2::Client::HelpCenter::Categories < Zendesk2::PagedCollection
2
+ include Zendesk2::Searchable
3
+
4
+ model Zendesk2::Client::HelpCenter::Category
5
+
6
+ self.collection_method = :get_help_center_categories
7
+ self.collection_root = "categories"
8
+ self.model_method = :get_help_center_category
9
+ self.model_root = "category"
10
+ end
@@ -0,0 +1,10 @@
1
+ class Zendesk2::Client::HelpCenter::Sections < Zendesk2::PagedCollection
2
+ include Zendesk2::Searchable
3
+
4
+ model Zendesk2::Client::HelpCenter::Section
5
+
6
+ self.collection_method = :get_help_center_sections
7
+ self.collection_root = "sections"
8
+ self.model_method = :get_help_center_section
9
+ self.model_root = "section"
10
+ end
@@ -0,0 +1 @@
1
+ module Zendesk2::Client::HelpCenter; end
@@ -6,21 +6,24 @@ class Zendesk2::Client < Cistern::Service
6
6
 
7
7
  def self.data
8
8
  @data ||= {
9
- :categories => {},
10
- :forums => {},
11
- :groups => {},
12
- :identities => {},
13
- :memberships => {},
14
- :organizations => {},
15
- :ticket_audits => {},
16
- :ticket_comments => {},
17
- :ticket_fields => {},
18
- :ticket_metrics => {},
19
- :tickets => {},
20
- :topic_comments => {},
21
- :topics => {},
22
- :user_fields => {},
23
- :users => {},
9
+ :categories => {},
10
+ :forums => {},
11
+ :groups => {},
12
+ :help_center_articles => {},
13
+ :help_center_categories => {},
14
+ :help_center_sections => {},
15
+ :identities => {},
16
+ :memberships => {},
17
+ :organizations => {},
18
+ :ticket_audits => {},
19
+ :ticket_comments => {},
20
+ :ticket_fields => {},
21
+ :ticket_metrics => {},
22
+ :tickets => {},
23
+ :topic_comments => {},
24
+ :topics => {},
25
+ :user_fields => {},
26
+ :users => {},
24
27
  }
25
28
  end
26
29
 
@@ -57,6 +60,10 @@ class Zendesk2::Client < Cistern::Service
57
60
  @current_user
58
61
  end
59
62
 
63
+ def html_url_for(path)
64
+ File.join(@url, path.to_s)
65
+ end
66
+
60
67
  def url_for(path)
61
68
  File.join(@url, "/api/v2", path.to_s)
62
69
  end
@@ -0,0 +1,69 @@
1
+ class Zendesk2::Client::HelpCenter::Article < Zendesk2::Model
2
+ extend Zendesk2::Attributes
3
+
4
+ # @return [Integer] Automatically assigned when the article is created
5
+ identity :id, type: :integer # ro:yes required:no
6
+
7
+ # @return [Integer] The id of the user who wrote the article (set to the user who made the request on create by default)
8
+ attribute :author_id, type: :integer # ro:no required:no
9
+ # @return [String] The body of the article
10
+ attribute :body, type: :string # ro:no required:no
11
+ # @return [Boolean] True if comments are disabled; false otherwise
12
+ attribute :comments_disabled, type: :boolean # ro:no required:no
13
+ # @return [Time] The time at which the article was created
14
+ attribute :created_at, type: :time # ro:yes required:no
15
+ # @return [Boolean] True if the translation for the current locale is a draft; false otherwise. false by default
16
+ attribute :draft, type: :boolean # ro:no required:no
17
+ # @return [String] The url of the article in Help Center
18
+ attribute :html_url, type: :string # ro:yes required:no
19
+ # @return [String] An array of label names associated with this article. By default no label names are used (only available on certain plans)
20
+ attribute :label_names, type: :string # ro:no required:no
21
+ # @return [String] The locale that the article is being displayed in
22
+ attribute :locale, type: :string # ro:no required:yes
23
+ # @return [Boolean] Whether the article is out of date
24
+ attribute :outdated, type: :boolean # ro:yes required:no
25
+ # @return [Integer] The position of this article in the article list. '0' by default
26
+ attribute :position, type: :integer # ro:no required:no
27
+ # @return [Boolean] True if this article is promoted; false otherwise. false by default
28
+ attribute :promoted, type: :boolean # ro:no required:no
29
+ # @return [Integer] The id of the section to which this article belongs
30
+ attribute :section_id, type: :integer # ro:no required:no
31
+ # @return [String] The source (default) locale of the article
32
+ attribute :source_locale, type: :string # ro:yes required:no
33
+ # @return [String] The title of the article
34
+ attribute :title, type: :string # ro:no required:yes
35
+ # @return [Time] The time at which the article was last updated
36
+ attribute :updated_at, type: :time # ro:yes required:no
37
+ # @return [String] The API url of the article
38
+ attribute :url, type: :string # ro:yes required:no
39
+ # @return [Integer] The number of votes cast on this article
40
+ attribute :vote_count, type: :integer # ro:yes required:no
41
+ # @return [Integer] The total sum of votes on this article
42
+ attribute :vote_sum, type: :integer # ro:yes required:no
43
+
44
+ assoc_accessor :section, collection: :help_center_sections
45
+
46
+ def save!
47
+ requires :title, :locale, :section_id
48
+
49
+ data = if new_record?
50
+ connection.create_help_center_article(params).body["article"]
51
+ else
52
+ connection.update_help_center_article(dirty_attributes.merge("id" => self.identity)).body["article"]
53
+ end
54
+
55
+ merge_attributes(data)
56
+ end
57
+
58
+ def destroy!
59
+ requires :id
60
+
61
+ connection.destroy_help_center_article(id)
62
+ end
63
+
64
+ private
65
+
66
+ def params
67
+ Cistern::Hash.slice(self.attributes, :author_id, :body, :comments_disabled, :draft, :label_names, :locale, :position, :promoted, :section_id, :title)
68
+ end
69
+ end
@@ -0,0 +1,53 @@
1
+ class Zendesk2::Client::HelpCenter::Category < Zendesk2::Model
2
+ extend Zendesk2::Attributes
3
+
4
+ # @return [Integer] Automatically assigned when creating categories
5
+ identity :id, type: :integer # ro:yes required:no
6
+
7
+ # @return [Time] The time at which the category was created
8
+ attribute :created_at, type: :time # ro:yes required:no
9
+ # @return [String] The description of the category
10
+ attribute :description, type: :string # ro:no required:no
11
+ # @return [String] The url of this category in Help Center
12
+ attribute :html_url, type: :string # ro:yes required:no
13
+ # @return [String] The locale that the category is displayed in
14
+ attribute :locale, type: :string # ro:no required:yes
15
+ # @return [String] The name of the category
16
+ attribute :name, type: :string # ro:no required:yes
17
+ # @return [Boolean] Whether the category is out of date
18
+ attribute :outdated, type: :boolean # ro:yes required:no
19
+ # @return [Integer] The position of this category relative to other categories
20
+ attribute :position, type: :integer # ro:no required:no
21
+ # @return [String] The source (default) locale of the category
22
+ attribute :source_locale, type: :string # ro:yes required:no
23
+ # @return [Array] The ids of all translations of this category
24
+ attribute :translation_ids, type: :array # ro:yes required:no
25
+ # @return [Time] The time at which the category was last updated
26
+ attribute :updated_at, type: :time # ro:yes required:no
27
+ # @return [String] The API url of this category
28
+ attribute :url, type: :string # ro:yes required:no
29
+
30
+ def save!
31
+ requires :name, :locale
32
+
33
+ data = if new_record?
34
+ connection.create_help_center_category(params).body["category"]
35
+ else
36
+ connection.update_help_center_category(dirty_attributes.merge("id" => self.identity)).body["category"]
37
+ end
38
+
39
+ merge_attributes(data)
40
+ end
41
+
42
+ def destroy!
43
+ requires :id
44
+
45
+ connection.destroy_help_center_category(id)
46
+ end
47
+
48
+ private
49
+
50
+ def params
51
+ Cistern::Hash.slice(self.attributes, :category_id, :description, :locale, :name, :position, :sorting)
52
+ end
53
+ end
@@ -0,0 +1,60 @@
1
+ class Zendesk2::Client::HelpCenter::Section < Zendesk2::Model
2
+ extend Zendesk2::Attributes
3
+
4
+ # @return [Integer] Automatically assigned when creating subscriptions
5
+ identity :id, type: :integer
6
+
7
+ # @return [Integer] The id of the category to which this section belongs
8
+ attribute :category_id, type: :integer # ro:no required:no
9
+ # @return [Time] The time at which the section was created
10
+ attribute :created_at, type: :datetime # ro:yes required:no
11
+ # @return [String] The description of the section
12
+ attribute :description, type: :string # ro:no required:no
13
+ # @return [String] The url of this section in HC
14
+ attribute :html_url, type: :string # ro:yes required:no
15
+ # @return [String] The locale in which the section is displayed
16
+ attribute :locale, type: :string # ro:no required:yes
17
+ # @return [String] The name of the section
18
+ attribute :name, type: :string # ro:no required:yes
19
+ # @return [Boolean] Whether the section is out of date
20
+ attribute :outdated, type: :boolean # ro:yes required:no
21
+ # @return [Integer] The position of this section in the section list. By default the section is added to the end of the list
22
+ attribute :position, type: :integer # ro:no required:no
23
+ # @return [String] The sorting of articles within this section. By default it's set to manual. See sorting below.
24
+ attribute :sorting, type: :string # ro:no required:no
25
+ # @return [String] The source (default) locale of the section
26
+ attribute :source_locale, type: :string # ro:yes required:no
27
+ # @return [Array] The ids of all translations of this section
28
+ attribute :translation_ids, type: :array # ro:yes required:no
29
+ # @return [Time] The time at which the section was last updated
30
+ attribute :updated_at, type: :datetime # ro:yes required:no
31
+ # @return [string] The API url of this section
32
+ attribute :url, type: :string # ro:yes required:no
33
+
34
+ # @return [Zendesk2::Client::HelpCenter::Category] category containing this section
35
+ assoc_accessor :category, collection: :help_center_categories
36
+
37
+ def save!
38
+ requires :name, :locale, :category_id
39
+
40
+ data = if new_record?
41
+ connection.create_help_center_section(params).body["section"]
42
+ else
43
+ connection.update_help_center_section(dirty_attributes.merge("id" => self.identity)).body["section"]
44
+ end
45
+
46
+ merge_attributes(data)
47
+ end
48
+
49
+ def destroy!
50
+ requires :id
51
+
52
+ connection.destroy_help_center_section(id)
53
+ end
54
+
55
+ private
56
+
57
+ def params
58
+ Cistern::Hash.slice(self.attributes, :category_id, :description, :locale, :name, :position, :sorting)
59
+ end
60
+ end
@@ -0,0 +1,61 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def create_help_center_article(params={})
4
+ section_id = require_parameters(params, "section_id")
5
+ path = if locale = params["locale"]
6
+ "/help_center/#{locale}/sections/#{section_id}/articles.json"
7
+ else
8
+ "/help_center/sections/#{section_id}/articles.json"
9
+ end
10
+
11
+
12
+ request(
13
+ :body => {"article" => params},
14
+ :method => :post,
15
+ :path => path,
16
+ )
17
+ end
18
+ end # Real
19
+
20
+ class Mock
21
+ def create_help_center_article(params={})
22
+ params = Cistern::Hash.stringify_keys(params)
23
+
24
+ identity = self.class.new_id
25
+
26
+ section_id = *require_parameters(params, "section_id")
27
+
28
+ locale = params["locale"] ||= "en-us"
29
+ position = self.data[:help_center_articles].values.select { |a| a["section_id"] == section_id }.size
30
+
31
+ record = {
32
+ "id" => identity,
33
+ "url" => url_for("/help_center/#{locale}/articles/#{identity}.json"),
34
+ "html_url" => html_url_for("/hc/#{locale}/articles/#{identity}.json"),
35
+ "author_id" => current_user["id"],
36
+ "comments_disabled" => false,
37
+ "label_names" => [],
38
+ "draft" => false,
39
+ "promoted" => false,
40
+ "position" => position,
41
+ "vote_sum" => 0,
42
+ "vote_count" => 0,
43
+ "section_id" => section_id,
44
+ "created_at" => Time.now.iso8601,
45
+ "updated_at" => Time.now.iso8601,
46
+ "title" => "",
47
+ "body" => "",
48
+ "source_locale" => locale,
49
+ "outdated" => false,
50
+ }.merge(params)
51
+
52
+ self.data[:help_center_articles][identity] = record
53
+
54
+ response(
55
+ :method => :post,
56
+ :body => {"article" => record},
57
+ :path => "/sections/#{section_id}.json"
58
+ )
59
+ end
60
+ end # Mock
61
+ end # Zendesk2::Client
@@ -0,0 +1,47 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def create_help_center_category(params={})
4
+ params = Cistern::Hash.stringify_keys(params)
5
+
6
+ require_parameters(params, "name")
7
+
8
+ request(
9
+ :body => {"category" => params},
10
+ :method => :post,
11
+ :path => "/help_center/categories.json",
12
+ )
13
+ end
14
+ end # Real
15
+
16
+ class Mock
17
+ def create_help_center_category(params={})
18
+ params = Cistern::Hash.stringify_keys(params)
19
+
20
+ require_parameters(params, "name")
21
+
22
+ identity = self.class.new_id
23
+
24
+ locale = params["locale"] ||= "en-us"
25
+ position = self.data[:help_center_categories].size
26
+
27
+ record = {
28
+ "id" => identity,
29
+ "url" => url_for("/help_center/#{locale}/categories/#{identity}.json"),
30
+ "html_url" => html_url_for("/hc/#{locale}/categories/#{identity}.json"),
31
+ "author_id" => current_user["id"],
32
+ "position" => position,
33
+ "created_at" => Time.now.iso8601,
34
+ "updated_at" => Time.now.iso8601,
35
+ "description" => "",
36
+ }.merge(params)
37
+
38
+ self.data[:help_center_categories][identity] = record
39
+
40
+ response(
41
+ :method => :post,
42
+ :body => {"category" => record},
43
+ :path => "/categories.json"
44
+ )
45
+ end
46
+ end # Mock
47
+ end # Zendesk2::Client
@@ -0,0 +1,55 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def create_help_center_section(params={})
4
+ category_id = require_parameters(params, "category_id")
5
+
6
+ request(
7
+ :body => {"section" => params},
8
+ :method => :post,
9
+ :path => "/help_center/categories/#{category_id}/sections.json",
10
+ )
11
+ end
12
+ end # Real
13
+
14
+ class Mock
15
+ def create_help_center_section(params={})
16
+ params = Cistern::Hash.stringify_keys(params)
17
+
18
+ identity = self.class.new_id
19
+
20
+ category_id = require_parameters(params, "category_id")
21
+
22
+ locale = params["locale"] ||= "en-us"
23
+ position = self.data[:help_center_sections].values.select { |a| a["category_id"] == category_id }.size
24
+
25
+ record = {
26
+ "id" => identity,
27
+ "url" => url_for("/help_center/#{locale}/sections/#{identity}.json"),
28
+ "html_url" => html_url_for("/hc/#{locale}/sections/#{identity}.json"),
29
+ "author_id" => current_user["id"],
30
+ "comments_disabled" => false,
31
+ "label_names" => [],
32
+ "draft" => false,
33
+ "promoted" => false,
34
+ "position" => position,
35
+ "vote_sum" => 0,
36
+ "vote_count" => 0,
37
+ "category_id" => category_id,
38
+ "created_at" => Time.now.iso8601,
39
+ "updated_at" => Time.now.iso8601,
40
+ "name" => "",
41
+ "body" => "",
42
+ "source_locale" => locale,
43
+ "outdated" => false,
44
+ }.merge(params)
45
+
46
+ self.data[:help_center_sections][identity] = record
47
+
48
+ response(
49
+ :method => :post,
50
+ :body => {"section" => record},
51
+ :path => "/sections/#{category_id}.json"
52
+ )
53
+ end
54
+ end # Mock
55
+ end # Zendesk2::Client
@@ -0,0 +1,22 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def destroy_help_center_article(id)
4
+ request(
5
+ :method => :delete,
6
+ :path => "/help_center/articles/#{id}.json"
7
+ )
8
+ end
9
+ end
10
+
11
+ class Mock
12
+ def destroy_help_center_article(id)
13
+ response(
14
+ :method => :delete,
15
+ :path => "/help_center/articles/#{id}.json",
16
+ :body => {
17
+ "article" => self.find!(:help_center_articles, id),
18
+ },
19
+ )
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def destroy_help_center_category(id)
4
+ request(
5
+ :method => :delete,
6
+ :path => "/help_center/categories/#{id}.json"
7
+ )
8
+ end
9
+ end
10
+
11
+ class Mock
12
+ def destroy_help_center_category(id)
13
+ response(
14
+ :method => :delete,
15
+ :path => "/help_center/categories/#{id}.json",
16
+ :body => {
17
+ "category" => self.find!(:help_center_categories, id),
18
+ },
19
+ )
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def destroy_help_center_section(id)
4
+ request(
5
+ :method => :delete,
6
+ :path => "/help_center/sections/#{id}.json"
7
+ )
8
+ end
9
+ end
10
+
11
+ class Mock
12
+ def destroy_help_center_section(id)
13
+ response(
14
+ :method => :delete,
15
+ :path => "/help_center/sections/#{id}.json",
16
+ :body => {
17
+ "section" => self.find!(:help_center_sections, id),
18
+ },
19
+ )
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,41 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def get_help_center_article(params={})
4
+ id = require_parameters(params, "id")
5
+ locale = params["locale"]
6
+
7
+ path = if locale
8
+ "/help_center/#{locale}/articles/#{id}.json"
9
+ else
10
+ "/help_center/articles/#{id}.json"
11
+ end
12
+
13
+
14
+ request(
15
+ :method => :get,
16
+ :path => path,
17
+ )
18
+ end
19
+ end # Real
20
+
21
+ class Mock
22
+ def get_help_center_article(params={})
23
+ id = require_parameters(params, "id")
24
+
25
+ locale = params["locale"]
26
+
27
+ path = if locale
28
+ "/help_center/#{locale}/articles/#{id}.json"
29
+ else
30
+ "/help_center/articles/#{id}.json"
31
+ end
32
+
33
+ response(
34
+ :path => path,
35
+ :body => {
36
+ "article" => self.find!(:help_center_articles, id.to_i)
37
+ },
38
+ )
39
+ end
40
+ end # Mock
41
+ end
@@ -0,0 +1,18 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def get_help_center_articles(params={})
4
+ page_params = Zendesk2.paging_parameters(params)
5
+
6
+ request(
7
+ :params => page_params,
8
+ :method => :get,
9
+ :path => "/help_center/articles.json",
10
+ )
11
+ end
12
+ end
13
+ class Mock
14
+ def get_help_center_articles(params={})
15
+ page(params, :help_center_articles, "/help_center_articles.json", "articles")
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def get_help_center_categories(params={})
4
+ page_params = Zendesk2.paging_parameters(params)
5
+
6
+ request(
7
+ :params => page_params,
8
+ :method => :get,
9
+ :path => "/help_center/categories.json",
10
+ )
11
+ end
12
+ end
13
+ class Mock
14
+ def get_help_center_categories(params={})
15
+ page(params, :help_center_categories, "/help_center_categories.json", "categories")
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,41 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def get_help_center_category(params={})
4
+ id = require_parameters(params, "id")
5
+ locale = params["locale"]
6
+
7
+ path = if locale
8
+ "/help_center/#{locale}/categories/#{id}.json"
9
+ else
10
+ "/help_center/categories/#{id}.json"
11
+ end
12
+
13
+
14
+ request(
15
+ :method => :get,
16
+ :path => path,
17
+ )
18
+ end
19
+ end # Real
20
+
21
+ class Mock
22
+ def get_help_center_category(params={})
23
+ id = require_parameters(params, "id")
24
+
25
+ locale = params["locale"]
26
+
27
+ path = if locale
28
+ "/help_center/#{locale}/categories/#{id}.json"
29
+ else
30
+ "/help_center/categories/#{id}.json"
31
+ end
32
+
33
+ response(
34
+ :path => path,
35
+ :body => {
36
+ "category" => self.find!(:help_center_categories, id.to_i)
37
+ },
38
+ )
39
+ end
40
+ end # Mock
41
+ end
@@ -0,0 +1,41 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def get_help_center_section(params={})
4
+ id = require_parameters(params, "id")
5
+ locale = params["locale"]
6
+
7
+ path = if locale
8
+ "/help_center/#{locale}/sections/#{id}.json"
9
+ else
10
+ "/help_center/sections/#{id}.json"
11
+ end
12
+
13
+
14
+ request(
15
+ :method => :get,
16
+ :path => path,
17
+ )
18
+ end
19
+ end # Real
20
+
21
+ class Mock
22
+ def get_help_center_section(params={})
23
+ id = require_parameters(params, "id")
24
+
25
+ locale = params["locale"]
26
+
27
+ path = if locale
28
+ "/help_center/#{locale}/sections/#{id}.json"
29
+ else
30
+ "/help_center/sections/#{id}.json"
31
+ end
32
+
33
+ response(
34
+ :path => path,
35
+ :body => {
36
+ "section" => self.find!(:help_center_sections, id.to_i)
37
+ },
38
+ )
39
+ end
40
+ end # Mock
41
+ end
@@ -0,0 +1,18 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def get_help_center_sections(params={})
4
+ page_params = Zendesk2.paging_parameters(params)
5
+
6
+ request(
7
+ :params => page_params,
8
+ :method => :get,
9
+ :path => "/help_center/sections.json",
10
+ )
11
+ end
12
+ end
13
+ class Mock
14
+ def get_help_center_sections(params={})
15
+ page(params, :help_center_sections, "/help_center_sections.json", "sections")
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def search_help_center_articles(query)
4
+ request(
5
+ :method => :get,
6
+ :params => {query: query},
7
+ :path => "/help_center/articles/search.json",
8
+ )
9
+ end
10
+ end # Real
11
+
12
+ class Mock
13
+ def search_help_center_articles(query)
14
+ terms = Hash[query.split(" ").map { |t| t.split(":") }]
15
+
16
+ collection = self.data[:help_center_articles].values
17
+
18
+ results = collection.select { |v| terms.all?{ |term, condition| v[term.to_s].to_s == condition.to_s } }
19
+
20
+ response(
21
+ :path => "/search.json",
22
+ :body => {"results" => results},
23
+ )
24
+ end
25
+ end # Mock
26
+ end
@@ -0,0 +1,48 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def update_help_center_article(params={})
4
+ id = require_parameters(params, "id")
5
+ locale = params["locale"]
6
+
7
+ path = if locale
8
+ "/help_center/#{locale}/articles/#{id}.json"
9
+ else
10
+ "/help_center/articles/#{id}.json"
11
+ end
12
+
13
+ request(
14
+ :method => :put,
15
+ :path => path,
16
+ :body => {
17
+ "article" => params
18
+ },
19
+ )
20
+ end
21
+ end
22
+ class Mock
23
+ def update_help_center_article(params={})
24
+ params = Cistern::Hash.stringify_keys(params)
25
+
26
+ require_parameters(params, "id")
27
+
28
+ id = params.delete("id")
29
+ locale = params["locale"]
30
+
31
+ path = if locale
32
+ "/help_center/#{locale}/articles/#{id}.json"
33
+ else
34
+ "/help_center/articles/#{id}.json"
35
+ end
36
+
37
+ body = self.data[:help_center_articles][id.to_i].merge!(params)
38
+
39
+ response(
40
+ :method => :put,
41
+ :path => path,
42
+ :body => {
43
+ "article" => body,
44
+ },
45
+ )
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,48 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def update_help_center_category(params={})
4
+ id = require_parameters(params, "id")
5
+ locale = params["locale"]
6
+
7
+ path = if locale
8
+ "/help_center/#{locale}/categories/#{id}.json"
9
+ else
10
+ "/help_center/categories/#{id}.json"
11
+ end
12
+
13
+ request(
14
+ :method => :put,
15
+ :path => path,
16
+ :body => {
17
+ "category" => params
18
+ },
19
+ )
20
+ end
21
+ end
22
+ class Mock
23
+ def update_help_center_category(params={})
24
+ params = Cistern::Hash.stringify_keys(params)
25
+
26
+ require_parameters(params, "id")
27
+
28
+ id = params.delete("id")
29
+ locale = params["locale"]
30
+
31
+ path = if locale
32
+ "/help_center/#{locale}/categories/#{id}.json"
33
+ else
34
+ "/help_center/categories/#{id}.json"
35
+ end
36
+
37
+ body = self.data[:help_center_categories][id.to_i].merge!(params)
38
+
39
+ response(
40
+ :method => :put,
41
+ :path => path,
42
+ :body => {
43
+ "category" => body,
44
+ },
45
+ )
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,48 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def update_help_center_section(params={})
4
+ id = require_parameters(params, "id")
5
+ locale = params["locale"]
6
+
7
+ path = if locale
8
+ "/help_center/#{locale}/sections/#{id}.json"
9
+ else
10
+ "/help_center/sections/#{id}.json"
11
+ end
12
+
13
+ request(
14
+ :method => :put,
15
+ :path => path,
16
+ :body => {
17
+ "section" => params
18
+ },
19
+ )
20
+ end
21
+ end
22
+ class Mock
23
+ def update_help_center_section(params={})
24
+ params = Cistern::Hash.stringify_keys(params)
25
+
26
+ require_parameters(params, "id")
27
+
28
+ id = params.delete("id")
29
+ locale = params["locale"]
30
+
31
+ path = if locale
32
+ "/help_center/#{locale}/sections/#{id}.json"
33
+ else
34
+ "/help_center/sections/#{id}.json"
35
+ end
36
+
37
+ body = self.data[:help_center_sections][id.to_i].merge!(params)
38
+
39
+ response(
40
+ :method => :put,
41
+ :path => path,
42
+ :body => {
43
+ "section" => body,
44
+ },
45
+ )
46
+ end
47
+ end
48
+ end
@@ -5,23 +5,28 @@ class Zendesk2::Client < Cistern::Service
5
5
  model_path "zendesk2/client/models"
6
6
  request_path "zendesk2/client/requests"
7
7
 
8
- # might be nice if cistern took care of this
8
+ # @fixme might be nice if cistern took care of this
9
9
  [
10
10
  [:collection, collection_path],
11
11
  [:model, model_path],
12
12
  [:request, request_path],
13
13
  ].each do |type, path|
14
- Dir[File.expand_path(File.join("../..", path, "*.rb"), __FILE__)].sort.each do |file|
15
- send(type, File.basename(file, ".rb"))
14
+ Dir[File.expand_path(File.join("../..", path, "**/*.rb"), __FILE__)].sort.each do |file|
15
+ send(type, file.gsub(/.*#{path}\/(.*)\.rb/, "\\1"), require: file)
16
16
  end
17
17
  end
18
18
 
19
19
  recognizes :url, :logger, :adapter, :username, :password, :token, :jwt_token
20
20
 
21
21
  module Shared
22
- def require_parameters(params, *requirements)
22
+ def require_parameters(_params, *requirements)
23
+ params = Cistern::Hash.stringify_keys(_params)
24
+
23
25
  if (missing = requirements - params.keys).any?
24
26
  raise ArgumentError, "missing parameters: #{missing.join(", ")}"
27
+ else
28
+ values = params.values_at(*requirements)
29
+ requirements.size == 1 ? values.first : values
25
30
  end
26
31
  end
27
32
  end
@@ -29,3 +34,4 @@ end
29
34
 
30
35
  require 'zendesk2/client/real'
31
36
  require 'zendesk2/client/mock'
37
+ require 'zendesk2/client/help_center'
@@ -5,7 +5,7 @@ class Zendesk2::Model < Cistern::Model
5
5
  # @abstract override in subclass
6
6
  # @raise [Zendesk2::Error] if unsuccessful
7
7
  def save!
8
- raise NotImplementError
8
+ raise NotImplementedError
9
9
  end
10
10
 
11
11
  # calls {#save!} and sets {#errors} if unsuccessful and applicable
@@ -16,11 +16,12 @@ module Zendesk2::Searchable
16
16
  # @see http://developer.zendesk.com/documentation/rest_api/search.html
17
17
  def search(terms)
18
18
  query = if terms.is_a?(Hash)
19
- terms.merge("type" => self.class.search_type).
20
- merge(self.class.scopes.inject({}){|r,k| r.merge(k.to_s => public_send(k))}).
19
+ terms.merge!("type" => self.class.search_type) if self.class.search_type
20
+ terms.merge(self.class.scopes.inject({}){|r,k| r.merge(k.to_s => public_send(k))}).
21
21
  map { |k,v| "#{k}:#{v}" }.join(" ")
22
22
  else
23
- additional_terms = ["type:#{self.class.search_type}"]
23
+ additional_terms = []
24
+ additional_terms = ["type:#{self.class.search_type}"] if self.class.search_type
24
25
  additional_terms += self.class.scopes.inject([]) { |r,k| ["#{k}:#{public_send(k)}"] }
25
26
 
26
27
  additional_terms.inject(terms.to_s) do |qualified_search, qualification|
@@ -1,3 +1,3 @@
1
1
  module Zendesk2
2
- VERSION = "1.1.3"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe "help_center/articles" do
4
+ let(:client) { create_client }
5
+ let!(:section) do
6
+ category = client.help_center_categories.create!(name: Zendesk2.uuid,
7
+ locale: "en-us",
8
+ )
9
+ client.help_center_sections.create!(:name => Zendesk2.uuid,
10
+ :locale => "en-us",
11
+ :category => category,
12
+ )
13
+ end
14
+
15
+ include_examples "zendesk resource", {
16
+ :collection => lambda { client.help_center_articles },
17
+ :create_params => lambda { { title: Zendesk2.uuid, locale: "en-us", section: section } },
18
+ :update_params => lambda { { title: Zendesk2.uuid } },
19
+ :search_params => lambda { Cistern::Hash.slice(create_params, :title) },
20
+ :search => true,
21
+ }
22
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe "help_center/categories" do
4
+ let(:client) { create_client }
5
+
6
+ include_examples "zendesk resource", {
7
+ :collection => lambda { client.help_center_categories },
8
+ :create_params => lambda { { name: Zendesk2.uuid, locale: "en-us" } },
9
+ :update_params => lambda { { name: Zendesk2.uuid } },
10
+ :search => false,
11
+ }
12
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe "help_center/sections" do
4
+ let(:client) { create_client }
5
+ let!(:category) do
6
+ client.help_center_categories.create!(name: Zendesk2.uuid,
7
+ locale: "en-us",
8
+ )
9
+ end
10
+
11
+ include_examples "zendesk resource", {
12
+ :collection => lambda { client.help_center_sections },
13
+ :create_params => lambda { { name: Zendesk2.uuid, locale: "en-us", category: category } },
14
+ :update_params => lambda { { name: Zendesk2.uuid } },
15
+ :search => false,
16
+ }
17
+ end
@@ -56,7 +56,7 @@ shared_examples "zendesk resource" do |options={}|
56
56
  if options.fetch(:update, true)
57
57
  it "should be updated" do
58
58
  @record = collection.create!(create_params)
59
- record.merge_attributes(update_params)
59
+ update_params.each { |k,v| record.send("#{k}=", v) }
60
60
  record.save
61
61
  update_params.each {|k,v| expect(record.send(k)).to eq(v)}
62
62
  end
data/zendesk2.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.version = Zendesk2::VERSION
18
18
 
19
19
  gem.add_dependency "addressable", "~> 2.2"
20
- gem.add_dependency "cistern", "~> 0.9", ">= 0.9.2"
20
+ gem.add_dependency "cistern", "~> 0.11"
21
21
  gem.add_dependency "faraday", "~> 0.9"
22
22
  gem.add_dependency "faraday_middleware", "~> 0.9"
23
23
  gem.add_dependency "jwt", "~> 1.0"
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.1.3
4
+ version: 1.2.0
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-02 00:00:00.000000000 Z
11
+ date: 2014-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -30,20 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.9'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 0.9.2
33
+ version: '0.11'
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
38
  - - "~>"
42
39
  - !ruby/object:Gem::Version
43
- version: '0.9'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 0.9.2
40
+ version: '0.11'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: faraday
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -107,6 +101,9 @@ files:
107
101
  - lib/zendesk2/client/collections/categories.rb
108
102
  - lib/zendesk2/client/collections/forums.rb
109
103
  - lib/zendesk2/client/collections/groups.rb
104
+ - lib/zendesk2/client/collections/help_center/articles.rb
105
+ - lib/zendesk2/client/collections/help_center/categories.rb
106
+ - lib/zendesk2/client/collections/help_center/sections.rb
110
107
  - lib/zendesk2/client/collections/memberships.rb
111
108
  - lib/zendesk2/client/collections/organizations.rb
112
109
  - lib/zendesk2/client/collections/ticket_audits.rb
@@ -119,11 +116,15 @@ files:
119
116
  - lib/zendesk2/client/collections/user_fields.rb
120
117
  - lib/zendesk2/client/collections/user_identities.rb
121
118
  - lib/zendesk2/client/collections/users.rb
119
+ - lib/zendesk2/client/help_center.rb
122
120
  - lib/zendesk2/client/mock.rb
123
121
  - lib/zendesk2/client/models/audit_event.rb
124
122
  - lib/zendesk2/client/models/category.rb
125
123
  - lib/zendesk2/client/models/forum.rb
126
124
  - lib/zendesk2/client/models/group.rb
125
+ - lib/zendesk2/client/models/help_center/article.rb
126
+ - lib/zendesk2/client/models/help_center/category.rb
127
+ - lib/zendesk2/client/models/help_center/section.rb
127
128
  - lib/zendesk2/client/models/membership.rb
128
129
  - lib/zendesk2/client/models/organization.rb
129
130
  - lib/zendesk2/client/models/ticket.rb
@@ -145,6 +146,9 @@ files:
145
146
  - lib/zendesk2/client/requests/create_category.rb
146
147
  - lib/zendesk2/client/requests/create_forum.rb
147
148
  - lib/zendesk2/client/requests/create_group.rb
149
+ - lib/zendesk2/client/requests/create_help_center_article.rb
150
+ - lib/zendesk2/client/requests/create_help_center_category.rb
151
+ - lib/zendesk2/client/requests/create_help_center_section.rb
148
152
  - lib/zendesk2/client/requests/create_membership.rb
149
153
  - lib/zendesk2/client/requests/create_organization.rb
150
154
  - lib/zendesk2/client/requests/create_ticket.rb
@@ -157,6 +161,9 @@ files:
157
161
  - lib/zendesk2/client/requests/destroy_category.rb
158
162
  - lib/zendesk2/client/requests/destroy_forum.rb
159
163
  - lib/zendesk2/client/requests/destroy_group.rb
164
+ - lib/zendesk2/client/requests/destroy_help_center_article.rb
165
+ - lib/zendesk2/client/requests/destroy_help_center_category.rb
166
+ - lib/zendesk2/client/requests/destroy_help_center_section.rb
160
167
  - lib/zendesk2/client/requests/destroy_membership.rb
161
168
  - lib/zendesk2/client/requests/destroy_organization.rb
162
169
  - lib/zendesk2/client/requests/destroy_ticket.rb
@@ -176,6 +183,12 @@ files:
176
183
  - lib/zendesk2/client/requests/get_forums.rb
177
184
  - lib/zendesk2/client/requests/get_group.rb
178
185
  - lib/zendesk2/client/requests/get_groups.rb
186
+ - lib/zendesk2/client/requests/get_help_center_article.rb
187
+ - lib/zendesk2/client/requests/get_help_center_articles.rb
188
+ - lib/zendesk2/client/requests/get_help_center_categories.rb
189
+ - lib/zendesk2/client/requests/get_help_center_category.rb
190
+ - lib/zendesk2/client/requests/get_help_center_section.rb
191
+ - lib/zendesk2/client/requests/get_help_center_sections.rb
179
192
  - lib/zendesk2/client/requests/get_membership.rb
180
193
  - lib/zendesk2/client/requests/get_organization.rb
181
194
  - lib/zendesk2/client/requests/get_organization_by_external_id.rb
@@ -207,10 +220,14 @@ files:
207
220
  - lib/zendesk2/client/requests/mark_membership_default.rb
208
221
  - lib/zendesk2/client/requests/mark_user_identity_primary.rb
209
222
  - lib/zendesk2/client/requests/search.rb
223
+ - lib/zendesk2/client/requests/search_help_center_articles.rb
210
224
  - lib/zendesk2/client/requests/search_user.rb
211
225
  - lib/zendesk2/client/requests/update_category.rb
212
226
  - lib/zendesk2/client/requests/update_forum.rb
213
227
  - lib/zendesk2/client/requests/update_group.rb
228
+ - lib/zendesk2/client/requests/update_help_center_article.rb
229
+ - lib/zendesk2/client/requests/update_help_center_category.rb
230
+ - lib/zendesk2/client/requests/update_help_center_section.rb
214
231
  - lib/zendesk2/client/requests/update_organization.rb
215
232
  - lib/zendesk2/client/requests/update_request.rb
216
233
  - lib/zendesk2/client/requests/update_ticket.rb
@@ -230,6 +247,9 @@ files:
230
247
  - spec/categories_spec.rb
231
248
  - spec/forums_spec.rb
232
249
  - spec/groups_spec.rb
250
+ - spec/help_center/articles_spec.rb
251
+ - spec/help_center/categories_spec.rb
252
+ - spec/help_center/sections_spec.rb
233
253
  - spec/memberships_spec.rb
234
254
  - spec/organizations_spec.rb
235
255
  - spec/shared/zendesk_resource.rb
@@ -271,6 +291,9 @@ test_files:
271
291
  - spec/categories_spec.rb
272
292
  - spec/forums_spec.rb
273
293
  - spec/groups_spec.rb
294
+ - spec/help_center/articles_spec.rb
295
+ - spec/help_center/categories_spec.rb
296
+ - spec/help_center/sections_spec.rb
274
297
  - spec/memberships_spec.rb
275
298
  - spec/organizations_spec.rb
276
299
  - spec/shared/zendesk_resource.rb