Class: SupportPal::Session

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/supportpal.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Session

Uncomment to debug output debug_output $stdout

Raises:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/supportpal.rb', line 15

def initialize(options)
  # Make a class variable
  @options = options

  # Load config
  if @options['config'] then # Can be hash with values, or path to yaml
    config = SupportPal::Configure.new(@options['config'])
  else
    config = SupportPal::Configure.new
  end
  @config = config.config
    
  # Check to ensure required options exist
  raise Error, 'You must provide a base_uri option!' if ! @options['base_uri']
  self.class.base_uri @options['base_uri']

  raise Error, 'You must provide an auth token in config!' if ! @config[:auth_token]

  # Default headers
  @auth = { username: @config[:auth_token], password: 'X' }
  @http_options = { basic_auth: @auth }
end

Instance Method Details

#add_ticket_note(ticket_id, message, options = {}) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/supportpal.rb', line 77

def add_ticket_note(ticket_id, message, options = {})
  params = {}
  params['text']                        = message

  params['user_id']                     = @config[:ticket_user_id]
  params['user_id']                     = options['operator_id'] if options['operator_id']
  params['user_id']                     = options['user_id'] if options['user_id']

  params['ticket_id']                   = ticket_id
  params['message_type']                = 1 # 1 = note, 0 = reply

  @http_options.merge!({ body: params })
  res = self.class.post("/api/ticket/message", @http_options)
  response = res.parsed_response
  if response['status'] == 'success' then
    return {
      :status                           => 'success',
      :message                          => response['message']
    }
  else
    return {
      :status                           => 'failure',
      :message                          => response['message']
    }
  end
end

#close_ticket_by_id(ticket_id) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/supportpal.rb', line 104

def close_ticket_by_id(ticket_id)
  # Check if ticket_id is an integer
  @http_options.merge!({ body: { status: 2 } })
  res = self.class.put("/api/ticket/ticket/#{ticket_id}", @http_options)
  response = res.parsed_response
  if response['status'] == 'success' then
    return {
      :status                           => 'success',
      :message                          => response['message']
    }
  else
    return {
      :status                           => 'failure',
      :message                          => response['message']
    }
  end
end

#open_new_ticket(subject, message, options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/supportpal.rb', line 43

def open_new_ticket(subject, message, options = {})
  params = {}
  params['subject']                     = subject
  params['text']                        = message

  params['user']                        = @config[:ticket_user_id]
  params['user']                        = options[:operator_id] if options[:operator_id]
  params['user']                        = options[:user_id] if options[:user_id]

  params['department']                  = (options[:department]) ? options[:department] : @config[:ticket_department_id]
  params['status']                      = (options[:status]) ? options[:status] : @config[:ticket_status]
  params['priority']                    = (options[:priority]) ? options[:priority] : @config[:ticket_priority]

  params['internal']                    = options[:internal] if options[:internal]

  params['send_user_email']             = (options[:send_user_email]) ? options[:send_user_email] : @config[:ticket_send_user_email]
  params['send_operators_email']        = (options[:send_operators_email]) ? options[:send_operators_email] : @config[:ticket_send_operators_email]

  @http_options.merge!({ body: params })
  res = self.class.post('/api/ticket/ticket', @http_options)
  response = res.parsed_response
  if response['status'] == 'success' then
    return {
      :status                           => 'success',
    :ticket_id                          => response['data']['id']
    }
  else
    return {
      :status                           => 'failure',
      :message                          => response['message']
    }
  end
end

#testObject



38
39
40
41
# File 'lib/supportpal.rb', line 38

def test
  puts "Base URI is #{self.class.base_uri}"
  res = self.class.get('/api/selfservice/type', @http_options)
end