zendesk_help_center_api 0.0.1

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +91 -0
  3. data/lib/zendesk_api/help_center.rb +155 -0
  4. metadata +103 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5b3bc0dbe25b5d814ddf87f31c33a9d054695035
4
+ data.tar.gz: 0d2fefe1c7f41ed2cc04ac198bda9b89d207de31
5
+ SHA512:
6
+ metadata.gz: 9a6fb847cab6527af5b4b40f2f6facd627ff4b80679db38b5050cfee2fa8844d4030c5aa8bd8f95e4bb3fbad18401f2829f1200e2a5a00564f4b291dd233e544
7
+ data.tar.gz: 95b3beb3c5e5b203bff4979b3163443da44f0ed866540f45b1823d3d1052b5d37d2ab42f409be438f36ce911a6ee01079145cda2e895679e648c24134a681973
data/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # Zendesk HelpCenter API Client
2
+
3
+ This gem added support for `Zendesk Help Center` methods under [ZendeskAPI::Client](https://github.com/zendesk/zendesk_api_client_rb) gem.
4
+
5
+ To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'zendesk_help_center_api'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ ```
19
+ $ bundle
20
+ ```
21
+
22
+ Or install it yourself as:
23
+
24
+ ```
25
+ $ gem install zendesk_help_center_api
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ```ruby
31
+ require 'zendesk_api/help_center'
32
+ ```
33
+
34
+ ### Help Center
35
+
36
+ #### Categories
37
+
38
+ ```ruby
39
+ categories = client.hc_categories
40
+ category = categories.build(name: 'Test Category')
41
+ category.save
42
+ category.update(description: 'This is a test')
43
+ category.destroy
44
+ ```
45
+
46
+ #### Sections
47
+
48
+ ```ruby
49
+ sections = category.sections
50
+ section = sections.first
51
+ category.update(name: 'This is a test')
52
+ ```
53
+
54
+ #### Articles
55
+
56
+ ```ruby
57
+ articles = section.articles
58
+ articles.build(title: 'Test Article')
59
+ category.update(description: 'This is a test')
60
+ article.destroy
61
+ ```
62
+
63
+ ### Help Center Translations
64
+
65
+ ```ruby
66
+ categories_tr = category.translations
67
+ category_tr = categories_tr.build(locale: 'uk', name: 'Тестова Стаття')
68
+ category_tr.save
69
+
70
+ sections_tr = sections.translations
71
+ section_tr = article_tr.build(locale: 'uk', name: 'Це тест')
72
+ section_tr.save
73
+
74
+ articles_tr = article.translations
75
+ article_tr = article_translations.build(locale: 'uk', title: 'Тестова Стаття')
76
+ article_tr.save
77
+ ```
78
+
79
+ ## Development
80
+
81
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
82
+
83
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
84
+
85
+ ## Contributing
86
+
87
+ 1. Fork it ( https://github.com/mamantoha/zendesk_help_center_api_client_rb/fork )
88
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
89
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
90
+ 4. Push to the branch (`git push origin my-new-feature`)
91
+ 5. Create a new Pull Request
@@ -0,0 +1,155 @@
1
+ require 'zendesk_api'
2
+ # require 'byebug'
3
+
4
+ module ZendeskAPI
5
+ module HelpCenter
6
+ include DataNamespace
7
+
8
+ class Article < Resource; end
9
+ class Section < Resource; end
10
+
11
+ class Article < Resource
12
+ class << self
13
+ def singular_resource_name
14
+ 'article'
15
+ end
16
+ end
17
+ end
18
+
19
+ class Section < Resource
20
+ class << self
21
+ def singular_resource_name
22
+ 'section'
23
+ end
24
+ end
25
+ end
26
+
27
+ class HcCategory < Resource
28
+ class << self
29
+ def singular_resource_name
30
+ 'category'
31
+ end
32
+ end
33
+ end
34
+
35
+ class HcCategory < Resource
36
+ class Translation < DataResource
37
+ extend Read
38
+ include Create
39
+ include Update
40
+ include Destroy
41
+
42
+ def initialize(client, attributes = {})
43
+ attributes["category_id"] ||= attributes.delete('source_id')
44
+ super
45
+ end
46
+
47
+ # Categorues and sections have the mandatory keys 'name' and 'description'. But in translations used 'title' and 'body' keys.
48
+ # Here we replace this keys:
49
+ #
50
+ # More info:
51
+ # https://support.zendesk.com/hc/communities/public/posts/204262967-Error-when-creating-new-translation-for-the-section-via-Rest-API
52
+ #
53
+ def attributes_for_save
54
+ attributes[:title] ||= attributes.delete(:name)
55
+ attributes[:body] ||= attributes.delete(:description)
56
+
57
+ attributes
58
+ end
59
+
60
+ def destroy!
61
+ super do |req|
62
+ req.path = @client.config.url + "/help_center/translations/" + id.to_s
63
+ end
64
+ end
65
+
66
+ has HcCategory
67
+ end
68
+
69
+ has_many Translation
70
+ end
71
+
72
+ class Section < Resource
73
+ class Translation < DataResource
74
+ extend Read
75
+ include Create
76
+ include Update
77
+ include Destroy
78
+
79
+ def initialize(client, attributes = {})
80
+ attributes["section_id"] ||= attributes.delete('source_id')
81
+ super
82
+ end
83
+
84
+ def attributes_for_save
85
+ attributes[:title] ||= attributes.delete(:name)
86
+ attributes[:body] ||= attributes.delete(:description)
87
+
88
+ attributes
89
+ end
90
+
91
+ def destroy!
92
+ super do |req|
93
+ req.path = @client.config.url + "/help_center/translations/" + id.to_s
94
+ end
95
+ end
96
+
97
+ has Section
98
+ end
99
+
100
+ has_many Translation
101
+ end
102
+
103
+ class Article < Resource
104
+ class Translation < DataResource
105
+ extend Read
106
+ include Create
107
+ include Update
108
+ include Destroy
109
+
110
+ def initialize(client, attributes = {})
111
+ attributes["article_id"] ||= attributes.delete('source_id')
112
+ super
113
+ end
114
+
115
+ def destroy!
116
+ super do |req|
117
+ req.path = @client.config.url + "/help_center/translations/" + id.to_s
118
+ end
119
+ end
120
+
121
+ has Article
122
+ end
123
+
124
+ has_many Translation
125
+ end
126
+
127
+ class HcCategory < Resource
128
+ namespace "help_center"
129
+
130
+ has_many Section
131
+ has_many Article
132
+ end
133
+
134
+ class Section < Resource
135
+ namespace "help_center"
136
+
137
+ has HcCategory
138
+ has_many Article
139
+
140
+ def save!(*)
141
+ category = @association.options.parent
142
+ super do |req|
143
+ req.path = "help_center/categories/#{category.id}/sections"
144
+ end
145
+ end
146
+ end
147
+
148
+ class Article < Resource
149
+ namespace "help_center"
150
+
151
+ has HcCategory
152
+ has Section
153
+ end
154
+ end
155
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zendesk_help_center_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Anton Maminov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: zendesk_api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Ruby wrapper for the REST API at http://www.zendesk.com. Documentation
70
+ at https://developer.zendesk.com/rest_api/docs/help_center/introduction.
71
+ email:
72
+ - anton.linux@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - README.md
78
+ - lib/zendesk_api/help_center.rb
79
+ homepage: https://github.com/mamantoha/zendesk_help_center_api_client_rb
80
+ licenses:
81
+ - Apache License Version 2.0
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 2.0.0
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.2.2
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Zendesk Help Center REST API Client
103
+ test_files: []