lita-zendesk 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c98df925470543243c15a83d4fdcfb992700608
4
- data.tar.gz: 5e6e5433eb861b713218f3d484baa41850bd0848
3
+ metadata.gz: 0ed3bd3957808a547668213958374125fed8ebe9
4
+ data.tar.gz: 9126e0044a74c67b1c20a9d8c5bc79f6a16c0735
5
5
  SHA512:
6
- metadata.gz: e63a6e6268461a45dc92601236f85db370df275e52fde5c1f418f3513835598e7a73052d81900555c663b26cf4db412b43460b43ce30e8062db8c595054378a5
7
- data.tar.gz: 76230b57b6a39cb7a72c3f911a4fda96bb3040eba1589d3d5911d3d829f266c825568f410d1d4971d3c8a91ea7cbcd21f7c6df1115d483f1ce449b619dde403b
6
+ metadata.gz: c6624b406255735ca9e35fb5e5ec8c7e908f1b96c421867b75970b26500407949ee668c4158744215596cba0fdcc0a5ec24c47cd66ce321cb0fbd21b3b924ba3
7
+ data.tar.gz: 06e78b27d1ee692b105de17f597909031676a2d657242581803ff160b86f29f1dde2c6058ff7426c1519401db33a1f8e4c86db349c8d393c18f269a8c1135f7d
@@ -1,4 +1,8 @@
1
1
  CHANGELOG
2
2
  ---------
3
- - **2016-08-30**: 0.0.1
3
+ - **0.0.5** - 2016-08-31
4
+ - Add free form ticket search
5
+ - **0.0.2-0.0.4** - 2015-08-30 - 31
6
+ - Various bugfixes
7
+ - **0.0.1** - 2016-08-30
4
8
  - Initial commit
data/README.md CHANGED
@@ -44,6 +44,8 @@ end
44
44
 
45
45
  ```
46
46
  Lita > @lita help
47
+ Lita: zd connection - returns information on the Zendesk connection
48
+ Lita: zd search tickets <QUERY> - returns search results
47
49
  Lita: zd tickets - returns the total count of all unsolved tickets
48
50
  Lita: zd all tickets - returns the count of all tickets
49
51
  Lita: zd pending tickets - returns a count of tickets that are pending
@@ -75,7 +77,11 @@ Lita
75
77
 
76
78
  * https://www.lita.io/
77
79
 
78
- Ported and adapted from `hubot-scripts/zendesk.coffee`:
80
+ Zendesk Search API
81
+
82
+ * https://developer.zendesk.com/rest_api/docs/core/search
83
+
84
+ Ported and enhanced from `hubot-scripts/zendesk.coffee`:
79
85
 
80
86
  * https://github.com/github/hubot-scripts/blob/master/src/scripts/zendesk.coffee
81
87
 
@@ -8,6 +8,8 @@ module Lita
8
8
  is_command = false
9
9
 
10
10
  VERSION_URL = 'api/v2'
11
+ QUERY_SEARCH_PREFIX = 'search.json?query='
12
+ QUERY_TICKETS_SEARCH = 'search.json?query=type:ticket '
11
13
  QUERY_TICKETS_ALL = 'tickets'
12
14
  QUERY_TICKETS_ESCALATED = 'search.json?query=tags:escalated+status:open+status:pending+type:ticket'
13
15
  QUERY_TICKETS_HOLD = 'search.json?query=status:hold+type:ticket'
@@ -23,7 +25,8 @@ module Lita
23
25
  config :token, type: String, default: ''
24
26
  config :password, type: String, default: ''
25
27
 
26
- def init
28
+ def check_client(reload = false)
29
+ return if @conn && !reload
27
30
  @base_url = base_url
28
31
  @version_url = "#{@base_url}/#{VERSION_URL}"
29
32
  @tickets_url = "#{@base_url}/tickets"
@@ -54,45 +57,25 @@ module Lita
54
57
  end
55
58
 
56
59
  def zendesk_request(url)
57
- init unless @conn
60
+ check_client
58
61
  if url.index('http') != 0
59
62
  url = "#{@version_url}/#{url}"
60
63
  end
61
64
  @conn.get url
62
65
  end
63
66
 
64
- def ticket_count(response, url, ticket_type = '')
65
- res = zendesk_request url
66
- ticket_count = res.body['count']
67
- ticket_word = ticket_count == 1 ? 'ticket' : 'tickets'
68
- ticket_desc = ticket_type == '' ? '' : "#{ticket_type} "
69
- response.reply "#{ticket_count} #{ticket_desc}#{ticket_word}."
70
- end
71
-
72
- def ticket_list(response, url, ticket_type = '')
73
- res = zendesk_request url
74
- tickets = res.body['results']
75
- tickets.each do |ticket|
76
- response.reply "Ticket #{ticket['id']} is #{ticket['status']}: #{@tickets_url}/#{ticket['id']} - #{ticket['subject']}"
77
- end
78
- ticket_length = tickets.length
79
- ticket_count = res.body['count']
80
- ticket_word = ticket_count == 1 ? 'ticket' : 'tickets'
81
- ticket_desc = ticket_type == '' ? '' : "#{ticket_type} "
82
- response.reply "Listing #{ticket_length} of #{ticket_count} #{ticket_desc}#{ticket_word}."
83
- end
84
-
85
- def tickets(count)
86
- count == 1 ? 'ticket' : 'tickets'
87
- end
88
-
89
- # Info
67
+ # General
90
68
 
91
69
  route(/^(?:zd|zendesk)\s+connection\s*$/, :zd_instance_info, command: true, help: { 'zd connection' => 'returns information on the Zendesk connection' })
92
70
  def zd_instance_info(response)
93
71
  response.reply "Using Zendesk instance at: #{base_url}"
94
72
  end
95
73
 
74
+ route(/^(?:zd|zendesk)\s+search\s+tickets?\s+(\S.*?)\s*$/, :search_tickets, command: true, help: { 'zd search tickets <QUERY>' => 'returns search results' })
75
+ def search_tickets(response)
76
+ ticket_search response, QUERY_TICKETS_SEARCH, response.matches[0][0]
77
+ end
78
+
96
79
  # Ticket Counts
97
80
 
98
81
  route(/^(?:zd|zendesk)(\s+unsolved)?\s+tickets?\s*$/, :unsolved_tickets, command: true, help: { 'zd tickets' => 'returns the total count of all unsolved tickets' })
@@ -184,6 +167,46 @@ module Lita
184
167
  message += "\nDescription:\n-----\n#{data['ticket']['description']}\n-----\n"
185
168
  response.reply message
186
169
  end
170
+
171
+ private
172
+
173
+ def ticket_count(response, url, ticket_type = '')
174
+ res = zendesk_request url
175
+ ticket_count = res.body['count']
176
+ ticket_word = ticket_count == 1 ? 'ticket' : 'tickets'
177
+ ticket_desc = ticket_type == '' ? '' : "#{ticket_type} "
178
+ response.reply "#{ticket_count} #{ticket_desc}#{ticket_word}."
179
+ end
180
+
181
+ def ticket_search(response, url, query)
182
+ url += query
183
+ res = zendesk_request url
184
+ tickets = res.body['results']
185
+ tickets.each do |ticket|
186
+ response.reply "Ticket #{ticket['id']} is #{ticket['status']}: #{@tickets_url}/#{ticket['id']} - #{ticket['subject']}"
187
+ end
188
+ ticket_length = tickets.length
189
+ ticket_count = res.body['count']
190
+ ticket_word = ticket_count == 1 ? 'result' : 'results'
191
+ response.reply "Listing #{ticket_length} of #{ticket_count} matching #{ticket_word}."
192
+ end
193
+
194
+ def ticket_list(response, url, ticket_type = '')
195
+ res = zendesk_request url
196
+ tickets = res.body['results']
197
+ tickets.each do |ticket|
198
+ response.reply "Ticket #{ticket['id']} is #{ticket['status']}: #{@tickets_url}/#{ticket['id']} - #{ticket['subject']}"
199
+ end
200
+ ticket_length = tickets.length
201
+ ticket_count = res.body['count']
202
+ ticket_word = ticket_count == 1 ? 'ticket' : 'tickets'
203
+ ticket_desc = ticket_type == '' ? '' : "#{ticket_type} "
204
+ response.reply "Listing #{ticket_length} of #{ticket_count} #{ticket_desc}#{ticket_word}."
205
+ end
206
+
207
+ def tickets(count)
208
+ count == 1 ? 'ticket' : 'tickets'
209
+ end
187
210
  end
188
211
 
189
212
  Lita.register_handler(Zendesk)
@@ -1,9 +1,9 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-zendesk'
3
3
  spec.date = '2016-08-31'
4
- spec.version = '0.0.4'
4
+ spec.version = '0.0.5'
5
5
  spec.authors = ['John Wang']
6
- spec.email = ["johncwang@gmail.com"]
6
+ spec.email = ['johncwang@gmail.com']
7
7
  spec.description = %q{A Zendesk handler for Lita.}
8
8
  spec.summary = %q{A Zendesk handler for the Lita chatbot.}
9
9
  spec.homepage = 'https://github.com/grokify/lita-zendesk'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-zendesk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Wang