zensana 1.6.2 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -2
- data/lib/zensana.rb +1 -0
- data/lib/zensana/commands/view.rb +15 -7
- data/lib/zensana/helpers.rb +55 -0
- data/lib/zensana/models/zendesk/view.rb +11 -2
- data/lib/zensana/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26228bf1614321af4ecf3045084e0fdf3970fba6
|
4
|
+
data.tar.gz: 39b1f80fc6b4fe3323fd3711d6ae550d6ac65fb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 092da1a5c00e8d1e8c4f80f76d6928883649bfd7ea2a5b62ebd49ebfaedc5e566f7b347a317150752354b2ae670f47d6c17ee418aa14e694d0b705a6b6cf60b0
|
7
|
+
data.tar.gz: 8c89f95b12f3df61e704f90a5d5d0c3eeb26cb1a931797f703298c2960e2c88780d3823fa956b6685d75386a8624d8b29858e7aacec6c033bad2e598910def8e
|
data/README.md
CHANGED
@@ -52,9 +52,12 @@ There is one command for Zendesk groups:
|
|
52
52
|
#### view command
|
53
53
|
|
54
54
|
There is one command to generate an export of Zendesk tickets from a
|
55
|
-
defined view
|
55
|
+
defined view. Pass in a specific view number or select from the list of
|
56
|
+
all views available to you:
|
56
57
|
|
57
|
-
zensana view export
|
58
|
+
zensana view export # Export Zendesk View using the predetermined fields
|
59
|
+
Options:
|
60
|
+
-v, [--view=VIEW] # specific view number to export
|
58
61
|
|
59
62
|
The csv will contain the following fields:
|
60
63
|
|
data/lib/zensana.rb
CHANGED
@@ -2,20 +2,28 @@ require 'csv'
|
|
2
2
|
|
3
3
|
module Zensana
|
4
4
|
class Command::View < Zensana::Command
|
5
|
+
include Zensana::Helpers
|
5
6
|
|
6
|
-
desc 'export
|
7
|
-
|
7
|
+
desc 'export', 'Export Zendesk View using the predetermined fields'
|
8
|
+
option :view, type: 'string', aliases: '-v', default: nil, desc: 'specific view number to export'
|
9
|
+
def export
|
8
10
|
view = Zensana::Zendesk::View.new
|
9
|
-
view.find(id)
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
if view_id = options[:view]
|
13
|
+
view.find(view_id)
|
14
|
+
unless yes?("\nThis will export the tickets in the Zendesk View called '#{view.title}' as a CSV. Proceed?", :yellow)
|
15
|
+
say EXIT_SELECTION_MSG, :red
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
else
|
19
|
+
views = view.list.map { |v| { :key => v['id'], :value => v['title'] } }.sort_by { |i| i[:value] }
|
20
|
+
view_id = ask_which_item(views, "\nChoose the Zendesk View you wish to export", :single).first
|
21
|
+
view.find(view_id)
|
14
22
|
end
|
15
23
|
|
16
24
|
tickets = view.tickets
|
17
25
|
|
18
|
-
csv_file = "zendesk_export_view_#{
|
26
|
+
csv_file = "zendesk_export_view_#{view_id}_#{Time.now.strftime('%Y_%m_%d_%H%M')}.csv"
|
19
27
|
Dir.chdir file_dir = File.join(Dir.home, 'Downloads')
|
20
28
|
|
21
29
|
CSV.open(csv_file, 'w') do |output|
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Zensana
|
2
|
+
module Helpers
|
3
|
+
|
4
|
+
INVALID_SELECTION_MSG = "\n --> That's not a valid selection, I'm out of here!\n\n"
|
5
|
+
EXIT_SELECTION_MSG = "\n --> OK, nothing else for me to do here!\n\n"
|
6
|
+
|
7
|
+
# provide a list of choices to the user and ask them to select one or more
|
8
|
+
# list is an array of hashes like this:
|
9
|
+
# {
|
10
|
+
# :key => 'value to be returned if selected',
|
11
|
+
# :value'=> 'value to be displayed as choice'
|
12
|
+
# }
|
13
|
+
def ask_which_item(items, prompt, mode=:single)
|
14
|
+
return Array(get_hash(items.first, :key)) if items.size == 1
|
15
|
+
str_format = "\n %#{items.count.to_s.size}s: %s"
|
16
|
+
prompt << "\n > Enter a single selection, "
|
17
|
+
prompt << "multiple selections separated by ',', 'A' for all, " if mode == :multiple
|
18
|
+
prompt << "'Q' or nothing to quit"
|
19
|
+
question = set_color prompt, :yellow
|
20
|
+
answers = {}
|
21
|
+
|
22
|
+
items.each_with_index do |item, index|
|
23
|
+
i = (index + 1).to_s
|
24
|
+
answers[i] = get_hash(item, :key)
|
25
|
+
question << format(str_format, i, get_hash(item, :value))
|
26
|
+
end
|
27
|
+
|
28
|
+
say question
|
29
|
+
reply = ask(" >", :yellow).to_s
|
30
|
+
replies = reply.split(',')
|
31
|
+
if reply.empty? || reply.upcase == 'Q'
|
32
|
+
say EXIT_SELECTION_MSG, :green
|
33
|
+
exit 0
|
34
|
+
elsif answers[reply]
|
35
|
+
answers.values_at(reply)
|
36
|
+
elsif mode == :single
|
37
|
+
say INVALID_SELECTION_MSG, :red
|
38
|
+
exit 1
|
39
|
+
elsif mode == :multiple && reply.upcase == 'A'
|
40
|
+
answers.values
|
41
|
+
elsif mode == :multiple && !replies.empty?
|
42
|
+
selected_items = answers.values_at(*replies)
|
43
|
+
if selected_items.include?(nil)
|
44
|
+
say INVALID_SELECTION_MSG, :red
|
45
|
+
exit 1
|
46
|
+
end
|
47
|
+
selected_items
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_hash(hash, key)
|
52
|
+
hash[key.to_sym] || hash [key.to_s]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -11,8 +11,12 @@ module Zensana
|
|
11
11
|
@attributes = {}
|
12
12
|
end
|
13
13
|
|
14
|
+
def list(active_only = true)
|
15
|
+
fetch_list(active_only)
|
16
|
+
end
|
17
|
+
|
14
18
|
def find(id)
|
15
|
-
@attributes =
|
19
|
+
@attributes = fetch_view(id)
|
16
20
|
end
|
17
21
|
|
18
22
|
def tickets
|
@@ -30,10 +34,15 @@ module Zensana
|
|
30
34
|
|
31
35
|
private
|
32
36
|
|
33
|
-
def
|
37
|
+
def fetch_view(id)
|
34
38
|
zendesk_service.fetch("/views/#{id}.json")['view']
|
35
39
|
end
|
36
40
|
|
41
|
+
def fetch_list(active_only=true)
|
42
|
+
url = active_only ? "/views/active.json/" : "/views.json"
|
43
|
+
zendesk_service.fetch(url)['views']
|
44
|
+
end
|
45
|
+
|
37
46
|
def get_tickets(id)
|
38
47
|
zendesk_service.fetch("/views/#{id}/tickets.json")['tickets']
|
39
48
|
end
|
data/lib/zensana/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zensana
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Warren Bain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- lib/zensana/commands/group.rb
|
147
147
|
- lib/zensana/commands/project.rb
|
148
148
|
- lib/zensana/commands/view.rb
|
149
|
+
- lib/zensana/helpers.rb
|
149
150
|
- lib/zensana/models/asana/attachment.rb
|
150
151
|
- lib/zensana/models/asana/project.rb
|
151
152
|
- lib/zensana/models/asana/task.rb
|