help_spot 0.0.9 → 0.1.0
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/lib/help_spot/version.rb +1 -1
- data/lib/help_spot.rb +24 -4
- metadata +4 -4
data/lib/help_spot/version.rb
CHANGED
data/lib/help_spot.rb
CHANGED
@@ -7,6 +7,9 @@ class HelpSpot
|
|
7
7
|
format :xml
|
8
8
|
mattr_inheritable :base
|
9
9
|
|
10
|
+
class ApiErrors < RuntimeError
|
11
|
+
end
|
12
|
+
|
10
13
|
def initialize(base, user, pass)
|
11
14
|
self.class.base_uri base
|
12
15
|
self.class.basic_auth user, pass
|
@@ -15,10 +18,12 @@ class HelpSpot
|
|
15
18
|
# Verify authentication credentials
|
16
19
|
#
|
17
20
|
def authenticated?
|
18
|
-
version =
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
version = begin
|
22
|
+
api_request(:get, 'private.version').results.version
|
23
|
+
true
|
24
|
+
rescue HelpSpot::ApiErrors => e
|
25
|
+
return false
|
26
|
+
end
|
22
27
|
end
|
23
28
|
|
24
29
|
def create_request(options = {})
|
@@ -79,6 +84,21 @@ private
|
|
79
84
|
end
|
80
85
|
parsed_options[:query].merge!(:method => method)
|
81
86
|
response = self.class.send(http_method, '/index.php', parsed_options)
|
87
|
+
|
88
|
+
if errors = response['errors']
|
89
|
+
# JSON gets returned weirdly sometimes if there's a single error. it gets interpreted as a hash, rather than an array with one thing
|
90
|
+
if errors.kind_of?(Hash)
|
91
|
+
errors = [errors['error']]
|
92
|
+
end
|
93
|
+
|
94
|
+
errors_string = errors.map do |error|
|
95
|
+
"* #{error['id']} - #{error['description']}"
|
96
|
+
end.join("\n")
|
97
|
+
|
98
|
+
raise ApiErrors, "#{errors.size} error(s) during #{method} API request:\n#{errors_string}"
|
99
|
+
end
|
100
|
+
|
101
|
+
|
82
102
|
if munge_options[:collection]
|
83
103
|
unless collection = response[munge_options[:collection]][munge_options[:item]]
|
84
104
|
return []
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: help_spot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.9
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jesse Newland
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-07-
|
18
|
+
date: 2012-07-23 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|