zendesk2 1.10.0 → 1.11.0

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: a4b6c9e3a2263e5d8e84d8c0d408c2a40d898106
4
- data.tar.gz: db66a761d97b525ef31cb6d63ae5b6d28b5751fe
3
+ metadata.gz: 9e80f873dd170c7aa2f3a62268d1e2580228f5c5
4
+ data.tar.gz: 4eca8baf6dd0b2f4be9d2b2a4879dd77c78cec69
5
5
  SHA512:
6
- metadata.gz: f14e79bbd8b508ce7f9d22e31e4249f85ffeb4fd153b4ae244ac79293425b76ab63253c7ea8723cb1b57be64376f9dd8637ee034a25a24917d61b99e2deeb704
7
- data.tar.gz: a8b6cc3a9da6ecd75fe1174a59b790076b9f2c51004318199e9b759c634008aa6bac5a57b276125315c53c610380b5290aaf8f4e012061c9ae3543e51262c9b0
6
+ metadata.gz: 717c640ad7636fefe296d93c3c75f317fb83e758bc08c2fda527abbf2c917adb364d484cbdf75753d92a966442d6eabf58c5deb6224f0bc34474d064bfb35e21
7
+ data.tar.gz: 5a635a1179e896ab3cfcc00aa1b6751310afb29f803d8775ab3cd65c0e3ab004c6d69257db0e617eedfdfc95e682890fe8c1461c54e8f567b6164966199007c7
data/.travis.yml CHANGED
@@ -5,7 +5,6 @@ cache:
5
5
  rvm:
6
6
  - 2.3.0
7
7
  - 2.2.4
8
- - 2.1.8
9
8
  script:
10
9
  - bundle exec rubocop -Da
11
10
  - bundle exec rake spec
data/CHANGELOG.md CHANGED
@@ -2,7 +2,28 @@
2
2
 
3
3
  ## [Unreleased](https://github.com/lanej/zendesk2/tree/HEAD)
4
4
 
5
- [Full Changelog](https://github.com/lanej/zendesk2/compare/v1.8.1...HEAD)
5
+ [Full Changelog](https://github.com/lanej/zendesk2/compare/v1.10.0...HEAD)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - Please add support to Help Center subscriptions [\#43](https://github.com/lanej/zendesk2/issues/43)
10
+ - feature\(hc\): add subscriptions [\#54](https://github.com/lanej/zendesk2/pull/54) ([lanej](https://github.com/lanej))
11
+
12
+ ## [v1.10.0](https://github.com/lanej/zendesk2/tree/v1.10.0) (2016-07-01)
13
+ [Full Changelog](https://github.com/lanej/zendesk2/compare/v1.9.0...v1.10.0)
14
+
15
+ **Implemented enhancements:**
16
+
17
+ - feature\(hc\): posts [\#56](https://github.com/lanej/zendesk2/pull/56) ([lanej](https://github.com/lanej))
18
+ - feature\(hc\): add topics [\#55](https://github.com/lanej/zendesk2/pull/55) ([lanej](https://github.com/lanej))
19
+
20
+ **Merged pull requests:**
21
+
22
+ - Add locale option to categories endpoint [\#53](https://github.com/lanej/zendesk2/pull/53) ([codeminator](https://github.com/codeminator))
23
+ - Enable rubocop [\#52](https://github.com/lanej/zendesk2/pull/52) ([lanej](https://github.com/lanej))
24
+
25
+ ## [v1.9.0](https://github.com/lanej/zendesk2/tree/v1.9.0) (2016-05-25)
26
+ [Full Changelog](https://github.com/lanej/zendesk2/compare/v1.8.1...v1.9.0)
6
27
 
7
28
  **Merged pull requests:**
8
29
 
data/Gemfile CHANGED
@@ -8,9 +8,9 @@ gem 'rake'
8
8
  # To avoid warnings from JWT
9
9
  gem 'json', '~> 1.8'
10
10
  gem 'rubocop', '~> 0.41', require: false
11
- gem 'pry-nav'
12
11
 
13
12
  group :test do
13
+ gem 'pry-nav'
14
14
  gem 'awesome_print'
15
15
  gem 'rspec', '~> 3.2'
16
16
  gem 'rack-test'
@@ -2,19 +2,22 @@
2
2
  module Zendesk2::HelpCenter; end
3
3
 
4
4
  require 'zendesk2/help_center/translation_source'
5
+ require 'zendesk2/help_center/subscription_request'
5
6
 
6
7
  require 'zendesk2/help_center/create_help_center_article'
7
8
  require 'zendesk2/help_center/create_help_center_category'
8
9
  require 'zendesk2/help_center/create_help_center_post'
9
10
  require 'zendesk2/help_center/create_help_center_section'
11
+ require 'zendesk2/help_center/create_help_center_subscription'
10
12
  require 'zendesk2/help_center/create_help_center_topic'
11
13
  require 'zendesk2/help_center/create_help_center_translation'
12
14
  require 'zendesk2/help_center/destroy_help_center_article'
13
15
  require 'zendesk2/help_center/destroy_help_center_category'
14
16
  require 'zendesk2/help_center/destroy_help_center_post'
15
17
  require 'zendesk2/help_center/destroy_help_center_section'
16
- require 'zendesk2/help_center/destroy_help_center_translation'
17
18
  require 'zendesk2/help_center/destroy_help_center_topic'
19
+ require 'zendesk2/help_center/destroy_help_center_subscription'
20
+ require 'zendesk2/help_center/destroy_help_center_translation'
18
21
  require 'zendesk2/help_center/get_help_center_access_policy'
19
22
  require 'zendesk2/help_center/get_help_center_article'
20
23
  require 'zendesk2/help_center/get_help_center_articles'
@@ -27,10 +30,13 @@ require 'zendesk2/help_center/get_help_center_posts'
27
30
  require 'zendesk2/help_center/get_help_center_section'
28
31
  require 'zendesk2/help_center/get_help_center_sections'
29
32
  require 'zendesk2/help_center/get_help_center_sections_articles'
33
+ require 'zendesk2/help_center/get_help_center_subscription'
34
+ require 'zendesk2/help_center/get_help_center_subscriptions'
30
35
  require 'zendesk2/help_center/get_help_center_topic'
31
36
  require 'zendesk2/help_center/get_help_center_topics'
32
37
  require 'zendesk2/help_center/get_help_center_translation'
33
38
  require 'zendesk2/help_center/get_help_center_translations'
39
+ require 'zendesk2/help_center/get_users_help_center_subscriptions'
34
40
  require 'zendesk2/help_center/search_help_center_articles'
35
41
  require 'zendesk2/help_center/update_help_center_access_policy'
36
42
  require 'zendesk2/help_center/update_help_center_article'
@@ -38,6 +44,7 @@ require 'zendesk2/help_center/update_help_center_category'
38
44
  require 'zendesk2/help_center/update_help_center_post'
39
45
  require 'zendesk2/help_center/update_help_center_section'
40
46
  require 'zendesk2/help_center/update_help_center_topic'
47
+ require 'zendesk2/help_center/update_help_center_subscription'
41
48
  require 'zendesk2/help_center/update_help_center_translation'
42
49
 
43
50
  require 'zendesk2/help_center/access_policy'
@@ -45,6 +52,7 @@ require 'zendesk2/help_center/article'
45
52
  require 'zendesk2/help_center/category'
46
53
  require 'zendesk2/help_center/post'
47
54
  require 'zendesk2/help_center/section'
55
+ require 'zendesk2/help_center/subscription'
48
56
  require 'zendesk2/help_center/topic'
49
57
  require 'zendesk2/help_center/translation'
50
58
 
@@ -52,5 +60,6 @@ require 'zendesk2/help_center/articles'
52
60
  require 'zendesk2/help_center/categories'
53
61
  require 'zendesk2/help_center/posts'
54
62
  require 'zendesk2/help_center/sections'
63
+ require 'zendesk2/help_center/subscriptions'
55
64
  require 'zendesk2/help_center/topics'
56
65
  require 'zendesk2/help_center/translations'
@@ -54,6 +54,12 @@ class Zendesk2::HelpCenter::Article
54
54
  cistern.help_center_translations(source_id: identity, source_type: 'Article')
55
55
  end
56
56
 
57
+ def subscriptions
58
+ requires :identity
59
+
60
+ cistern.help_center_subscriptions(content_id: identity, content_type: 'article')
61
+ end
62
+
57
63
  def save!
58
64
  response = if new_record?
59
65
  requires :title, :locale, :section_id
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+ class Zendesk2::CreateHelpCenterSubscription
3
+ include Zendesk2::Request
4
+ include Zendesk2::HelpCenter::SubscriptionRequest
5
+
6
+ request_method :post
7
+ request_path { |r| "/#{r.route_prefix}/#{r.plural_content_type}/#{r.content_id}/subscriptions.json" }
8
+ request_body do |r|
9
+ { 'subscription' => r.subscription_params } if r.subscription_params.any?
10
+ end
11
+
12
+ def subscription_params
13
+ return @subscription_params if @subscription_params
14
+ body = Cistern::Hash.slice(subscription, *self.class.accepted_attributes(content_type))
15
+ body['source_locale'] = body.delete('locale') if body['locale']
16
+ @subscription_params = body
17
+ end
18
+
19
+ def mock
20
+ identity = cistern.serial_id
21
+
22
+ url = url_for("/help_center/#{plural_content_type}/#{content_id}/subscription.json")
23
+
24
+ content_collection = "help_center_#{plural_content_type}".to_sym
25
+ find!(content_collection, content_id)
26
+
27
+ if subscription_params.empty?
28
+ mock_response('Required parameter missing: subscription', status: 400)
29
+ end
30
+
31
+
32
+ record = subscription_params.merge(
33
+ 'id' => identity,
34
+ 'url' => url,
35
+ 'created_at' => Time.now.iso8601, # @todo create #timestamp helper
36
+ 'updated_at' => Time.now.iso8601,
37
+ 'content_id' => content_id,
38
+ 'content_type' => content_type,
39
+ )
40
+
41
+ record['locale'] = record.delete('source_locale') if record['source_locale']
42
+
43
+ cistern.data[:help_center_subscriptions][identity] = record
44
+
45
+ mock_response('subscription' => record)
46
+ end
47
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ class Zendesk2::DestroyHelpCenterSubscription
3
+ include Zendesk2::Request
4
+ include Zendesk2::HelpCenter::SubscriptionRequest
5
+
6
+ request_method :delete
7
+ request_path do |r|
8
+ route = "/#{r.route_prefix}/#{r.plural_content_type}/#{r.content_id}"
9
+ route + "/subscriptions/#{r.subscription_id}.json"
10
+ end
11
+
12
+ def mock
13
+ content_collection = "help_center_#{plural_content_type}".to_sym
14
+ find!(content_collection, content_id)
15
+
16
+ delete!(:help_center_subscriptions, subscription_id)
17
+
18
+ mock_response(nil, status: 204)
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ class Zendesk2::GetHelpCenterSubscription
3
+ include Zendesk2::Request
4
+ include Zendesk2::HelpCenter::SubscriptionRequest
5
+
6
+ request_method :get
7
+ request_path do |r|
8
+ content_path = "/#{r.route_prefix}/#{r.plural_content_type}"
9
+ content_path + "/#{r.content_id}/subscriptions/#{r.subscription_id}.json"
10
+ end
11
+
12
+ def mock(_params = {})
13
+ mock_response('subscription' => find!(:help_center_subscriptions, subscription_id))
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ class Zendesk2::GetHelpCenterSubscriptions
3
+ include Zendesk2::Request
4
+ include Zendesk2::HelpCenter::SubscriptionRequest
5
+
6
+ request_path { |r| "/#{r.route_prefix}/#{r.plural_content_type}/#{r.content_id}/subscriptions.json" }
7
+
8
+ page_params!
9
+
10
+ def content_type
11
+ params.fetch('content_type')
12
+ end
13
+
14
+ def content_id
15
+ params.fetch('content_id').to_i
16
+ end
17
+
18
+ def mock
19
+ article_subscriptions = cistern.data[:help_center_subscriptions].values.select do |sub|
20
+ sub['content_id'] == content_id
21
+ end
22
+
23
+ page(article_subscriptions, root: 'subscriptions')
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ class Zendesk2::GetUsersHelpCenterSubscriptions
3
+ include Zendesk2::Request
4
+
5
+ request_path { |r| "/help_center/users/#{r.user_id}/subscriptions.json" }
6
+
7
+ page_params!
8
+
9
+ def user_id
10
+ params.fetch('user_id').to_i
11
+ end
12
+
13
+ def mock
14
+ article_subscriptions = cistern.data[:help_center_subscriptions].values.select do |sub|
15
+ sub['user_id'] == user_id
16
+ end
17
+
18
+ page(article_subscriptions, root: 'subscriptions')
19
+ end
20
+ end
@@ -61,7 +61,7 @@ class Zendesk2::HelpCenter::Post
61
61
  end
62
62
 
63
63
  def author
64
- author_id && cistern.users.get!(author_id)
64
+ cistern.users.get!(author_id) if author_id
65
65
  end
66
66
 
67
67
  def topic
@@ -69,4 +69,10 @@ class Zendesk2::HelpCenter::Post
69
69
 
70
70
  cistern.help_center_topics.get!(topic_id)
71
71
  end
72
+
73
+ def subscriptions
74
+ requires :identity
75
+
76
+ cistern.help_center_subscriptions(content_id: identity, content_type: 'post')
77
+ end
72
78
  end
@@ -73,6 +73,12 @@ class Zendesk2::HelpCenter::Section
73
73
  cistern.help_center_access_policy(response)
74
74
  end
75
75
 
76
+ def subscriptions
77
+ requires :identity
78
+
79
+ cistern.help_center_subscriptions(content_id: identity, content_type: 'section')
80
+ end
81
+
76
82
  def translations
77
83
  requires :identity
78
84
 
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+ class Zendesk2::HelpCenter::Subscription
3
+ include Zendesk2::Model
4
+
5
+ extend Zendesk2::Attributes
6
+
7
+ # @return [Integer] Automatically assigned when the subscription is created
8
+ identity :id, type: :integer # ro: yes, required: no
9
+
10
+ # @return [String] The API url of the subscription
11
+ attribute :url # ro: yes, required: no
12
+ # @return [Integer] The id of the user who has this subscription
13
+ attribute :user_id, type: :integer # ro: yes, required: no
14
+ # @return [Integer] The id of the subscribed item
15
+ attribute :content_id, type: :integer # ro: yes, required: no
16
+ # @return [String] The type of the subscribed item
17
+ attribute :content_type # ro: yes, required: no
18
+ # @return [String] The locale of the subscribed item
19
+ attribute :locale # ro: yes, required: yes
20
+ # @return [Boolean] Subscribe also to article comments. Only for section subscriptions.
21
+ attribute :include_comments, type: :boolean # ro: yes, required: no
22
+ # @return [Time] The time at which the subscription was created
23
+ attribute :created_at, type: :time # ro: yes, required: no
24
+ # @return [Time] The time at which the subscription was last updated
25
+ attribute :updated_at, type: :time # ro: yes, required: no
26
+
27
+ def destroy!
28
+ requires :identity
29
+
30
+ cistern.destroy_help_center_subscription('subscription' => attributes)
31
+ end
32
+
33
+ def save!
34
+ response = if new_record?
35
+ requires :content_id, :content_type
36
+
37
+ cistern.create_help_center_subscription('subscription' => attributes)
38
+ else
39
+ requires :identity
40
+
41
+ cistern.update_help_center_subscription('subscription' => attributes)
42
+ end
43
+
44
+ merge_attributes(response.body['subscription'])
45
+ end
46
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+ module Zendesk2::HelpCenter::SubscriptionRequest
3
+
4
+ def self.included(klass)
5
+ super
6
+ klass.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+ def accepted_attributes(type)
11
+ case type
12
+ when 'topic'
13
+ %w(include_comments user_id)
14
+ when 'post'
15
+ %w(user_id)
16
+ else
17
+ %w(locale user_id)
18
+ end
19
+ end
20
+ end
21
+
22
+ def route_prefix
23
+ case content_type
24
+ when 'topic', 'post'
25
+ 'community'
26
+ else
27
+ 'help_center'
28
+ end
29
+ end
30
+
31
+ def plural_content_type
32
+ pluralize(content_type)
33
+ end
34
+
35
+ def content_type
36
+ subscription.fetch('content_type')
37
+ end
38
+
39
+ def content_id
40
+ subscription.fetch('content_id').to_i
41
+ end
42
+
43
+ def subscription_id
44
+ subscription.fetch('id')
45
+ end
46
+
47
+ def subscription
48
+ Cistern::Hash.stringify_keys(params.fetch('subscription'))
49
+ end
50
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+ class Zendesk2::HelpCenter::Subscriptions
3
+ include Zendesk2::Collection
4
+ include Zendesk2::PagedCollection
5
+
6
+ include Zendesk2::Searchable
7
+
8
+ model Zendesk2::HelpCenter::Subscription
9
+
10
+ self.collection_method = :get_help_center_subscriptions
11
+ self.collection_root = 'subscriptions'
12
+ self.model_method = :get_help_center_subscription
13
+ self.model_root = 'subscription'
14
+
15
+ attribute :content_id, type: :integer
16
+ attribute :content_type, type: :string
17
+ attribute :user_id, type: :integer
18
+
19
+ scopes << :content_id
20
+ scopes << :content_type
21
+ scopes << :user_id
22
+
23
+ def collection_method
24
+ user_id ? :get_users_help_center_subscriptions : super
25
+ end
26
+
27
+ def get!(*args)
28
+ requires :content_id, :content_type
29
+
30
+ super
31
+ end
32
+ end
@@ -49,4 +49,10 @@ class Zendesk2::HelpCenter::Topic
49
49
 
50
50
  cistern.help_center_posts(topic_id: identity)
51
51
  end
52
+
53
+ def subscriptions
54
+ requires :identity
55
+
56
+ cistern.help_center_subscriptions(content_id: identity, content_type: 'topic')
57
+ end
52
58
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+ class Zendesk2::UpdateHelpCenterSubscription
3
+ include Zendesk2::Request
4
+ include Zendesk2::HelpCenter::SubscriptionRequest
5
+
6
+ request_method :put
7
+ request_path { |r| "/#{r.route_prefix}/#{r.plural_content_type}/#{r.content_id}/subscriptions.json" }
8
+ request_body do |r|
9
+ { 'subscription' => r.subscription_params } if r.subscription_params.any?
10
+ end
11
+
12
+ def subscription_params
13
+ return @subscription_params if @subscription_params
14
+ body = Cistern::Hash.slice(subscription, *self.class.accepted_attributes(content_type))
15
+ body['source_locale'] = body.delete('locale') if body['locale']
16
+ @subscription_params = body
17
+ end
18
+
19
+ def mock
20
+ subscription = find!(:help_center_subscriptions, subscription_id)
21
+
22
+ if subscription_params.empty?
23
+ mock_response('Required parameter missing: subscription', status: 400)
24
+ end
25
+
26
+ updated = subscription_params
27
+ updated['locale'] = updated.delete('source_locale') if updated['source_locale']
28
+ updated['updated_at'] = Time.now.iso8601
29
+
30
+ subscription.merge!(updated)
31
+
32
+ mock_response('subscription' => subscription)
33
+ end
34
+ end
data/lib/zendesk2/mock.rb CHANGED
@@ -14,6 +14,7 @@ class Zendesk2::Mock
14
14
  help_center_categories: {},
15
15
  help_center_posts: {},
16
16
  help_center_sections: {},
17
+ help_center_subscriptions: {},
17
18
  help_center_topics: {},
18
19
  help_center_translations: {},
19
20
  identities: {},
data/lib/zendesk2/user.rb CHANGED
@@ -190,6 +190,13 @@ class Zendesk2::User
190
190
  cistern.organizations(user: self)
191
191
  end
192
192
 
193
+ # @return [Zendesk2::HelpCenter::Subscriptions] subscriptions
194
+ def subscriptions
195
+ requires :identity
196
+
197
+ cistern.help_center_subscriptions(user_id: identity)
198
+ end
199
+
193
200
  # @return [Zendesk2::HelpCenter::Post] authored posts
194
201
  def posts
195
202
  requires :identity
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Zendesk2
3
- VERSION = '1.10.0'
3
+ VERSION = '1.11.0'
4
4
  end
@@ -17,20 +17,4 @@ describe 'help_center/articles' do
17
17
  update_params: -> { { title: mock_uuid } },
18
18
  search_params: -> { Cistern::Hash.slice(create_params, :title) },
19
19
  search: true
20
-
21
- describe 'translations' do
22
- let!(:article) do
23
- client.help_center_articles.create!(title: mock_uuid,
24
- locale: 'en-us',
25
- section: section)
26
- end
27
- let!(:locale) { mock_uuid }
28
-
29
- include_examples 'zendesk#resource',
30
- collection: -> { article.translations },
31
- fetch_params: ->(r) { Cistern::Hash.slice(r.attributes, :source_id, :source_type, :locale) },
32
- create_params: -> { { source: article, locale: locale, title: mock_uuid } },
33
- update_params: -> { { title: mock_uuid } },
34
- search: false
35
- end
36
20
  end
@@ -28,16 +28,4 @@ describe 'help_center/categories' do
28
28
  expect(category.articles.all).to match_array(articles)
29
29
  end
30
30
  end
31
-
32
- describe 'translations' do
33
- let!(:category) { client.help_center_categories.create!(name: mock_uuid, locale: 'en-us') }
34
- let!(:locale) { mock_uuid }
35
-
36
- include_examples 'zendesk#resource',
37
- collection: -> { category.translations },
38
- fetch_params: ->(r) { Cistern::Hash.slice(r.attributes, :source_id, :source_type, :locale) },
39
- create_params: -> { { source: category, locale: locale, title: mock_uuid } },
40
- update_params: -> { { title: mock_uuid } },
41
- search: false
42
- end
43
31
  end
@@ -43,17 +43,4 @@ describe 'help_center/sections' do
43
43
  end.to change { section.reload.access_policy.viewable_by }.from(old_viewable_by).to(new_viewable_by)
44
44
  end
45
45
  end
46
-
47
- describe 'translations' do
48
- let!(:category) { client.help_center_categories.create!(name: mock_uuid, locale: 'en-us') }
49
- let!(:section) { category.sections.create!(name: mock_uuid, locale: 'en-us') }
50
- let!(:locale) { mock_uuid }
51
-
52
- include_examples 'zendesk#resource',
53
- collection: -> { section.translations },
54
- fetch_params: ->(r) { Cistern::Hash.slice(r.attributes, :source_id, :source_type, :locale) },
55
- create_params: -> { { source: section, locale: locale, title: mock_uuid } },
56
- update_params: -> { { title: mock_uuid } },
57
- search: false
58
- end
59
46
  end
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ describe 'help_center/subscriptions' do
5
+ let(:client) { create_client }
6
+ let(:category) { client.help_center_categories.create!(name: mock_uuid, locale: 'en-us') }
7
+ let(:section) do
8
+ client.help_center_sections.create!(name: mock_uuid,
9
+ locale: 'en-us',
10
+ category: category)
11
+ end
12
+
13
+ describe 'with an article' do
14
+ let!(:article) do
15
+ client.help_center_articles.create!(title: mock_uuid,
16
+ locale: 'en-us',
17
+ section: section)
18
+ end
19
+
20
+ include_examples 'zendesk#resource',
21
+ collection: -> { article.subscriptions },
22
+ create_params: lambda {
23
+ subscriber = client.users.create!(
24
+ email: mock_email,
25
+ name: mock_uuid,
26
+ )
27
+ { user_id: subscriber.id, locale: 'en-us' }
28
+ },
29
+ update_params: lambda {
30
+ subscriber = client.users.create!(
31
+ email: mock_email,
32
+ name: mock_uuid,
33
+ )
34
+ { user_id: subscriber.id, locale: 'en-gb' }
35
+ },
36
+ search: false
37
+ end
38
+
39
+ describe 'with an section' do
40
+ before { section }
41
+
42
+ include_examples 'zendesk#resource',
43
+ collection: -> { section.subscriptions },
44
+ create_params: lambda {
45
+ subscriber = client.users.create!(
46
+ email: mock_email,
47
+ name: mock_uuid,
48
+ )
49
+ { user_id: subscriber.id, locale: 'en-us' }
50
+ },
51
+ update_params: lambda {
52
+ subscriber = client.users.create!(
53
+ email: mock_email,
54
+ name: mock_uuid,
55
+ )
56
+ { user_id: subscriber.id, locale: 'en-gb' }
57
+ },
58
+ search: false
59
+ end
60
+
61
+ describe 'with a topic' do
62
+ let!(:topic) { client.help_center_topics.create(name: mock_uuid) }
63
+
64
+ include_examples 'zendesk#resource',
65
+ collection: -> { topic.subscriptions },
66
+ create_params: lambda {
67
+ subscriber = client.users.create!(
68
+ email: mock_email,
69
+ name: mock_uuid,
70
+ )
71
+ { user_id: subscriber.id, include_comments: true }
72
+ },
73
+ update_params: lambda {
74
+ subscriber = client.users.create!(
75
+ email: mock_email,
76
+ name: mock_uuid,
77
+ )
78
+ { user_id: subscriber.id, include_comments: false }
79
+ },
80
+ search: false
81
+ end
82
+
83
+ describe 'with a post' do
84
+ let!(:topic) { client.help_center_topics.create(name: mock_uuid) }
85
+ let!(:author) do
86
+ client.users.create!(
87
+ email: mock_email,
88
+ name: mock_uuid,
89
+ )
90
+ end
91
+ let!(:post) do
92
+ client.help_center_posts.create(
93
+ title: mock_uuid,
94
+ details: mock_uuid,
95
+ topic_id: topic.id,
96
+ author_id: author.id,
97
+ )
98
+ end
99
+
100
+ include_examples 'zendesk#resource',
101
+ collection: -> { post.subscriptions },
102
+ create_params: lambda {
103
+ subscriber = client.users.create!(
104
+ email: mock_email,
105
+ name: mock_uuid,
106
+ )
107
+ { user_id: subscriber.id }
108
+ },
109
+ update_params: lambda {
110
+ subscriber = client.users.create!(
111
+ email: mock_email,
112
+ name: mock_uuid,
113
+ )
114
+ { user_id: subscriber.id }
115
+ },
116
+ search: false
117
+ end
118
+
119
+ it 'lists subscription by user' do
120
+ subscriber = client.users.create!(
121
+ email: mock_email,
122
+ name: mock_uuid,
123
+ )
124
+
125
+ subscription = section.subscriptions.create(user_id: subscriber.id, locale: 'en-us')
126
+
127
+ expect(subscriber.subscriptions).to include(subscription)
128
+ end
129
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ describe 'help_center/translations' do
5
+ let(:client) { create_client }
6
+ let!(:locale) { mock_uuid }
7
+ let!(:category) { client.help_center_categories.create!(name: mock_uuid, locale: 'en-us') }
8
+
9
+ let(:section) { category.sections.create!(name: mock_uuid, locale: 'en-us') }
10
+
11
+ describe 'by category' do
12
+ include_examples 'zendesk#resource',
13
+ collection: -> { category.translations },
14
+ fetch_params: ->(r) { Cistern::Hash.slice(r.attributes, :source_id, :source_type, :locale) },
15
+ create_params: -> { { source: category, locale: locale, title: mock_uuid } },
16
+ update_params: -> { { title: mock_uuid } },
17
+ search: false
18
+ end
19
+
20
+ describe 'by section' do
21
+ before { section }
22
+
23
+ include_examples 'zendesk#resource',
24
+ collection: -> { section.translations },
25
+ fetch_params: ->(r) { Cistern::Hash.slice(r.attributes, :source_id, :source_type, :locale) },
26
+ create_params: -> { { source: section, locale: locale, title: mock_uuid } },
27
+ update_params: -> { { title: mock_uuid } },
28
+ search: false
29
+ end
30
+
31
+ describe 'by article' do
32
+ let!(:article) { client.help_center_articles.create!(title: mock_uuid, locale: 'en-us', section: section) }
33
+
34
+ include_examples 'zendesk#resource',
35
+ collection: -> { article.translations },
36
+ fetch_params: ->(r) { Cistern::Hash.slice(r.attributes, :source_id, :source_type, :locale) },
37
+ create_params: -> { { source: article, locale: locale, title: mock_uuid } },
38
+ update_params: -> { { title: mock_uuid } },
39
+ search: false
40
+ end
41
+ end
@@ -23,7 +23,9 @@ shared_examples 'zendesk#resource' do |options = {}|
23
23
  if options.fetch(:paged, true)
24
24
  context 'paging' do
25
25
  before(:each) do
26
- @resources = Array.new(3) { collection.create!(instance_exec(&options[:create_params])) }
26
+ if collection.reload.count < 3
27
+ @resources = Array.new(3) { collection.create!(instance_exec(&options[:create_params])) }
28
+ end
27
29
  end
28
30
 
29
31
  after(:each) { (@resources || []).each(&:destroy) }
@@ -77,13 +79,15 @@ shared_examples 'zendesk#resource' do |options = {}|
77
79
  end
78
80
  end
79
81
 
80
- it 'should be destroyed' do
81
- @record = collection.create!(create_params)
82
- expect(record.identity).not_to be_nil
83
- record.destroy
82
+ if options.fetch(:destroy, true)
83
+ it 'should be destroyed' do
84
+ @record = collection.create!(create_params)
85
+ expect(record.identity).not_to be_nil
86
+ record.destroy
84
87
 
85
- if !options.fetch(:delayed_destroy, false) && !Zendesk2.mocking?
86
- expect(record).to be_destroyed
88
+ if !options.fetch(:delayed_destroy, false) && !Zendesk2.mocking?
89
+ expect(record).to be_destroyed
90
+ end
87
91
  end
88
92
  end
89
93
 
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.10.0
4
+ version: 1.11.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: 2016-07-01 00:00:00.000000000 Z
11
+ date: 2016-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cistern
@@ -173,12 +173,14 @@ files:
173
173
  - lib/zendesk2/help_center/create_help_center_category.rb
174
174
  - lib/zendesk2/help_center/create_help_center_post.rb
175
175
  - lib/zendesk2/help_center/create_help_center_section.rb
176
+ - lib/zendesk2/help_center/create_help_center_subscription.rb
176
177
  - lib/zendesk2/help_center/create_help_center_topic.rb
177
178
  - lib/zendesk2/help_center/create_help_center_translation.rb
178
179
  - lib/zendesk2/help_center/destroy_help_center_article.rb
179
180
  - lib/zendesk2/help_center/destroy_help_center_category.rb
180
181
  - lib/zendesk2/help_center/destroy_help_center_post.rb
181
182
  - lib/zendesk2/help_center/destroy_help_center_section.rb
183
+ - lib/zendesk2/help_center/destroy_help_center_subscription.rb
182
184
  - lib/zendesk2/help_center/destroy_help_center_topic.rb
183
185
  - lib/zendesk2/help_center/destroy_help_center_translation.rb
184
186
  - lib/zendesk2/help_center/get_help_center_access_policy.rb
@@ -193,15 +195,21 @@ files:
193
195
  - lib/zendesk2/help_center/get_help_center_section.rb
194
196
  - lib/zendesk2/help_center/get_help_center_sections.rb
195
197
  - lib/zendesk2/help_center/get_help_center_sections_articles.rb
198
+ - lib/zendesk2/help_center/get_help_center_subscription.rb
199
+ - lib/zendesk2/help_center/get_help_center_subscriptions.rb
196
200
  - lib/zendesk2/help_center/get_help_center_topic.rb
197
201
  - lib/zendesk2/help_center/get_help_center_topics.rb
198
202
  - lib/zendesk2/help_center/get_help_center_translation.rb
199
203
  - lib/zendesk2/help_center/get_help_center_translations.rb
204
+ - lib/zendesk2/help_center/get_users_help_center_subscriptions.rb
200
205
  - lib/zendesk2/help_center/post.rb
201
206
  - lib/zendesk2/help_center/posts.rb
202
207
  - lib/zendesk2/help_center/search_help_center_articles.rb
203
208
  - lib/zendesk2/help_center/section.rb
204
209
  - lib/zendesk2/help_center/sections.rb
210
+ - lib/zendesk2/help_center/subscription.rb
211
+ - lib/zendesk2/help_center/subscription_request.rb
212
+ - lib/zendesk2/help_center/subscriptions.rb
205
213
  - lib/zendesk2/help_center/topic.rb
206
214
  - lib/zendesk2/help_center/topics.rb
207
215
  - lib/zendesk2/help_center/translation.rb
@@ -212,6 +220,7 @@ files:
212
220
  - lib/zendesk2/help_center/update_help_center_category.rb
213
221
  - lib/zendesk2/help_center/update_help_center_post.rb
214
222
  - lib/zendesk2/help_center/update_help_center_section.rb
223
+ - lib/zendesk2/help_center/update_help_center_subscription.rb
215
224
  - lib/zendesk2/help_center/update_help_center_topic.rb
216
225
  - lib/zendesk2/help_center/update_help_center_translation.rb
217
226
  - lib/zendesk2/logger.rb
@@ -279,7 +288,9 @@ files:
279
288
  - spec/help_center/categories_spec.rb
280
289
  - spec/help_center/posts_spec.rb
281
290
  - spec/help_center/sections_spec.rb
291
+ - spec/help_center/subscriptions_spec.rb
282
292
  - spec/help_center/topics_spec.rb
293
+ - spec/help_center/translations_spec.rb
283
294
  - spec/lib/paged_collection_spec.rb
284
295
  - spec/lib/rate_limit_spec.rb
285
296
  - spec/memberships_spec.rb
@@ -331,7 +342,9 @@ test_files:
331
342
  - spec/help_center/categories_spec.rb
332
343
  - spec/help_center/posts_spec.rb
333
344
  - spec/help_center/sections_spec.rb
345
+ - spec/help_center/subscriptions_spec.rb
334
346
  - spec/help_center/topics_spec.rb
347
+ - spec/help_center/translations_spec.rb
335
348
  - spec/lib/paged_collection_spec.rb
336
349
  - spec/lib/rate_limit_spec.rb
337
350
  - spec/memberships_spec.rb
@@ -349,3 +362,4 @@ test_files:
349
362
  - spec/users_spec.rb
350
363
  - spec/views_spec.rb
351
364
  - spec/zendesk2_spec.rb
365
+ has_rdoc: