zendesk-tools 0.0.6 → 0.0.7

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: b12ae0f5184332c0c4e6e81809487bac6ce34b3a
4
- data.tar.gz: ddc6a390e7cf8cb76b4b14e0765b3598500d7445
3
+ metadata.gz: a1c809bf314ac68b5cd817992131485d4df02194
4
+ data.tar.gz: 16e2a802ac9cd969714f5eb2767cd9b4e7fe4f0a
5
5
  SHA512:
6
- metadata.gz: 16634d6ab6fb1260861627bb68d0274e639e3cd6e961cbe7867cadc2673b1a5a7ea444c28c2fcdfd92cfaf44e966a8707771962d4d2c0d449cb9876bd872ca9c
7
- data.tar.gz: bcc4fda7f8821c554ad5bfbffdb925e8045fbdea79ee58bc934e957c45ef394c126cc660c2136e0a6d407303785c0cc731a489000b4a17a648761d0d15ec3bb5
6
+ metadata.gz: 81753d360a0bac0b62a095508ed381e7f5f987bde0de365d7cc053f7cb5f99ab6b01e33e801968a53fd81a22279cc835e3838c9975476a43598aa2c6411c9bec
7
+ data.tar.gz: 8ba4302d4d8f5c7976fd81e2c373dc52d20d5b096b990e86175634f2696274b4dc0656bb44790799633186f226dd696297d96823620f16c7a931b3023b83050f
@@ -18,45 +18,83 @@ module ZendeskTools
18
18
  end
19
19
 
20
20
  def run
21
- @client.suspended_tickets.each do |suspended_ticket|
22
- if should_recover?(suspended_ticket)
23
- log.info "Recovering: #{suspended_ticket.subject}"
21
+ @client.suspended_tickets.each { |suspended_ticket| process_ticket(suspended_ticket) }
22
+ end
23
+
24
+ private
24
25
 
26
+ def process_ticket(suspended_ticket)
27
+ if should_recover?(suspended_ticket)
28
+ subject = suspended_ticket.subject
29
+ user_id = get_user_id(suspended_ticket)
30
+ content = suspended_ticket.content
31
+
32
+ log.info "Recovering: #{subject}"
33
+
34
+ # If there is no ticketID, we need to create a new ticket. Otherwise we update with new comment.
35
+ if suspended_ticket.ticket_id.nil?
36
+ ticket = create_ticket(user_id, content, subject)
37
+ else
25
38
  ticket_id = suspended_ticket.ticket_id
26
- author_id = suspended_ticket.author.id
27
- content = suspended_ticket.content
39
+ ticket = update_ticket(user_id, content, ticket_id)
40
+ end
28
41
 
29
- # * Create new comment with correct author and content
30
- ticket = @client.tickets.find(:id => ticket_id)
31
- ticket.comment = ZendeskAPI::Ticket::Comment.new(@client, :value => content, :author_id => author_id)
42
+ # * Check for attachments and upload it to comment if it exists
43
+ suspended_ticket.attachments.each do |attachment|
44
+ url = attachment.fetch('content_url')
45
+ name = attachment.fetch('file_name')
46
+ path = File.join(@tmpdir, name)
32
47
 
33
- # * Check for attachments and upload it to comment if it exists
34
- suspended_ticket.attachments.each do |attachment|
35
- url = attachment.fetch('content_url')
36
- name = attachment.fetch('file_name')
37
- path = File.join(@tmpdir, name)
48
+ log.info "downloading #{url}"
38
49
 
39
- log.info "downloading #{url}"
50
+ File.open(path, 'wb') { |file| download(url, file) }
51
+ ticket.comment.uploads << path
52
+ end
40
53
 
41
- File.open(path, 'wb') { |file| download(url, file) }
42
- ticket.comment.uploads << path
43
- end
54
+ # * Save comment and upload it to zendesk.
55
+ log.info "uploading"
56
+ ticket.save
44
57
 
45
- # * Save comment and upload it to zendesk
46
- log.info "uploading"
47
- ticket.save
58
+ # * delete/destroy the recovered ticket
59
+ suspended_ticket.destroy
60
+ log.info "cleaning up"
61
+ FileUtils.rm_rf @tmpdir
62
+ else
63
+ log.info "Not recovering: #{suspended_ticket.subject}"
64
+ end
65
+ end
48
66
 
49
- # * delete/destroy the recovered ticket
50
- suspended_ticket.destroy
51
- log.info "cleaning up"
52
- FileUtils.rm_rf @tmpdir
53
- else
54
- log.info "Not recovering: #{suspended_ticket.subject}"
55
- end
67
+ def should_recover?(suspended_ticket)
68
+ cause = suspended_ticket.cause
69
+
70
+ @recover_causes.any? { |recover_cause| cause.include?(recover_cause) }
71
+ end
72
+
73
+ def get_user_id(suspended_ticket)
74
+ if suspended_ticket.author.id.nil?
75
+ user_id = @client.users.search(:query => suspended_ticket.author.email).first.id
76
+ else
77
+ user_id = suspended_ticket.author.id
56
78
  end
79
+ user_id
57
80
  end
58
81
 
59
- private
82
+ def create_ticket(user_id, content, subject)
83
+ # Create a new ticket with info from suspended ticket
84
+ @client.tickets.create(
85
+ :subject => subject,
86
+ :comment => { :value => content, :author_id => user_id },
87
+ :submitter_id => user_id,
88
+ :requester_id => user_id
89
+ )
90
+ end
91
+
92
+ def update_ticket(user_id, content, ticket_id)
93
+ # * Update ticket with info from suspended ticket
94
+ ticket = @client.tickets.find(:id => ticket_id)
95
+ ticket.comment = ZendeskAPI::Ticket::Comment.new(@client, :value => content, :author_id => user_id)
96
+ ticket
97
+ end
60
98
 
61
99
  def download(url, destination)
62
100
  uri = URI.parse(url)
@@ -85,12 +123,6 @@ module ZendeskTools
85
123
  raise "ERROR:#{resp.code} for #{url}"
86
124
  end
87
125
  end
88
-
89
- def should_recover?(suspended_ticket)
90
- cause = suspended_ticket.cause
91
- subject = suspended_ticket.subject
92
-
93
- @recover_causes.any? { |recover_cause| cause.include?(recover_cause) }
94
- end
126
+
95
127
  end
96
- end
128
+ end
@@ -1,3 +1,3 @@
1
1
  module ZendeskTools
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -6,8 +6,8 @@ require 'zendesk-tools/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "zendesk-tools"
8
8
  gem.version = ZendeskTools::VERSION
9
- gem.authors = ["Jari Bakken", "Eivind Throndsen"]
10
- gem.email = ["jari@finn.no", "eivind.throndsen@finn.no"]
9
+ gem.authors = ["Jari Bakken", "Eivind Throndsen", "Ole Andreas Sandring"]
10
+ gem.email = ["jari@finn.no", "eivind.throndsen@finn.no", "oas@finn.no"]
11
11
  gem.description = %q{Tools for FINNs ZenDesk}
12
12
  gem.summary = %q{Tools for FINNs ZenDesk}
13
13
  gem.homepage = "https://github.com/finn-no/zendesk-tools"
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency "zendesk_api", "~> 1.3.0"
20
+ gem.add_dependency "zendesk_api", "~> 1.3"
21
21
  gem.add_dependency "json"
22
22
  gem.add_dependency "rake"
23
23
  gem.add_dependency "geminabox"
metadata CHANGED
@@ -1,111 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jari Bakken
8
8
  - Eivind Throndsen
9
+ - Ole Andreas Sandring
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2014-06-18 00:00:00.000000000 Z
13
+ date: 2014-07-01 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: zendesk_api
16
17
  requirement: !ruby/object:Gem::Requirement
17
18
  requirements:
18
- - - ~>
19
+ - - "~>"
19
20
  - !ruby/object:Gem::Version
20
- version: 1.3.0
21
+ version: '1.3'
21
22
  type: :runtime
22
23
  prerelease: false
23
24
  version_requirements: !ruby/object:Gem::Requirement
24
25
  requirements:
25
- - - ~>
26
+ - - "~>"
26
27
  - !ruby/object:Gem::Version
27
- version: 1.3.0
28
+ version: '1.3'
28
29
  - !ruby/object:Gem::Dependency
29
30
  name: json
30
31
  requirement: !ruby/object:Gem::Requirement
31
32
  requirements:
32
- - - '>='
33
+ - - ">="
33
34
  - !ruby/object:Gem::Version
34
35
  version: '0'
35
36
  type: :runtime
36
37
  prerelease: false
37
38
  version_requirements: !ruby/object:Gem::Requirement
38
39
  requirements:
39
- - - '>='
40
+ - - ">="
40
41
  - !ruby/object:Gem::Version
41
42
  version: '0'
42
43
  - !ruby/object:Gem::Dependency
43
44
  name: rake
44
45
  requirement: !ruby/object:Gem::Requirement
45
46
  requirements:
46
- - - '>='
47
+ - - ">="
47
48
  - !ruby/object:Gem::Version
48
49
  version: '0'
49
50
  type: :runtime
50
51
  prerelease: false
51
52
  version_requirements: !ruby/object:Gem::Requirement
52
53
  requirements:
53
- - - '>='
54
+ - - ">="
54
55
  - !ruby/object:Gem::Version
55
56
  version: '0'
56
57
  - !ruby/object:Gem::Dependency
57
58
  name: geminabox
58
59
  requirement: !ruby/object:Gem::Requirement
59
60
  requirements:
60
- - - '>='
61
+ - - ">="
61
62
  - !ruby/object:Gem::Version
62
63
  version: '0'
63
64
  type: :runtime
64
65
  prerelease: false
65
66
  version_requirements: !ruby/object:Gem::Requirement
66
67
  requirements:
67
- - - '>='
68
+ - - ">="
68
69
  - !ruby/object:Gem::Version
69
70
  version: '0'
70
71
  - !ruby/object:Gem::Dependency
71
72
  name: log4r
72
73
  requirement: !ruby/object:Gem::Requirement
73
74
  requirements:
74
- - - '>='
75
+ - - ">="
75
76
  - !ruby/object:Gem::Version
76
77
  version: '0'
77
78
  type: :runtime
78
79
  prerelease: false
79
80
  version_requirements: !ruby/object:Gem::Requirement
80
81
  requirements:
81
- - - '>='
82
+ - - ">="
82
83
  - !ruby/object:Gem::Version
83
84
  version: '0'
84
85
  - !ruby/object:Gem::Dependency
85
86
  name: pry
86
87
  requirement: !ruby/object:Gem::Requirement
87
88
  requirements:
88
- - - '>='
89
+ - - ">="
89
90
  - !ruby/object:Gem::Version
90
91
  version: '0'
91
92
  type: :development
92
93
  prerelease: false
93
94
  version_requirements: !ruby/object:Gem::Requirement
94
95
  requirements:
95
- - - '>='
96
+ - - ">="
96
97
  - !ruby/object:Gem::Version
97
98
  version: '0'
98
99
  description: Tools for FINNs ZenDesk
99
100
  email:
100
101
  - jari@finn.no
101
102
  - eivind.throndsen@finn.no
103
+ - oas@finn.no
102
104
  executables:
103
105
  - zendesk-tools
104
106
  extensions: []
105
107
  extra_rdoc_files: []
106
108
  files:
107
- - .gitattributes
108
- - .gitignore
109
+ - ".gitattributes"
110
+ - ".gitignore"
109
111
  - Gemfile
110
112
  - LICENSE.txt
111
113
  - README.md
@@ -128,17 +130,17 @@ require_paths:
128
130
  - lib
129
131
  required_ruby_version: !ruby/object:Gem::Requirement
130
132
  requirements:
131
- - - '>='
133
+ - - ">="
132
134
  - !ruby/object:Gem::Version
133
135
  version: '0'
134
136
  required_rubygems_version: !ruby/object:Gem::Requirement
135
137
  requirements:
136
- - - '>='
138
+ - - ">="
137
139
  - !ruby/object:Gem::Version
138
140
  version: '0'
139
141
  requirements: []
140
142
  rubyforge_project:
141
- rubygems_version: 2.0.14
143
+ rubygems_version: 2.2.2
142
144
  signing_key:
143
145
  specification_version: 4
144
146
  summary: Tools for FINNs ZenDesk