zendesk2 0.0.15 → 0.0.16

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.
data/README.md CHANGED
@@ -30,15 +30,19 @@ Default credentials will be read in from `~/.zendesk2` file in YAML format.
30
30
  ### Creating the client
31
31
 
32
32
  Either the absolute url or the subdomain is required. Username and password is always required.
33
+
33
34
  ```ruby
34
35
  Zendesk2::Client.new(subdomain: "engineyard", username: "orchestra", password: "gwoo")
35
36
  => #<Zendesk2::Client::Real:0x007f99da1f9430 @url="https://engineyard.zendesk.com/api/v2", @username="orchestra", @password="gwoo", …>
36
37
  ```
38
+
37
39
  or
40
+
38
41
  ```ruby
39
42
  Zendesk2::Client.new(url: "http://support.cloud.engineyard.com", username: "mate", password: "bambilla")
40
43
  => #<Zendesk2::Client::Real:0x007fd1bae486b0 @url="http://support.cloud.engineyard.com", @username="mate", @password="bambilla", …>
41
44
  ```
45
+
42
46
  ### Resources
43
47
 
44
48
  #### Collections
@@ -46,13 +50,14 @@ Zendesk2::Client.new(url: "http://support.cloud.engineyard.com", username: "mate
46
50
  Currently support resources
47
51
 
48
52
  * Categories
49
- * User
50
- * Ticket
51
- * Organization
52
53
  * Forums
54
+ * Organization
55
+ * Ticket
53
56
  * Topics
57
+ * User
54
58
 
55
59
  All collection are accessed like so:
60
+
56
61
  ```ruby
57
62
  client.users.all
58
63
  => <Zendesk2::Client::Users
@@ -67,7 +72,9 @@ client.users.all
67
72
  >
68
73
  ]
69
74
  ```
75
+
70
76
  Collections also respond to `create` and `new`
77
+
71
78
  ```ruby
72
79
  client.users.create(email: "ohhai@example.org", name: "lulz")
73
80
  => <Zendesk2::Client::User
@@ -90,9 +97,11 @@ client.users.new(email: "ohhai@example.org")
90
97
  ...
91
98
  >
92
99
  ```
100
+
93
101
  #### Paging
94
102
 
95
103
  Paged collections respond to `next_page` and `previous_page` when appropriate. `page_size` and `page` can be passed directly to the collection to control size and index.
104
+
96
105
  ```ruby
97
106
  page = client.users.all("per_page" => 1, "page" => 4)
98
107
  => <Zendesk2::Client::Users
@@ -109,6 +118,7 @@ page = client.users.all("per_page" => 1, "page" => 4)
109
118
  >
110
119
  ]
111
120
  ```
121
+
112
122
  ```ruby
113
123
  page.next_page
114
124
  => <Zendesk2::Client::Users
@@ -125,6 +135,7 @@ page.next_page
125
135
  >
126
136
  ]
127
137
  ```
138
+
128
139
  ```ruby
129
140
  page.previous_page
130
141
  => <Zendesk2::Client::Users
@@ -141,13 +152,16 @@ page.previous_page
141
152
  >
142
153
  ]
143
154
  ```
155
+
144
156
  #### Models
145
157
 
146
158
  All models respond to `destroy` and `save` if applicable. `save` performs a 'create' operation if there is no identity provided or an 'update' if there is an identity.
159
+
147
160
  ```ruby
148
161
  Zendesk2::Client::Ticket.new.save # performs a create
149
162
  Zendesk2::Client::Ticket.new(id: 1).save # performs an update
150
163
  ```
164
+
151
165
  Attributes can be enumerated by the `attributes` method.
152
166
 
153
167
  ## Releasing
@@ -0,0 +1,45 @@
1
+ class Zendesk2::Client::TopicComment < Cistern::Model
2
+ extend Zendesk2::Attributes
3
+
4
+ PARAMS = %w[id topic_id user_id body informative]
5
+
6
+ identity :id, type: :integer # ro[integer] mandatory [yes] Automatically assigned upon creation
7
+ attribute :url, type: :string # ro[yes] mandatory [no] The API url of this topic comment
8
+ attribute :topic_id, type: :integer # ro[no] mandatory [yes] The id of the topic this comment was made on
9
+ attribute :user_id, type: :integer # ro[no] mandatory [yes] The id of the user making the topic comment
10
+ attribute :body, type: :string # ro[no] mandatory [yes] The comment body
11
+ attribute :informative, type: :boolean # ro[no] mandatory [no] If the comment has been flagged as informative
12
+ attribute :attachments, type: :array # ro[yes] mandatory [no] Attachments to this comment as Attachment objects
13
+ attribute :created_at, type: :date # ro[yes] mandatory [no] The time the topic_comment was created
14
+ attribute :updated_at, type: :date # ro[yes] mandatory [no] The time of the last update of the topic_comment
15
+
16
+ assoc_accessor :user
17
+ assoc_accessor :topic
18
+
19
+ def destroy
20
+ requires :identity
21
+
22
+ connection.destroy_topic_comment("id" => self.identity)
23
+ end
24
+
25
+ def destroyed?
26
+ !self.reload
27
+ end
28
+
29
+ def save
30
+ data = if new_record?
31
+ requires :topic_id, :user_id, :body
32
+ connection.create_topic_comment(params).body["topic_comment"]
33
+ else
34
+ requires :identity
35
+ connection.update_topic_comment(params).body["topic_comment"]
36
+ end
37
+ merge_attributes(data)
38
+ end
39
+
40
+ private
41
+
42
+ def params
43
+ Cistern::Hash.slice(Zendesk2.stringify_keys(attributes), *PARAMS)
44
+ end
45
+ end
@@ -0,0 +1,12 @@
1
+ class Zendesk2::Client::TopicComments < Cistern::Collection
2
+ include Zendesk2::PagedCollection
3
+ include Zendesk2::Searchable
4
+
5
+ model Zendesk2::Client::TopicComment
6
+
7
+ self.collection_method= :get_topic_comments
8
+ self.collection_root= "topic_comments"
9
+ self.model_method= :get_topic_comment
10
+ self.model_root= "topic_comment"
11
+ self.search_type= "topic_comment"
12
+ end
@@ -0,0 +1,33 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def create_topic_comment(params={})
4
+ request(
5
+ :body => {"topic_comment" => params},
6
+ :method => :post,
7
+ :path => "/topic_comments.json",
8
+ )
9
+ end
10
+ end # Real
11
+
12
+ class Mock
13
+ def create_topic_comment(params={})
14
+ identity = self.class.new_id
15
+
16
+ record = {
17
+ "id" => identity,
18
+ "url" => url_for("/topic_comments/#{identity}.json"),
19
+ "created_at" => Time.now.iso8601,
20
+ "updated_at" => Time.now.iso8601,
21
+ }.merge(params)
22
+
23
+ path = "/topic_comments.json"
24
+ self.data[:topic_comments][identity]= record
25
+
26
+ response(
27
+ :method => :post,
28
+ :body => {"topic_comment" => record},
29
+ :path => path,
30
+ )
31
+ end
32
+ end # Mock
33
+ end
@@ -0,0 +1,28 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def destroy_topic_comment(params={})
4
+ id = params["id"]
5
+
6
+ request(
7
+ :method => :delete,
8
+ :path => "/topic_comments/#{id}.json"
9
+ )
10
+ end
11
+ end
12
+
13
+ class Mock
14
+ def destroy_topic_comment(params={})
15
+ id = params["id"]
16
+ path = "/topic_comments/#{id}.json"
17
+
18
+ body = self.data[:topic_comments].delete(id)
19
+ response(
20
+ :method => :delete,
21
+ :path => path,
22
+ :body => {
23
+ "topic_comment" => body,
24
+ },
25
+ )
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def get_topic_comment(params={})
4
+ id = params["id"]
5
+
6
+ request(
7
+ :method => :get,
8
+ :path => "/topic_comments/#{id}.json"
9
+ )
10
+ end
11
+ end # Real
12
+
13
+ class Mock
14
+ def get_topic_comment(params={})
15
+ id = params["id"]
16
+ body = self.data[:topic_comments][id]
17
+
18
+ response(
19
+ :path => "/topic_comments/#{id}.json",
20
+ :body => {
21
+ "topic_comment" => body
22
+ },
23
+ )
24
+ end
25
+ end # Mock
26
+ end
@@ -0,0 +1,18 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def get_topic_comments(params={})
4
+ page_params = Zendesk2.paging_parameters(params)
5
+
6
+ request(
7
+ :params => page_params,
8
+ :method => :get,
9
+ :path => "/topic_comments.json",
10
+ )
11
+ end
12
+ end
13
+ class Mock
14
+ def get_topic_comments(params={})
15
+ page(params, :topic_comments, "/topic_comments.json", "topic_comments")
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def update_topic_comment(params={})
4
+ id = params.delete("id")
5
+
6
+ request(
7
+ :method => :put,
8
+ :path => "/topic_comments/#{id}.json",
9
+ :body => {
10
+ "topic_comment" => params
11
+ },
12
+ )
13
+ end
14
+ end
15
+ class Mock
16
+ def update_topic_comment(params={})
17
+ id = params.delete("id")
18
+ path = "/topic_comments/#{id}.json"
19
+
20
+ body = self.data[:topic_comments][id].merge!(params)
21
+ response(
22
+ :method => :put,
23
+ :path => path,
24
+ :body => {
25
+ "topic_comment" => body
26
+ },
27
+ )
28
+ end
29
+ end
30
+ end
@@ -9,6 +9,8 @@ class Zendesk2::Client < Cistern::Service
9
9
  collection :forums
10
10
  model :topic
11
11
  collection :topics
12
+ model :topic_comment
13
+ collection :topic_comments
12
14
  model :organization
13
15
  collection :organizations
14
16
  model :ticket
@@ -19,12 +21,14 @@ class Zendesk2::Client < Cistern::Service
19
21
  request :create_category
20
22
  request :create_forum
21
23
  request :create_topic
24
+ request :create_topic_comment
22
25
  request :create_organization
23
26
  request :create_ticket
24
27
  request :create_user
25
28
  request :destroy_category
26
29
  request :destroy_forum
27
30
  request :destroy_topic
31
+ request :destroy_topic_comment
28
32
  request :destroy_organization
29
33
  request :destroy_ticket
30
34
  request :destroy_user
@@ -32,6 +36,7 @@ class Zendesk2::Client < Cistern::Service
32
36
  request :get_category
33
37
  request :get_forum
34
38
  request :get_topic
39
+ request :get_topic_comment
35
40
  request :get_organization
36
41
  request :get_organization_tickets
37
42
  request :get_organization_users
@@ -40,6 +45,7 @@ class Zendesk2::Client < Cistern::Service
40
45
  request :get_categories
41
46
  request :get_forums
42
47
  request :get_topics
48
+ request :get_topic_comments
43
49
  request :get_organizations
44
50
  request :get_requested_tickets
45
51
  request :get_ccd_tickets
@@ -49,6 +55,7 @@ class Zendesk2::Client < Cistern::Service
49
55
  request :update_category
50
56
  request :update_forum
51
57
  request :update_topic
58
+ request :update_topic_comment
52
59
  request :update_organization
53
60
  request :update_ticket
54
61
  request :update_user
@@ -121,12 +128,13 @@ class Zendesk2::Client < Cistern::Service
121
128
 
122
129
  def self.data
123
130
  @data ||= {
124
- :users => {},
125
- :organizations => {},
126
- :tickets => {},
127
- :forums => {},
128
- :topics => {},
129
- :categories => {},
131
+ :users => {},
132
+ :organizations => {},
133
+ :tickets => {},
134
+ :forums => {},
135
+ :topics => {},
136
+ :categories => {},
137
+ :topic_comments => {},
130
138
  }
131
139
  end
132
140
 
@@ -206,8 +214,9 @@ class Zendesk2::Client < Cistern::Service
206
214
  end
207
215
 
208
216
  def pluralize(word)
209
- [[/y$/, 'ies'], [/$/, 's']].find{|regex, replace| word.gsub!(regex, replace) if word.match(regex)}
210
- word
217
+ pluralized = word.dup
218
+ [[/y$/, 'ies'], [/$/, 's']].find{|regex, replace| pluralized.gsub!(regex, replace) if pluralized.match(regex)}
219
+ pluralized
211
220
  end
212
221
 
213
222
  def response(options={})
@@ -1,3 +1,3 @@
1
1
  module Zendesk2
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe "topic_comments" do
4
+ let(:client) { create_client }
5
+ let(:user) { client.users.create(email: "zendesk2+#{Zendesk2.uuid}@example.org", name: Zendesk2.uuid, verified: true) }
6
+ let(:forum) { client.forums.create(name: Zendesk2.uuid) }
7
+ let(:topic) { client.topics.create(title: Zendesk2.uuid, body: Zendesk2.uuid, forum: forum) }
8
+ it_should_behave_like "a resource",
9
+ :topic_comments,
10
+ lambda { {body: Zendesk2.uuid, topic_id: topic.id, user_id: user.id} },
11
+ lambda { {body: Zendesk2.uuid} }
12
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-31 00:00:00.000000000 Z
12
+ date: 2012-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cistern
@@ -101,6 +101,8 @@ files:
101
101
  - lib/zendesk2/client/models/ticket.rb
102
102
  - lib/zendesk2/client/models/tickets.rb
103
103
  - lib/zendesk2/client/models/topic.rb
104
+ - lib/zendesk2/client/models/topic_comment.rb
105
+ - lib/zendesk2/client/models/topic_comments.rb
104
106
  - lib/zendesk2/client/models/topics.rb
105
107
  - lib/zendesk2/client/models/user.rb
106
108
  - lib/zendesk2/client/models/users.rb
@@ -109,12 +111,14 @@ files:
109
111
  - lib/zendesk2/client/requests/create_organization.rb
110
112
  - lib/zendesk2/client/requests/create_ticket.rb
111
113
  - lib/zendesk2/client/requests/create_topic.rb
114
+ - lib/zendesk2/client/requests/create_topic_comment.rb
112
115
  - lib/zendesk2/client/requests/create_user.rb
113
116
  - lib/zendesk2/client/requests/destroy_category.rb
114
117
  - lib/zendesk2/client/requests/destroy_forum.rb
115
118
  - lib/zendesk2/client/requests/destroy_organization.rb
116
119
  - lib/zendesk2/client/requests/destroy_ticket.rb
117
120
  - lib/zendesk2/client/requests/destroy_topic.rb
121
+ - lib/zendesk2/client/requests/destroy_topic_comment.rb
118
122
  - lib/zendesk2/client/requests/destroy_user.rb
119
123
  - lib/zendesk2/client/requests/get_categories.rb
120
124
  - lib/zendesk2/client/requests/get_category.rb
@@ -130,6 +134,8 @@ files:
130
134
  - lib/zendesk2/client/requests/get_ticket.rb
131
135
  - lib/zendesk2/client/requests/get_tickets.rb
132
136
  - lib/zendesk2/client/requests/get_topic.rb
137
+ - lib/zendesk2/client/requests/get_topic_comment.rb
138
+ - lib/zendesk2/client/requests/get_topic_comments.rb
133
139
  - lib/zendesk2/client/requests/get_topics.rb
134
140
  - lib/zendesk2/client/requests/get_user.rb
135
141
  - lib/zendesk2/client/requests/get_users.rb
@@ -139,6 +145,7 @@ files:
139
145
  - lib/zendesk2/client/requests/update_organization.rb
140
146
  - lib/zendesk2/client/requests/update_ticket.rb
141
147
  - lib/zendesk2/client/requests/update_topic.rb
148
+ - lib/zendesk2/client/requests/update_topic_comment.rb
142
149
  - lib/zendesk2/client/requests/update_user.rb
143
150
  - lib/zendesk2/error.rb
144
151
  - lib/zendesk2/logger.rb
@@ -152,6 +159,7 @@ files:
152
159
  - spec/spec_helper.rb
153
160
  - spec/support/client_helper.rb
154
161
  - spec/tickets_spec.rb
162
+ - spec/topic_comments_spec.rb
155
163
  - spec/topics_spec.rb
156
164
  - spec/users_spec.rb
157
165
  - zendesk2.gemspec
@@ -187,6 +195,7 @@ test_files:
187
195
  - spec/spec_helper.rb
188
196
  - spec/support/client_helper.rb
189
197
  - spec/tickets_spec.rb
198
+ - spec/topic_comments_spec.rb
190
199
  - spec/topics_spec.rb
191
200
  - spec/users_spec.rb
192
201
  has_rdoc: