whd_ticket 0.1.2 → 0.2.2
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 +4 -4
- data/bin/whd_ticket +2 -1
- data/lib/whd_ticket/version.rb +1 -1
- data/lib/whd_ticket/whd_rest_method.rb +49 -0
- data/lib/whd_ticket.rb +32 -40
- 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: 8bbe1b81b3e3865b24e1514be544572de4327bdb
|
|
4
|
+
data.tar.gz: e32794d8034c22a5e4cc90a4c0339d95df16fc04
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: efc6e125c6356e3863f2290f97cd5d1831bb637754d7626229d5789c352367483e71ca8d63b53a26168e2ce1ab194d1e83928424d4e37e1a4bd923257693052f
|
|
7
|
+
data.tar.gz: 124e2e196c4d36efe2c26b933224cf8640e0ff023fe70c77cbd97b3de5b4bf489940cbdd26f69aa2c3114542eb41bdfeb4cf1fc989f90992109d8ef40c440d20
|
data/bin/whd_ticket
CHANGED
data/lib/whd_ticket/version.rb
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require 'net/http'
|
|
3
|
+
|
|
4
|
+
module WHD
|
|
5
|
+
class SendRestRequest
|
|
6
|
+
|
|
7
|
+
def initialize(whd_url, api_key, data)
|
|
8
|
+
@whd_url = whd_url
|
|
9
|
+
@whd_url_path = "/helpdesk/WebObjects/Helpdesk.woa"
|
|
10
|
+
@api_key = api_key
|
|
11
|
+
@data = data
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def create
|
|
15
|
+
|
|
16
|
+
url = "#{@whd_url}#{@whd_url_path}/ra/Tickets"
|
|
17
|
+
puts url
|
|
18
|
+
uri = URI.parse(url)
|
|
19
|
+
params = { :apiKey => @api_key }
|
|
20
|
+
uri.query = URI.encode_www_form(params)
|
|
21
|
+
|
|
22
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
23
|
+
# http.set_debug_output $stdout
|
|
24
|
+
http.use_ssl = true
|
|
25
|
+
|
|
26
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
|
27
|
+
request['Content-Type'] = "application/json"
|
|
28
|
+
|
|
29
|
+
request.body = @data.to_json
|
|
30
|
+
|
|
31
|
+
response = http.request(request)
|
|
32
|
+
|
|
33
|
+
begin
|
|
34
|
+
json = JSON.parse(response.body)
|
|
35
|
+
rescue JSON::ParserError => e
|
|
36
|
+
print "There seems to be an issue with the json reponse. Please have a look!!\n"
|
|
37
|
+
return
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
if response.code == '201'
|
|
41
|
+
print "Ticket with id: #{json["id"]} and subject '#{json["subject"]}' has been created.\n"
|
|
42
|
+
else
|
|
43
|
+
print "There was an error creating the ticket.\n"
|
|
44
|
+
print "http code : #{response.code}"
|
|
45
|
+
print "http message : #{respnse.message}"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
data/lib/whd_ticket.rb
CHANGED
|
@@ -1,33 +1,46 @@
|
|
|
1
1
|
require "whd_ticket/version"
|
|
2
|
-
require '
|
|
3
|
-
require '
|
|
4
|
-
require 'time'
|
|
2
|
+
require 'time' # to setup the right time format for the api
|
|
3
|
+
require 'whd_ticket/whd_rest_method'
|
|
5
4
|
|
|
6
5
|
module WHD
|
|
7
6
|
|
|
8
7
|
class Ticket
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
attr_accessor :whd_url, :api_key, :ticket_client, :ticket_subject, :ticket_details, :send_data
|
|
11
10
|
|
|
11
|
+
def initialize
|
|
12
|
+
unless ENV["WHD_URL"]
|
|
13
|
+
print "You must set an environment variable for WHD_URL with the url of your WebHelpDesk.\n"
|
|
14
|
+
print "e.g. echo export WHD_URL=https://servicedesk.com >> ~/.profile\n"
|
|
15
|
+
return
|
|
16
|
+
end
|
|
17
|
+
unless ENV["WHD_API_KEY"]
|
|
18
|
+
print "You must set an environment variable for WHD_URL with the apiKey for the tech creating the ticket.\n"
|
|
19
|
+
print "e.g. echo export WHD_API_KEY=OdWPct19cIZbGIbVJkarpbrIvvx561tErxx87l3l >> ~/.profile\n"
|
|
20
|
+
return
|
|
21
|
+
end
|
|
22
|
+
@whd_url = ENV["WHD_URL"]
|
|
23
|
+
@api_key = ENV["WHD_API_KEY"]
|
|
24
|
+
|
|
25
|
+
# get info from user
|
|
12
26
|
print "Enter a client usename for the ticket.\n"
|
|
13
|
-
ticket_client = gets.chomp
|
|
27
|
+
@ticket_client = gets.chomp
|
|
14
28
|
print "Enter a subject for the ticket.\n"
|
|
15
|
-
ticket_subject = gets.chomp
|
|
29
|
+
@ticket_subject = gets.chomp
|
|
16
30
|
print "Enter the ticket details.\n"
|
|
17
|
-
ticket_details = gets.chomp
|
|
18
|
-
|
|
19
|
-
whd_utc_time = Time.now.strftime("%Y-%m-%d\T%H:%M:%S\Z")
|
|
31
|
+
@ticket_details = gets.chomp
|
|
20
32
|
|
|
21
|
-
|
|
22
|
-
|
|
33
|
+
@whd_utc_time = Time.now.strftime("%Y-%m-%d\T%H:%M:%S\Z")
|
|
34
|
+
@send_data = {
|
|
35
|
+
"reportDateUtc": @whd_utc_time,
|
|
23
36
|
"emailClient": true,
|
|
24
37
|
"emailTech": true,
|
|
25
38
|
"emailTechGroupLevel": false,
|
|
26
39
|
"emailGroupManager": false,
|
|
27
40
|
"emailCc": false,
|
|
28
41
|
"emailBcc": false,
|
|
29
|
-
"subject": ticket_subject,
|
|
30
|
-
"detail": ticket_details,
|
|
42
|
+
"subject": @ticket_subject,
|
|
43
|
+
"detail": @ticket_details,
|
|
31
44
|
"assignToCreatingTech": true,
|
|
32
45
|
"problemtype": {
|
|
33
46
|
"type": "ProblemType",
|
|
@@ -36,7 +49,7 @@ module WHD
|
|
|
36
49
|
"sendEmail": false,
|
|
37
50
|
"clientReporter": {
|
|
38
51
|
"type": "Client",
|
|
39
|
-
"id": ticket_client
|
|
52
|
+
"id": @ticket_client
|
|
40
53
|
},
|
|
41
54
|
"customFields": [
|
|
42
55
|
{
|
|
@@ -49,33 +62,12 @@ module WHD
|
|
|
49
62
|
}
|
|
50
63
|
]
|
|
51
64
|
}
|
|
65
|
+
end
|
|
52
66
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
params = { :apiKey => api_key }
|
|
57
|
-
uri.query = URI.encode_www_form(params)
|
|
58
|
-
|
|
59
|
-
# Full control
|
|
60
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
|
61
|
-
# http.set_debug_output $stdout
|
|
62
|
-
http.use_ssl = true
|
|
63
|
-
|
|
64
|
-
request = Net::HTTP::Post.new(uri.request_uri)
|
|
65
|
-
request['Content-Type'] = "application/json"
|
|
66
|
-
|
|
67
|
-
request.body = send_data.to_json
|
|
68
|
-
|
|
69
|
-
response = http.request(request)
|
|
70
|
-
|
|
71
|
-
json = JSON.parse(response.body)
|
|
72
|
-
# Status
|
|
73
|
-
# puts response.code # => '200'
|
|
74
|
-
# puts response.message # => 'OK'
|
|
75
|
-
# puts response.class.name # => 'HTTPOK'
|
|
76
|
-
# puts json
|
|
77
|
-
# Body
|
|
78
|
-
puts "Ticket with id: #{json["id"]} and subject '#{json["subject"]}' has been created."
|
|
67
|
+
def create
|
|
68
|
+
sendrequest = WHD::SendRestRequest.new(@whd_url, @api_key, @send_data)
|
|
69
|
+
sendrequest.create
|
|
79
70
|
end
|
|
71
|
+
|
|
80
72
|
end
|
|
81
73
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: whd_ticket
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Smith
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-01-
|
|
11
|
+
date: 2017-01-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -74,6 +74,7 @@ files:
|
|
|
74
74
|
- bin/whd_ticket
|
|
75
75
|
- lib/whd_ticket.rb
|
|
76
76
|
- lib/whd_ticket/version.rb
|
|
77
|
+
- lib/whd_ticket/whd_rest_method.rb
|
|
77
78
|
- whd_ticket.gemspec
|
|
78
79
|
homepage: https://bitbucket.org/michaelosmith
|
|
79
80
|
licenses:
|