Class: WHD::Ticket

Inherits:
Object
  • Object
show all
Defined in:
lib/whd_ticket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTicket

Returns a new instance of Ticket.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/whd_ticket.rb', line 11

def initialize
  unless ENV["WHD_URL"]
    print "You must set an environment variable for WHD_URL with the url of your WebHelpDesk.\n"
    print "e.g. echo export WHD_URL=https://servicedesk.com >> ~/.profile\n"
    exit
  end
  unless ENV["WHD_API_KEY"]
    print "You must set an environment variable for WHD_API_KEY with the apiKey for the tech creating the ticket.\n"
    print "e.g. echo export WHD_API_KEY=OdWPct19cIZbGIbVJkarpbrIvvx561tErxx87l3l >> ~/.profile\n"
    exit
  end
  @whd_url = ENV["WHD_URL"]
  @api_key = ENV["WHD_API_KEY"]

  # get info from user
  print "Enter a client usename for the ticket.\n"
  @ticket_client = gets.chomp
  print "Enter a subject for the ticket.\n"
  @ticket_subject = gets.chomp
  print "Enter the ticket details.\n"
  @ticket_details = gets.chomp

  @whd_utc_time = Time.now.strftime("%Y-%m-%d\T%H:%M:%S\Z")
  @send_data = {
    :reportDateUtc => @whd_utc_time,
    :emailClient => true,
    :emailTech => true,
    :emailTechGroupLevel => false,
    :emailGroupManager => false,
    :emailCc => false,
    :emailBcc => false,
    :subject => @ticket_subject,
    :detail => @ticket_details,
    :assignToCreatingTech => true,
    :problemtype => {
      :type => "ProblemType",
      :id => 124
    },
    :sendEmail => false,
    :clientReporter => {
      :type => "Client",
      :id => @ticket_client
    },
    :customFields => [
      {
        :definitionId => 21,
        :restValue => "WHD"
      },
      {
        :definitionId => 216,
        :restValue => "No"
      }
    ]
  }
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



9
10
11
# File 'lib/whd_ticket.rb', line 9

def api_key
  @api_key
end

#send_dataObject

Returns the value of attribute send_data.



9
10
11
# File 'lib/whd_ticket.rb', line 9

def send_data
  @send_data
end

#ticket_clientObject

Returns the value of attribute ticket_client.



9
10
11
# File 'lib/whd_ticket.rb', line 9

def ticket_client
  @ticket_client
end

#ticket_detailsObject

Returns the value of attribute ticket_details.



9
10
11
# File 'lib/whd_ticket.rb', line 9

def ticket_details
  @ticket_details
end

#ticket_subjectObject

Returns the value of attribute ticket_subject.



9
10
11
# File 'lib/whd_ticket.rb', line 9

def ticket_subject
  @ticket_subject
end

#whd_urlObject

Returns the value of attribute whd_url.



9
10
11
# File 'lib/whd_ticket.rb', line 9

def whd_url
  @whd_url
end

Instance Method Details

#createObject



67
68
69
70
# File 'lib/whd_ticket.rb', line 67

def create
  sendrequest = WHD::SendRestRequest.new(@whd_url, @api_key, @send_data)
  sendrequest.create
end