surveymonkey 0.2.2 → 0.3.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.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/surveymonkey/error.rb +54 -0
- data/lib/surveymonkey/request.rb +10 -1
- data/lib/surveymonkey/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e1ba04b72f387956b57379112fcc3d0b2af52bc
|
4
|
+
data.tar.gz: 646d1fbe102a8c982f8bf6d360e602dd790577bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84eb3f064ff7f5538fb07c0d542616a88e60230360d6f56bdfcd6f7716adbae616bc035e1472fb693dcc9959372047e617f58b17a21e7f7807fcc5aaf915b29c
|
7
|
+
data.tar.gz: 93123b3ba30cf464513bd35f603fe1b93bcf3d19f5add1e7db5f8475cdf0637d51757ece7bdf774f91197aae3237590aa3a6c0a70618b6e7b1c68f7b12b9cc08
|
data/README.md
CHANGED
@@ -67,6 +67,8 @@ To pass parameters to an API method, pass a hash as the `method_params` paramete
|
|
67
67
|
|
68
68
|
API method responses are parsed into Ruby data structures; do with them as you think best.
|
69
69
|
|
70
|
+
SurveyMonkey API responses include a `status` attribute. The possible values of this attribute are documented upstream; `Surveymonkey::Client` inspects each API response and raises a `Surveymonkey::Error` if the status code is other than 0.
|
71
|
+
|
70
72
|
## Development
|
71
73
|
|
72
74
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'surveymonkey/logging'
|
2
|
+
|
3
|
+
class Surveymonkey::Error < StandardError
|
4
|
+
# constants
|
5
|
+
|
6
|
+
##
|
7
|
+
# API status codes, documented upstream.
|
8
|
+
|
9
|
+
Status_codes = {
|
10
|
+
0 => 'Success',
|
11
|
+
1 => 'Not Authenticated',
|
12
|
+
2 => 'Invalid User Credentials',
|
13
|
+
3 => 'Invalid Request',
|
14
|
+
4 => 'Unknown User',
|
15
|
+
5 => 'System Error'
|
16
|
+
}
|
17
|
+
|
18
|
+
attr_reader :status, :status_name, :status_codes, :errmsg
|
19
|
+
|
20
|
+
##
|
21
|
+
# Create a new Surveymonkey::Error object. Pass in the hash parsed from the
|
22
|
+
# JSON object returned by the API.
|
23
|
+
|
24
|
+
def initialize(error = {}, status_codes = Status_codes)
|
25
|
+
begin
|
26
|
+
@status_codes = status_codes
|
27
|
+
@status = error.fetch('status', 0)
|
28
|
+
@errmsg = error.fetch('errmsg', '')
|
29
|
+
@status_name = _status_name(@status)
|
30
|
+
|
31
|
+
rescue StandardError => e
|
32
|
+
$log.error(sprintf("%s: unable to parse '%s' as error\n", __method__, error.inspect))
|
33
|
+
raise
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# Stringify a Surveymonkey::Error object.
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
sprintf("Error %i (%s): %s", self.status, self.status_name, self.errmsg)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def _status_name(error) # :nodoc:
|
47
|
+
begin
|
48
|
+
self.status_codes.fetch(error)
|
49
|
+
rescue StandardError => e
|
50
|
+
$log.error(sprintf("%s: %i is not a valid error code\n", __method__, error))
|
51
|
+
raise
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/surveymonkey/request.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'surveymonkey/logging'
|
2
2
|
require 'surveymonkey/api'
|
3
3
|
require 'surveymonkey/client'
|
4
|
+
require 'surveymonkey/error'
|
4
5
|
|
5
6
|
##
|
6
7
|
# Object representing a request to the SurveyMonkey API. Parameters should all be populated automatically.
|
@@ -46,7 +47,15 @@ class Surveymonkey::Request
|
|
46
47
|
$log.debug(sprintf("%s: response code %i\n", __method__, response.code))
|
47
48
|
$log.debug(sprintf("%s: response headers '%s'\n", __method__, response.headers.inspect))
|
48
49
|
|
49
|
-
response.parsed_response
|
50
|
+
parsed = response.parsed_response
|
51
|
+
status = parsed.fetch('status')
|
52
|
+
|
53
|
+
if status == 0
|
54
|
+
parsed
|
55
|
+
else
|
56
|
+
$log.debug(sprintf("%s: API returned status %i\n", __method__, status))
|
57
|
+
raise Surveymonkey::Error.new(parsed)
|
58
|
+
end
|
50
59
|
|
51
60
|
rescue StandardError => e
|
52
61
|
$log.error(sprintf("%s: unable to execute API request: %s\n", __method__, e.message))
|
data/lib/surveymonkey/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: surveymonkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Huff
|
@@ -158,6 +158,7 @@ files:
|
|
158
158
|
- lib/surveymonkey/api.rb
|
159
159
|
- lib/surveymonkey/api/method.rb
|
160
160
|
- lib/surveymonkey/client.rb
|
161
|
+
- lib/surveymonkey/error.rb
|
161
162
|
- lib/surveymonkey/logging.rb
|
162
163
|
- lib/surveymonkey/request.rb
|
163
164
|
- lib/surveymonkey/version.rb
|