Class: HelpSpot

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/help_spot.rb,
lib/help_spot/version.rb

Defined Under Namespace

Classes: ApiErrors

Constant Summary collapse

VERSION =
'0.2.1'

Instance Method Summary collapse

Constructor Details

#initialize(base, user, pass) ⇒ HelpSpot

Returns a new instance of HelpSpot.



13
14
15
16
# File 'lib/help_spot.rb', line 13

def initialize(base, user, pass)
  self.class.base_uri base
  self.class.basic_auth user, pass
end

Instance Method Details

#authenticated?Boolean

Verify authentication credentials

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
# File 'lib/help_spot.rb', line 20

def authenticated?
  version = begin 
              api_request(:get, 'private.version').results.version
              true
            rescue HelpSpot::ApiErrors => e
              return false
            end
end

#categoriesObject



51
52
53
# File 'lib/help_spot.rb', line 51

def categories
  api_request(:get, 'private.request.getCategories', {:fDeleted => 0}, {:collection => 'categories', :item => 'category'})
end

#create_request(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
# File 'lib/help_spot.rb', line 29

def create_request(options = {})
  raise ArgumentError unless options[:tNote] && options[:xCategory]
  raise ArgumentError unless options[:sFirstName] || options[:sLastName] || options[:sUserId] || options[:sEmail] || options[:sPhone]
  api_request(:post, 'private.request.create', options, :item => 'request').xRequest.to_i
end

#custom_fields(options = {}) ⇒ Object



59
60
61
# File 'lib/help_spot.rb', line 59

def custom_fields(options = {})
  api_request(:get, 'private.request.getCustomFields', options, {:collection => 'customfields', :item => 'field'})
end

#filter(id, options = {}) ⇒ Object



63
64
65
# File 'lib/help_spot.rb', line 63

def filter(id, options = {})
  api_request(:get, 'private.filter.get', options.merge(:xFilter => id), {:collection => 'filter', :item => 'request'})
end

#request(id, options = {}) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/help_spot.rb', line 39

def request(id, options = {})
  response = api_request(:get, 'private.request.get', options.merge(:xRequest => id), :item => 'request')
  #munge even further the request history
  response.request_history = response.request_history['item'] rescue []
  response.request_history = [response.request_history] unless response.request_history.is_a?(Array)
  response
end

#search_requests(options = {}) ⇒ Object



47
48
49
# File 'lib/help_spot.rb', line 47

def search_requests(options = {})
  api_request(:get, 'private.request.search', options, {:collection => 'requests', :item => 'request'})
end

#search_time_events(options = {}) ⇒ Object



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

def search_time_events(options = {})
  api_request(:get, 'private.timetracker.search', options, {:collection => 'time_events', :item => 'event'})
end

#status_typesObject



55
56
57
# File 'lib/help_spot.rb', line 55

def status_types
  api_request(:get, 'private.request.getStatusTypes', {:fActiveOnly => 1}, {:collection => 'results', :item => 'status'})
end

#time_events(id, options = {}) ⇒ Object



71
72
73
# File 'lib/help_spot.rb', line 71

def time_events(id, options = {})
  api_request(:get, 'private.request.getTimeEvents', options.merge(:xRequest => id), {:collection => 'time_events', :item => 'event'})
end

#update_request(id, options = {}) ⇒ Object



35
36
37
# File 'lib/help_spot.rb', line 35

def update_request(id, options = {})
  api_request(:post, 'private.request.update', options.merge(:xRequest => id), :item => 'request').xRequest.to_i
end