zensana 1.5.0 → 1.6.1

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: e97fa7d7b90bac8416207fa5ac106977a9b9d740
4
- data.tar.gz: f2e42a59aa59a9c59816e9e019ea300b21949f2c
3
+ metadata.gz: ca7b816a078aa4ca6fd657274c90bd8f3432786d
4
+ data.tar.gz: 906f8a914989097f2a8df7a7fc1ed167c2f74bec
5
5
  SHA512:
6
- metadata.gz: 8b8fe064dbcb2448348314366fec7874144b42f20ee5f4acf123263a813998026ffa60ca2aea628461567c48f3c7544adf274d6ff03cffae509bec7e58f9984e
7
- data.tar.gz: b0ce73be4a761d0d615ef3aaba765bf60b2a605ab9f4818f989a91c45ea04989779f6aa33ce07b8abb0dd33764cb6656b927a3388614a2cf3841affdf5aa4740
6
+ metadata.gz: 661690811595db9a3bef831e27d4581612106d87ade5016403d95efcbf5fc831464fcafe4f980fb813df1caacc91f50eb660afed0404a75b536cdc0ad9d0226c
7
+ data.tar.gz: 3877e4bc6521204e86682c2874d867c2e13658b39b876e27bb0468a8a2886056ffa10a70b3250adb364f7447faac584b6cca5a5f1779fe7cc1b3314919401603
data/README.md CHANGED
@@ -38,8 +38,28 @@ The help is pretty self-explanatory around the options so just try that
38
38
 
39
39
  $ zensana help
40
40
  Commands:
41
+ zensana group SUBCOMMAND # perform actions on ZenDesk agent groups
41
42
  zensana help [COMMAND] # Describe available commands or one specific command
42
43
  zensana project SUBCOMMAND # perform actions on Asana projects
44
+ zensana view SUBCOMMAND # perform actions on ZenDesk views
45
+
46
+ #### group command
47
+
48
+ There is one command for Zendesk groups:
49
+
50
+ zensana group find GROUP # List ZenDesk agent groups that match GROUP (by ID or NAME, regexp accepted)
51
+
52
+ #### view command
53
+
54
+ There is one command to generate an export of Zendesk tickets from a
55
+ defined view (provide its id):
56
+
57
+ zensana view export VIEW # Export Zendesk VIEW using the predetermined fields
58
+
59
+ The csv will contain the following fields:
60
+
61
+ Id, Status, Subject, Component, Description,
62
+ Requester, RequestDate, SolvedDate, Duration
43
63
 
44
64
  #### project command
45
65
 
@@ -67,7 +87,7 @@ control what gets converted.
67
87
 
68
88
  Convert PROJECT tasks to ZenDesk tickets (exact ID or NAME required)
69
89
 
70
- #### idempotentcy
90
+ ##### idempotentcy
71
91
 
72
92
  To ensure robustness of the conversion, especially given that internet
73
93
  connection issues may interrupt it, the project conversion is idempotent
data/lib/zensana/cli.rb CHANGED
@@ -7,5 +7,8 @@ module Zensana
7
7
  desc 'group SUBCOMMAND', 'perform actions on ZenDesk agent groups'
8
8
  subcommand 'group', Group
9
9
 
10
+ desc 'view SUBCOMMAND', 'perform actions on ZenDesk views'
11
+ subcommand 'view', View
12
+
10
13
  end
11
14
  end
@@ -0,0 +1,90 @@
1
+ require 'csv'
2
+ require 'pry'
3
+
4
+ module Zensana
5
+ class Command::View < Zensana::Command
6
+
7
+ desc 'export VIEW', 'Export Zendesk VIEW using the predetermined fields'
8
+ def export(id)
9
+ view = Zensana::Zendesk::View.new
10
+ view.find(id)
11
+
12
+ unless yes?("This will export the tickets in the view called '#{view.title}' as a CSV. Proceed?", :yellow)
13
+ say "\nNothing else for me to do, exiting...\n", :red
14
+ exit
15
+ end
16
+
17
+ tickets = view.tickets
18
+
19
+ csv_file = "zendesk_export_view_#{id}_#{Time.now.strftime('%Y_%m_%d_%H%M')}.csv"
20
+ Dir.chdir file_dir = File.join(Dir.home, 'Downloads')
21
+
22
+ CSV.open(csv_file, 'w') do |output|
23
+ output << %w(Id Status Subject Component Description Requester RequestDate SolvedDate Duration)
24
+ tickets.each do |ticket|
25
+ output.puts transform_ticket(ticket)
26
+ end
27
+ end
28
+
29
+ say "\nYour view has been successfully exported to '#{File.join(file_dir, csv_file)}'", :green
30
+ end
31
+
32
+ private
33
+
34
+ # create an array of fields matching the csv header
35
+ def transform_ticket(ticket)
36
+ fields = []
37
+ fields << ticket['id']
38
+ fields << ticket['status']
39
+ fields << ticket['subject']
40
+ fields << get_component(ticket['custom_fields'])
41
+ fields << clean_text(ticket['description'], 5)
42
+ fields << get_user_name(ticket['requester_id'])
43
+ created = Date.parse(ticket['created_at'])
44
+ updated = Date.parse(ticket['updated_at'])
45
+ fields << created.to_s
46
+ fields << updated.to_s
47
+ fields << (updated - created).to_i
48
+ end
49
+
50
+ def get_user_name(id)
51
+ user = Zendesk::User.new.find(id)
52
+ user['name'] || user['email']
53
+ end
54
+
55
+ def get_component(fields)
56
+ get_custom_field(fields, '24375555').split('_').last
57
+ end
58
+
59
+ def get_custom_field(fields, id)
60
+ fields.each do |field|
61
+ return field['value'] if field['id'].to_s == id.to_s
62
+ end
63
+ end
64
+
65
+ def clean_text(text, max_lines)
66
+ ''.tap do |result|
67
+ text.split("\n").each do |line|
68
+ next if line.empty? || ignore_line?(line)
69
+ result << line << ' '
70
+ break if (max_lines -= 1).zero?
71
+ end
72
+ end
73
+ end
74
+
75
+ def ignore_line?(line)
76
+ ignore_list.inject(false) do |result, matcher|
77
+ result || line.include?(matcher)
78
+ end
79
+ end
80
+
81
+ def ignore_list
82
+ [
83
+ 'Original Message', 'From:', 'Sent:',
84
+ 'To:', 'Cc:', 'Subject:',
85
+ '---', '___', 'Hi ', 'Hi,'
86
+ ]
87
+ end
88
+
89
+ end
90
+ end
@@ -0,0 +1,42 @@
1
+ require 'json'
2
+
3
+ module Zensana
4
+ class Zendesk
5
+ class View
6
+ include Zensana::Zendesk::Access
7
+
8
+ attr_reader :attributes
9
+
10
+ def initialize
11
+ @attributes = {}
12
+ end
13
+
14
+ def find(id)
15
+ @attributes = fetch(id)
16
+ end
17
+
18
+ def tickets
19
+ raise NotFound, "You must fetch the view first!" unless self.id
20
+ get_tickets self.id
21
+ end
22
+
23
+ def id
24
+ attributes['id']
25
+ end
26
+
27
+ def method_missing(name, *args, &block)
28
+ attributes[name.to_s] || super
29
+ end
30
+
31
+ private
32
+
33
+ def fetch(id)
34
+ zendesk_service.fetch("/views/#{id}.json")['view']
35
+ end
36
+
37
+ def get_tickets(id)
38
+ zendesk_service.fetch("/views/#{id}/tickets.json")['tickets']
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module Zensana
2
- VERSION = "1.5.0"
2
+ VERSION = "1.6.1"
3
3
  end
data/lib/zensana.rb CHANGED
@@ -11,15 +11,18 @@ require 'zensana/models/asana/attachment'
11
11
  require 'zensana/models/asana/project'
12
12
  require 'zensana/models/asana/task'
13
13
  require 'zensana/models/asana/user'
14
+
14
15
  require 'zensana/models/zendesk/attachment'
15
16
  require 'zensana/models/zendesk/comment'
16
17
  require 'zensana/models/zendesk/group'
17
18
  require 'zensana/models/zendesk/ticket'
18
19
  require 'zensana/models/zendesk/user'
20
+ require 'zensana/models/zendesk/view'
19
21
 
20
22
  require 'zensana/command'
21
23
  require 'zensana/commands/group'
22
24
  require 'zensana/commands/project'
25
+ require 'zensana/commands/view'
23
26
  require 'zensana/cli'
24
27
 
25
28
  module Zensana
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.5.0
4
+ version: 1.6.1
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-06-09 00:00:00.000000000 Z
11
+ date: 2015-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -145,6 +145,7 @@ files:
145
145
  - lib/zensana/command.rb
146
146
  - lib/zensana/commands/group.rb
147
147
  - lib/zensana/commands/project.rb
148
+ - lib/zensana/commands/view.rb
148
149
  - lib/zensana/models/asana/attachment.rb
149
150
  - lib/zensana/models/asana/project.rb
150
151
  - lib/zensana/models/asana/task.rb
@@ -154,6 +155,7 @@ files:
154
155
  - lib/zensana/models/zendesk/group.rb
155
156
  - lib/zensana/models/zendesk/ticket.rb
156
157
  - lib/zensana/models/zendesk/user.rb
158
+ - lib/zensana/models/zendesk/view.rb
157
159
  - lib/zensana/services/asana.rb
158
160
  - lib/zensana/services/error.rb
159
161
  - lib/zensana/services/response.rb