zendeath 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +18 -0
  3. data/README.md +30 -0
  4. data/bin/zendeath +3 -0
  5. data/lib/commands.rb +138 -0
  6. data/lib/zendeath.rb +55 -0
  7. metadata +50 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2b4a4219b3e41a6d6909d0d51a3111522430c95f
4
+ data.tar.gz: 9c7e4ac11893c29aaf97688f66b25cbff1469a53
5
+ SHA512:
6
+ metadata.gz: 5d85b1a84b7d88406ac286568a294a8a2a538eb8f117d31a08d00f60f24d2f13ce00d9ef8c44421cdba68689fbf429a43ba6ea07da33ad54486e6edfa5dfc5f6
7
+ data.tar.gz: b67f96b206898114b52df03df34df00e4d2f31a66ef6cc6a6576371838a31ceba1463378eb7612175fbfb2d0ad62de36b905ae6db22a859152724b516686d07f
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright © 2013 Zachary Alex Stern <zacharyalexstern@gmail.com>
2
+ This work is free. You can redistribute it and/or modify it under the
3
+ terms of the Do What The Fuck You Want To Public License, Version 2,
4
+ as published by Sam Hocevar. See below for more details.
5
+
6
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
7
+ Version 2, December 2004
8
+
9
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
10
+
11
+ Everyone is permitted to copy and distribute verbatim or modified
12
+ copies of this license document, and changing it is allowed as long
13
+ as the name is changed.
14
+
15
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
16
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
17
+
18
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Zendeath
2
+
3
+ An open source command-line client for Zendesk.
4
+
5
+ Primarly created as a learning experience.
6
+
7
+ Copy `.zendeath.yaml.example` to `~/.zendeath.yaml` and fill in relevant
8
+ details.
9
+
10
+ Current commands include:
11
+
12
+ * me - Shows what Zendesk knows about the current user.
13
+ * localinfo - Shows config data.
14
+ * alltickets - Shows total number of tickets, plus number of unsolved
15
+ tickets.
16
+ * myworking - Shows your current working tickets + some data.
17
+ * showticket - Show ticket info + comments.
18
+
19
+ Currently has no external dependencies for real functionality, but
20
+ requires pry because I'm lazy and it's a work in progress.
21
+
22
+ No tests because I don't know how to write tests yet.
23
+
24
+
25
+ #### todo
26
+
27
+ - [ ] showticket should give requester name
28
+ - [ ] showticket should left/right justify for requester/agent
29
+ - [ ] Ability to post updates to tickets
30
+ - [ ] Ability to change status of tickets
data/bin/zendeath ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'zendeath'
data/lib/commands.rb ADDED
@@ -0,0 +1,138 @@
1
+ class Commands
2
+ def initialize(baseurl, username, password)
3
+ @uri = URI.parse("https://#{baseurl}/")
4
+ @username = username
5
+ @password = password
6
+ @uri.path = '/api/v2/users/me.json'
7
+ @current_user_info = JSON.parse(makerequest)
8
+ end
9
+
10
+ def localinfo
11
+ puts @uri
12
+ puts @username
13
+ puts @password
14
+ end
15
+
16
+ def makerequest(type='Get', body='')
17
+ @http = Net::HTTP.new(@uri.host, @uri.port)
18
+ @http.use_ssl = true
19
+ @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
20
+
21
+ if type == 'Get'
22
+ @request = Net::HTTP::Get.new(@uri.request_uri)
23
+ elsif type == 'Put'
24
+ @request = Net::HTTP::Put.new(@uri.request_uri)
25
+ @reqest.body = body
26
+ else
27
+ raise ArgumentError.new('Unrecognized HTTP request type.')
28
+ end
29
+
30
+ @request.basic_auth(@username, @password)
31
+ return @response = @http.request(@request).body
32
+ end
33
+
34
+ def get_this_user(userid)
35
+ @uri.path = "/api/v2/users/#{userid}.json"
36
+ @uri.query = ''
37
+ return JSON.parse(makerequest)['user']
38
+ end
39
+
40
+ def me
41
+ def userelement(field)
42
+ @current_user_info['user'][field]
43
+ end
44
+
45
+ user_name = userelement('name')
46
+ user_email = userelement('email')
47
+ user_role = userelement('role')
48
+ user_created = userelement('created_at')
49
+ user_last_login = userelement('last_login_at')
50
+ user_time_zone = userelement('time_zone')
51
+
52
+ puts "Name: #{user_name}"
53
+ puts "Email: #{user_email}"
54
+ puts "Role: #{user_role}"
55
+ puts "Created: #{user_created}"
56
+ puts "Last Login: #{user_last_login}"
57
+ puts "Time Zone: #{user_time_zone}"
58
+ end
59
+
60
+ def alltickets
61
+ @uri.path = '/api/v2/tickets.json'
62
+ @response = JSON.parse(makerequest)
63
+ alltickets = @response['tickets']
64
+
65
+ pagecount = 1
66
+
67
+ while @response['next_page'] != nil
68
+ pagecount += 1
69
+ @uri.query = 'page=' + pagecount.to_s
70
+ @response = JSON.parse(makerequest)
71
+ alltickets.concat(@response['tickets'])
72
+ end
73
+
74
+ unsolved_tickets = alltickets.reject { |element| element['status'] == 'closed' }
75
+
76
+ puts "Total Tickets: #{alltickets.length.to_s}"
77
+ puts "Unsolved Tickets: #{unsolved_tickets.length.to_s}"
78
+ end
79
+
80
+ def myworking
81
+ @uri.path = '/api/v2/search.json'
82
+ @uri.query = URI.encode("query=status<solved+assignee:#{@username}+type:ticket")
83
+ @my_working_tickets = JSON.parse(makerequest)['results']
84
+
85
+ @my_working_tickets.each do |ticket|
86
+ requester = get_this_user(ticket['requester_id'])['name']
87
+ puts ticket['id'].to_s + ': ' + ticket['subject']
88
+ puts "Requester: #{requester}"
89
+ puts 'Status: ' + ticket['status']
90
+ puts ''
91
+ end
92
+ puts "Total Working Tickets: #{@my_working_tickets.length}"
93
+ end
94
+
95
+ def ticketinfo(ticketid)
96
+ @uri.path = "/api/v2/tickets/#{ticketid.to_s}.json"
97
+ JSON.parse(makerequest)
98
+ end
99
+
100
+ def ticketcomments(ticketid)
101
+ @uri.path = "/api/v2/tickets/#{ticketid.to_s}/comments.json"
102
+ JSON.parse(makerequest)
103
+ end
104
+
105
+ def showticket(ticketid)
106
+ info = ticketinfo(ticketid)
107
+ comments = ticketcomments(ticketid)
108
+
109
+ puts "Ticket ID: #{info['ticket']['id']}"
110
+ puts "Status: #{info['ticket']['status']}"
111
+ puts "Last Updated: #{info['ticket']['updated_at']}"
112
+ puts "Subject: #{info['ticket']['subject']}"
113
+ puts ""
114
+ comments['comments'].reverse.each do |comment|
115
+ puts "Timestamp: #{comment['created_at']}"
116
+ puts "Comment: #{comment['body']}"
117
+ puts "########################"
118
+ end
119
+ end
120
+
121
+ def updateticket(ticketid, comment, status='open', is_public='true')
122
+ # https://support.puppetlabs.com/api/v2/tickets/3717.json
123
+ @uri.path = "/api/v2/tickets/#{ticketid.to_s}.json"
124
+ unless status == ('pending' || 'open' || 'on-hold' || 'solved')
125
+ raise ArgumentError.new('Valid ticket status is pending, on-hold, open, or solved.')
126
+ end
127
+ updatearray = {
128
+ 'ticket' => {
129
+ 'comment' => { 'body' => comment, 'public' => is_public },
130
+ 'status' => status
131
+ }
132
+ }
133
+ updatearray_json = updatearray.to_json
134
+ response = makerequest('Put', updatearray_json)
135
+ end
136
+
137
+
138
+ end
data/lib/zendeath.rb ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+ #$LOAD_PATH << File.dirname(__FILE__)
3
+
4
+ module Zendeath
5
+ require 'net/http'
6
+ require 'net/https'
7
+ require 'yaml'
8
+ require 'json'
9
+ require 'commands'
10
+
11
+ configdata = YAML.load_file(ENV['HOME'] + '/.zendeath.yaml')
12
+ baseurl = configdata[:baseurl]
13
+ username = configdata[:username]
14
+ password = configdata[:password]
15
+
16
+ command = Commands.new(baseurl, username, password)
17
+
18
+ case ARGV[0]
19
+ when 'localinfo'
20
+ command.localinfo
21
+ when 'me'
22
+ command.me
23
+ when 'alltickets'
24
+ command.alltickets
25
+ when 'myworking'
26
+ command.myworking
27
+ when 'ticketinfo'
28
+ command.ticketinfo(ARGV[1])
29
+ when 'ticketcomments'
30
+ command.ticketcomments(ARGV[1])
31
+ when 'update'
32
+ # def updateticket(ticketid, comment, status='open', is_public='true')
33
+
34
+ command.updateticket(ARGV[1])
35
+ when 'showticket'
36
+ unless ARGV.length == 2
37
+ raise ArgumentError.new('showticket requires a ticket number')
38
+ end
39
+ command.showticket(ARGV[1])
40
+ else
41
+ puts 'Error!
42
+ Current commands include:
43
+ - localinfo
44
+ - me
45
+ - alltickets
46
+ - myworking
47
+ - ticketinfo <ticketid> - Not useful on its own.
48
+ - ticketcomments <ticketid> - Not useful on its own.
49
+ - showticket <ticketid>
50
+ - update <ticketid> <comment> [status] [public]
51
+
52
+ <param> - required param
53
+ [param] - optional param'
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zendeath
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Zachary Alex Stern
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Zendeath is a command line client for Zendesk, primarily focused on Puppet
14
+ Labs' use case, but may be made more generic in the future.
15
+ email: zacharyalexstern@gmail.com
16
+ executables:
17
+ - zendeath
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/commands.rb
22
+ - lib/zendeath.rb
23
+ - bin/zendeath
24
+ - LICENSE
25
+ - README.md
26
+ homepage: https://github.com/zacharyalexstern/zendeath
27
+ licenses:
28
+ - WTFPL
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.0.3
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Command Line Zendeath
50
+ test_files: []