help_spot 0.0.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.
- data/.gitignore +4 -0
- data/History.txt +14 -0
- data/LICENSE +19 -0
- data/README.rdoc +25 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/config/help_spot.yml.sample +6 -0
- data/help_spot.gemspec +54 -0
- data/lib/help_spot.rb +200 -0
- data/spec/help_spot_spec.rb +7 -0
- data/spec/spec_helper.rb +9 -0
- metadata +77 -0
data/.gitignore
ADDED
data/History.txt
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2009 Jamie Wilson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
= HelpSpot
|
2
|
+
|
3
|
+
Ruby gem to talk to the API of a HelpSpot instance.
|
4
|
+
|
5
|
+
For information on HelpSpot: http://www.userscape.com/products/helpspot/
|
6
|
+
|
7
|
+
Details of HelpSpot's API are at: http://www.userscape.com/helpdesk/index.php?pg=kb.book&id=6
|
8
|
+
|
9
|
+
== License
|
10
|
+
|
11
|
+
Licensed under the MIT License. See the included LICENSE file.
|
12
|
+
|
13
|
+
= Usage
|
14
|
+
|
15
|
+
== Installation
|
16
|
+
|
17
|
+
Copy the <tt>config/help_spot.yml.sample</tt> file to <tt>THE_ROOT_DIR_OF_YOUR_APP/config/help_spot.yml</tt>. Edit the file to have some sensible values.
|
18
|
+
|
19
|
+
Somewhere in your application, you'll want to do this once:
|
20
|
+
|
21
|
+
<tt>HelpSpot.configure</tt>
|
22
|
+
|
23
|
+
In my app, it also turns out it's useful to do this once:
|
24
|
+
|
25
|
+
<tt>HELPSPOT_CATEGORIES = HelpSpot.category_key_value_pairs</tt>
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "help_spot"
|
8
|
+
gem.summary = %Q{A package for interacting with UserScape's HelpSpot product.}
|
9
|
+
gem.description = %Q{A package for interacting with UserScape's HelpSpot product.}
|
10
|
+
gem.email = "jnewland@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/jnewland/help_spot"
|
12
|
+
gem.authors = ["Jamie Wilson","Jesse Newland"]
|
13
|
+
gem.add_development_dependency "rspec"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
if File.exist?('VERSION')
|
40
|
+
version = File.read('VERSION')
|
41
|
+
else
|
42
|
+
version = ""
|
43
|
+
end
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "help_spot #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
data/help_spot.gemspec
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{help_spot}
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jamie Wilson", "Jesse Newland"]
|
12
|
+
s.date = %q{2009-10-11}
|
13
|
+
s.description = %q{A package for interacting with UserScape's HelpSpot product.}
|
14
|
+
s.email = %q{jnewland@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"History.txt",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"config/help_spot.yml.sample",
|
27
|
+
"help_spot.gemspec",
|
28
|
+
"lib/help_spot.rb",
|
29
|
+
"spec/help_spot_spec.rb",
|
30
|
+
"spec/spec_helper.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/jnewland/help_spot}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.3}
|
36
|
+
s.summary = %q{A package for interacting with UserScape's HelpSpot product.}
|
37
|
+
s.test_files = [
|
38
|
+
"spec/help_spot_spec.rb",
|
39
|
+
"spec/spec_helper.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
50
|
+
end
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
53
|
+
end
|
54
|
+
end
|
data/lib/help_spot.rb
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
##
|
7
|
+
# help_spot
|
8
|
+
#
|
9
|
+
# A partial basic implementation of a HelpSpot API interface
|
10
|
+
#
|
11
|
+
# == Using help_spot
|
12
|
+
#
|
13
|
+
# === Basics
|
14
|
+
#
|
15
|
+
# Copy and edit the included config file. Include the gem in your app. Call the configure method. Hit the API.
|
16
|
+
#
|
17
|
+
# require 'help_spot'
|
18
|
+
# HelpSpot.configure(:config_file => '/path/to/help_spot.yml')
|
19
|
+
# HelpSpot.forums_list
|
20
|
+
#
|
21
|
+
# => [{"xForumId"=>"1", "fClosed"=>"0", "sForumName"=>"The First Forum", "iOrder"=>"0", "sDescription"=>"A test forum"}, {"xForumId"=>"2", "fClosed"=>"0", "sForumName"=>"Secondary Forum", "iOrder"=>"0", "sDescription"=>"Forum #2"}]
|
22
|
+
#
|
23
|
+
|
24
|
+
module HelpSpot
|
25
|
+
class << self
|
26
|
+
|
27
|
+
# Loads the config file.
|
28
|
+
#
|
29
|
+
# == Options
|
30
|
+
# * config_file (optional)
|
31
|
+
# Defaults to '/config/help_spot.yml'
|
32
|
+
# Shouldn't be required when using merb or Rails.
|
33
|
+
#
|
34
|
+
def configure(args={})
|
35
|
+
# work out the default app_root
|
36
|
+
if defined?(Merb)
|
37
|
+
app_root = Merb.root
|
38
|
+
elsif defined?(Rails)
|
39
|
+
app_root = RAILS_ROOT
|
40
|
+
else
|
41
|
+
app_root = '.'
|
42
|
+
end
|
43
|
+
|
44
|
+
config_file = args[:config_file] || '/config/help_spot.yml'
|
45
|
+
yml_file = app_root+config_file
|
46
|
+
|
47
|
+
raise yml_file+" not found" unless File.exist? yml_file
|
48
|
+
@config = YAML.load_file(yml_file)
|
49
|
+
end
|
50
|
+
|
51
|
+
# sends a feedback request to HelpSpot and returns the request ID number and access key
|
52
|
+
#
|
53
|
+
# == Options
|
54
|
+
# In addition to note you must also have at least one of the following set: first_name, last_name, user_id, email or phone
|
55
|
+
# * note
|
56
|
+
# The body of the ticket
|
57
|
+
# * category
|
58
|
+
# * first_name
|
59
|
+
# * last_name
|
60
|
+
# * user_id
|
61
|
+
# * email
|
62
|
+
# * phone
|
63
|
+
# * urgent
|
64
|
+
# A boolean flag. Defaults to false.
|
65
|
+
#
|
66
|
+
def create(args)
|
67
|
+
help_form = {:tNote => args[:note],
|
68
|
+
:xCategory => args[:category],
|
69
|
+
:sFirstName => args[:first_name],
|
70
|
+
:sLastName => args[:last_name],
|
71
|
+
:sUserId => args[:user_id],
|
72
|
+
:sEmail => args[:email],
|
73
|
+
:sPhone => args[:phone],
|
74
|
+
:fUrgent => args[:urgent]}.reject!{|k,v| v == nil}
|
75
|
+
|
76
|
+
JSON.parse(api_request('request.create', 'POST', help_form))['xRequest'] rescue []
|
77
|
+
end
|
78
|
+
|
79
|
+
# Returns an array of tickets belonging to a given user id.
|
80
|
+
#
|
81
|
+
# == Authentication
|
82
|
+
# This method does require authentication.
|
83
|
+
#
|
84
|
+
# == Options
|
85
|
+
# * user_id
|
86
|
+
# The user who's tickets you wish to view.
|
87
|
+
#
|
88
|
+
def get_by_user_id(args)
|
89
|
+
JSON.parse(api_request('private.request.search', 'GET', {:sUserId => args[:user_id]}))['request'] rescue nil
|
90
|
+
end
|
91
|
+
|
92
|
+
# Returns ticket categories.
|
93
|
+
#
|
94
|
+
# == Authentication
|
95
|
+
# This method does require authentication.
|
96
|
+
#
|
97
|
+
# == Options
|
98
|
+
# * include_deleted
|
99
|
+
# true if you want to include deleted categories.
|
100
|
+
#
|
101
|
+
def categories(args={})
|
102
|
+
res = api_request('private.request.getCategories', 'GET')
|
103
|
+
res = JSON.parse(res)['category'] rescue []
|
104
|
+
|
105
|
+
unless args[:include_deleted] and args[:include_deleted] == true
|
106
|
+
res.reject!{|k, v| v['fDeleted'] == '1'} rescue []
|
107
|
+
end
|
108
|
+
|
109
|
+
return res
|
110
|
+
end
|
111
|
+
|
112
|
+
# Returns an array of non-deleted categories, as key value pairs. Useful for select lists.
|
113
|
+
#
|
114
|
+
# == Authentication
|
115
|
+
# This method does require authentication.
|
116
|
+
#
|
117
|
+
def category_key_value_pairs
|
118
|
+
categories.collect{|k,v| [k,v['sCategory']]} rescue []
|
119
|
+
end
|
120
|
+
|
121
|
+
# Returns non-deleted categories, with a list of predefined categories removed
|
122
|
+
#
|
123
|
+
def category_key_value_pairs_without(categories=nil)
|
124
|
+
categories ||= @config['hidden_categories'] rescue nil
|
125
|
+
|
126
|
+
orig_categories = category_key_value_pairs
|
127
|
+
if categories
|
128
|
+
categories.each do |category|
|
129
|
+
orig_categories.reject!{|i| i[1] == category}
|
130
|
+
end
|
131
|
+
end
|
132
|
+
orig_categories
|
133
|
+
end
|
134
|
+
|
135
|
+
# Returns an array of forums
|
136
|
+
#
|
137
|
+
def forums_list
|
138
|
+
JSON.parse(HelpSpot.api_request('forums.list'))['forum'] rescue []
|
139
|
+
end
|
140
|
+
|
141
|
+
# Returns an array of forums
|
142
|
+
#
|
143
|
+
# == Options
|
144
|
+
# * forum_id
|
145
|
+
# The numeric id of the forum you want.
|
146
|
+
def forum_get(args)
|
147
|
+
JSON.parse(HelpSpot.api_request('forums.get', 'GET', :xForumId => args[:forum_id])) rescue []
|
148
|
+
end
|
149
|
+
|
150
|
+
# Returns an array of topics from a given forum
|
151
|
+
#
|
152
|
+
# == Options
|
153
|
+
# * forum_id
|
154
|
+
# The numeric id of the forum you want.
|
155
|
+
# * start
|
156
|
+
# record set position to start at
|
157
|
+
# * length
|
158
|
+
# how many records to return
|
159
|
+
#
|
160
|
+
def forum_get_topics(args={})
|
161
|
+
JSON.parse(HelpSpot.api_request('forums.getTopics', 'GET', {:xForumId => args[:forum_id]}.merge(args)))['topic'] rescue []
|
162
|
+
end
|
163
|
+
|
164
|
+
# Returns an array of posts from a given topic
|
165
|
+
#
|
166
|
+
# == Options
|
167
|
+
# * topic_id
|
168
|
+
# The numeric id of the topic
|
169
|
+
#
|
170
|
+
def forum_get_topic_posts(args={})
|
171
|
+
JSON.parse(HelpSpot.api_request('forums.getPosts', 'GET', :xTopicId => args[:topic_id]))['post'] rescue []
|
172
|
+
end
|
173
|
+
|
174
|
+
def api_request(api_method, http_method='POST', args={})
|
175
|
+
api_params = {:method => api_method, :output => 'json'}.merge(args)
|
176
|
+
query_params = api_params.collect{|k,v| [k.to_s, v.to_s]} # [URI.encode(k.to_s),URI.encode(v.to_s.gsub(/\ /, '+'))]
|
177
|
+
built_query = query_params.collect{|i| i.join('=')}.join('&') # make a query string
|
178
|
+
|
179
|
+
ru = URI::parse(@config['root_url']) # where ru = ROOT_URL
|
180
|
+
merged_query = [built_query, (ru.query == '' ? nil : ru.query)].compact.join('&') # merge our generated query string with the ROOT_URL's query string
|
181
|
+
|
182
|
+
url = URI::HTTP.new(ru.scheme, ru.userinfo, ru.host, ru.port, ru.registry, ru.path, ru.opaque, merged_query, ru.fragment)
|
183
|
+
|
184
|
+
request = nil
|
185
|
+
if http_method == 'POST'
|
186
|
+
request = Net::HTTP::Post.new(url.path)
|
187
|
+
request.set_form_data(query_params)
|
188
|
+
else
|
189
|
+
request = Net::HTTP::Get.new(url.path+'?'+url.query)
|
190
|
+
end
|
191
|
+
request.basic_auth @config['username'], @config['password']
|
192
|
+
http = Net::HTTP.new(url.host, url.port)
|
193
|
+
http.use_ssl = (url.scheme == 'https')
|
194
|
+
response = http.start { |h| h.request(request) }
|
195
|
+
|
196
|
+
response.body
|
197
|
+
end
|
198
|
+
|
199
|
+
end # class
|
200
|
+
end # module
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: help_spot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jamie Wilson
|
8
|
+
- Jesse Newland
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-10-11 00:00:00 -04:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rspec
|
18
|
+
type: :development
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
version:
|
26
|
+
description: A package for interacting with UserScape's HelpSpot product.
|
27
|
+
email: jnewland@gmail.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- LICENSE
|
34
|
+
- README.rdoc
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- History.txt
|
38
|
+
- LICENSE
|
39
|
+
- README.rdoc
|
40
|
+
- Rakefile
|
41
|
+
- VERSION
|
42
|
+
- config/help_spot.yml.sample
|
43
|
+
- help_spot.gemspec
|
44
|
+
- lib/help_spot.rb
|
45
|
+
- spec/help_spot_spec.rb
|
46
|
+
- spec/spec_helper.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://github.com/jnewland/help_spot
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --charset=UTF-8
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.3.3
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: A package for interacting with UserScape's HelpSpot product.
|
75
|
+
test_files:
|
76
|
+
- spec/help_spot_spec.rb
|
77
|
+
- spec/spec_helper.rb
|