surveymonkey 0.4.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/surveymonkey.rb +8 -8
- data/lib/surveymonkey/api.rb +11 -11
- data/lib/surveymonkey/api/method.rb +2 -3
- data/lib/surveymonkey/client.rb +7 -8
- data/lib/surveymonkey/error.rb +3 -3
- data/lib/surveymonkey/request.rb +77 -40
- data/lib/surveymonkey/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01090e5bb2cc9905f723fc8cd3ba440b0d7557bf
|
4
|
+
data.tar.gz: 800fa9a973a283ba9dd36053a88c6bdc66eb2285
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f75ee597a09ad0fab36c1a15063abef4dda45d0c6e0ccf0a8442076c6e7778ebb8666809643cdfb381f2f67060f8618bf0d809f8ba3d486cfbd730f14e4b4bc5
|
7
|
+
data.tar.gz: bdc3c2d2e98e212bc4671edf973c274d58e4eacbf30c341fe468a689ae59f4c97dabb1e0182430ca78cc33c807a340fff2d02e72285ab443c044dbaa1b3cc0e7
|
data/lib/surveymonkey.rb
CHANGED
@@ -38,16 +38,16 @@ module Surveymonkey
|
|
38
38
|
|
39
39
|
def method_missing(method_name, *args)
|
40
40
|
begin
|
41
|
-
$log.debug sprintf("%s: %s
|
41
|
+
$log.debug sprintf("%s: %s", __method__, 'enter')
|
42
42
|
|
43
43
|
the_args = Hash(Array(args).shift) || {}
|
44
44
|
|
45
45
|
# extract page_size if passed in args
|
46
46
|
page_size = the_args.delete('page_size') { |key| DefaultPageSize }.to_i
|
47
|
-
$log.debug sprintf("%s: page_size: %i
|
47
|
+
$log.debug sprintf("%s: page_size: %i", __method__, page_size)
|
48
48
|
|
49
49
|
method_params = the_args
|
50
|
-
$log.debug sprintf("%s: method_params: %s
|
50
|
+
$log.debug sprintf("%s: method_params: %s", __method__, method_params.inspect)
|
51
51
|
|
52
52
|
# is this a paginated method?
|
53
53
|
pagination_field = PaginatedMethods.fetch(method_name, nil)
|
@@ -60,15 +60,15 @@ module Surveymonkey
|
|
60
60
|
end
|
61
61
|
|
62
62
|
rescue TypeError => e
|
63
|
-
$log.fatal sprintf("%s: method parameters must be a hash
|
63
|
+
$log.fatal sprintf("%s: method parameters must be a hash", __method__)
|
64
64
|
exit 1
|
65
65
|
|
66
66
|
rescue KeyError => e
|
67
|
-
$log.fatal sprintf("%s: method '%s' not implemented
|
67
|
+
$log.fatal sprintf("%s: method '%s' not implemented", __method__, method_name.to_s)
|
68
68
|
exit 1
|
69
69
|
|
70
70
|
rescue StandardError => e
|
71
|
-
$log.error sprintf("%s: %s
|
71
|
+
$log.error sprintf("%s: %s", __method__, e.message)
|
72
72
|
raise e
|
73
73
|
|
74
74
|
end
|
@@ -124,7 +124,7 @@ module Surveymonkey
|
|
124
124
|
raise e
|
125
125
|
|
126
126
|
rescue StandardError => e
|
127
|
-
$log.error(sprintf("%s: %s
|
127
|
+
$log.error(sprintf("%s: %s", __method__, e.message))
|
128
128
|
raise e
|
129
129
|
|
130
130
|
end
|
@@ -139,7 +139,7 @@ module Surveymonkey
|
|
139
139
|
Surveymonkey::Request.new(method_name.to_s, {'method_params' => method_params}).execute
|
140
140
|
|
141
141
|
rescue StandardError => e
|
142
|
-
$log.error sprintf("%s: %s
|
142
|
+
$log.error sprintf("%s: %s", __method__, e.message)
|
143
143
|
raise e
|
144
144
|
|
145
145
|
end
|
data/lib/surveymonkey/api.rb
CHANGED
@@ -61,24 +61,24 @@ class Surveymonkey::API
|
|
61
61
|
|
62
62
|
def api_method(key, api_methods = self.api_methods)
|
63
63
|
begin
|
64
|
-
$log.debug(sprintf("%s: api methods: %s
|
65
|
-
$log.debug(sprintf("%s: fetching '%s' from API methods
|
64
|
+
$log.debug(sprintf("%s: api methods: %s", __method__, api_methods.inspect))
|
65
|
+
$log.debug(sprintf("%s: fetching '%s' from API methods", __method__, key))
|
66
66
|
value = api_methods.fetch(key)
|
67
|
-
$log.debug(sprintf("%s: retrieved '%s'
|
67
|
+
$log.debug(sprintf("%s: retrieved '%s'", __method__, value.inspect))
|
68
68
|
|
69
69
|
path = value['path']
|
70
|
-
$log.debug(sprintf("%s: path '%s'
|
70
|
+
$log.debug(sprintf("%s: path '%s'", __method__, path))
|
71
71
|
method = (value['method'] || 'post')
|
72
|
-
$log.debug(sprintf("%s: method '%s'
|
72
|
+
$log.debug(sprintf("%s: method '%s'", __method__, method))
|
73
73
|
|
74
74
|
# return
|
75
75
|
Surveymonkey::API::Method.new(path, method, method_name = key)
|
76
76
|
|
77
77
|
rescue KeyError => e
|
78
|
-
$log.error(sprintf("%s: '%s' not found in api methods
|
78
|
+
$log.error(sprintf("%s: '%s' not found in api methods", __method__, key))
|
79
79
|
raise e
|
80
80
|
rescue StandardError => e
|
81
|
-
$log.error(sprintf("%s: %s
|
81
|
+
$log.error(sprintf("%s: %s", __method__, e.message))
|
82
82
|
raise
|
83
83
|
end
|
84
84
|
end
|
@@ -91,15 +91,15 @@ class Surveymonkey::API
|
|
91
91
|
def api_method_params(method_params)
|
92
92
|
begin
|
93
93
|
# TODO validate params against API spec
|
94
|
-
$log.debug(sprintf("%s: parsing api method params from '%s'
|
94
|
+
$log.debug(sprintf("%s: parsing api method params from '%s'", __method__, method_params))
|
95
95
|
the_params = (method_params.kind_of?(String) ? method_params : JSON.generate(method_params || {}))
|
96
|
-
$log.debug(sprintf("%s: parsed method params '%s'
|
96
|
+
$log.debug(sprintf("%s: parsed method params '%s'", __method__, the_params))
|
97
97
|
|
98
98
|
# return
|
99
99
|
the_params
|
100
100
|
|
101
101
|
rescue StandardError => e
|
102
|
-
$log.error(sprintf("%s: %s
|
102
|
+
$log.error(sprintf("%s: %s", __method__, e.message))
|
103
103
|
raise
|
104
104
|
end
|
105
105
|
end
|
@@ -114,7 +114,7 @@ class Surveymonkey::API
|
|
114
114
|
@api_methods = Api_methods
|
115
115
|
@api_version = Api_version
|
116
116
|
rescue StandardError => e
|
117
|
-
$log.error(sprintf("%s: %s
|
117
|
+
$log.error(sprintf("%s: %s", __method__, e.message))
|
118
118
|
raise
|
119
119
|
end
|
120
120
|
end
|
@@ -21,9 +21,8 @@ class Surveymonkey::API::Method
|
|
21
21
|
@method_name = method_name.to_s
|
22
22
|
|
23
23
|
# validate the method
|
24
|
-
$log.debug(sprintf("%s:http_method: '%s'\n", __method__, http_method))
|
25
24
|
the_method = http_method.to_s.downcase
|
26
|
-
$log.debug(sprintf("%s:the_method: '%s'
|
25
|
+
$log.debug(sprintf("%s: the_method: '%s' (was '%s')", __method__, the_method, http_method))
|
27
26
|
|
28
27
|
if the_method =~ /^(get|post|patch|put|delete|move|copy|head|options)$/
|
29
28
|
@http_method = the_method
|
@@ -33,7 +32,7 @@ class Surveymonkey::API::Method
|
|
33
32
|
end
|
34
33
|
|
35
34
|
rescue StandardError => e
|
36
|
-
$log.error(sprintf("%s: unable to initialize API method: %s
|
35
|
+
$log.error(sprintf("%s: unable to initialize API method: %s", __method__, e.message))
|
37
36
|
raise
|
38
37
|
end
|
39
38
|
end
|
data/lib/surveymonkey/client.rb
CHANGED
@@ -30,16 +30,15 @@ class Surveymonkey::Client
|
|
30
30
|
|
31
31
|
self.class.logger $log, :debug
|
32
32
|
|
33
|
-
$log.debug(sprintf("%s: setting base_uri to '%s'
|
33
|
+
$log.debug(sprintf("%s: setting base_uri to '%s'", __method__, @baseuri))
|
34
34
|
self.class.base_uri @baseuri
|
35
35
|
|
36
|
-
$log.debug(sprintf("%s: setting headers'\n", __method__))
|
37
36
|
http_headers = _http_headers(@access_token)
|
38
37
|
self.class.headers http_headers
|
39
38
|
|
40
39
|
rescue StandardError => e
|
41
|
-
$log.error(sprintf("%s: %s
|
42
|
-
raise
|
40
|
+
$log.error(sprintf("%s: %s", __method__, e.message))
|
41
|
+
raise e
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
@@ -55,17 +54,17 @@ class Surveymonkey::Client
|
|
55
54
|
|
56
55
|
def _http_headers(token) #:nodoc:
|
57
56
|
begin
|
58
|
-
$log.debug(sprintf("%s: constructing http headers with token '%s'
|
57
|
+
$log.debug(sprintf("%s: constructing http headers with token '%s'", __method__, token))
|
59
58
|
http_headers = {
|
60
59
|
"Content-Type" => "application/json",
|
61
60
|
"Authorization" => sprintf("bearer %s", token),
|
62
61
|
}
|
63
|
-
$log.debug(sprintf("%s: http headers: '%s'
|
62
|
+
$log.debug(sprintf("%s: http headers: '%s'", __method__, http_headers))
|
64
63
|
http_headers
|
65
64
|
|
66
65
|
rescue StandardError => e
|
67
|
-
$log.error(sprintf("%s: %s
|
68
|
-
raise
|
66
|
+
$log.error(sprintf("%s: %s", __method__, e.message))
|
67
|
+
raise e
|
69
68
|
end
|
70
69
|
end
|
71
70
|
|
data/lib/surveymonkey/error.rb
CHANGED
@@ -29,8 +29,8 @@ class Surveymonkey::Error < StandardError
|
|
29
29
|
@status_name = _status_name(@status)
|
30
30
|
|
31
31
|
rescue StandardError => e
|
32
|
-
$log.error(sprintf("%s: unable to parse '%s' as error
|
33
|
-
raise
|
32
|
+
$log.error(sprintf("%s: unable to parse '%s' as error", __method__, error.inspect))
|
33
|
+
raise e
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -47,7 +47,7 @@ class Surveymonkey::Error < StandardError
|
|
47
47
|
begin
|
48
48
|
self.status_codes.fetch(error)
|
49
49
|
rescue StandardError => e
|
50
|
-
$log.error(sprintf("%s: %i is not a valid error code
|
50
|
+
$log.error(sprintf("%s: %i is not a valid error code", __method__, error))
|
51
51
|
raise
|
52
52
|
end
|
53
53
|
end
|
data/lib/surveymonkey/request.rb
CHANGED
@@ -26,40 +26,58 @@ class Surveymonkey::Request
|
|
26
26
|
|
27
27
|
def execute(method_params = self.method_params, api_method = self.api_method, api_key = self.api_key, access_token = self.access_token)
|
28
28
|
begin
|
29
|
-
$log.debug(sprintf("%s: enter
|
29
|
+
$log.debug(sprintf("%s: enter", __method__))
|
30
|
+
|
31
|
+
method_logname = sprintf("%s[%s]", __method__, api_method)
|
30
32
|
|
31
33
|
self.method_params=(self.api.api_method_params(method_params))
|
32
34
|
method_params = self.method_params
|
33
|
-
$log.debug(sprintf("%s: method_params: %s
|
35
|
+
$log.debug(sprintf("%s: method_params: %s", method_logname, method_params))
|
34
36
|
|
35
37
|
path = api_method.path
|
36
|
-
$log.debug(sprintf("%s: path: %s
|
38
|
+
$log.debug(sprintf("%s: path: %s", method_logname, path))
|
37
39
|
|
38
40
|
http_method = api_method.http_method
|
39
|
-
$log.debug(sprintf("%s: http_method: %s
|
41
|
+
$log.debug(sprintf("%s: http_method: %s", method_logname, http_method))
|
40
42
|
|
41
43
|
request_uri = _request_uri(path, api_key)
|
42
|
-
$log.debug(sprintf("%s: ready to make request for '%s'
|
44
|
+
$log.debug(sprintf("%s: ready to make request for '%s'", method_logname, api_method))
|
43
45
|
|
44
46
|
response = self.client.class.send(http_method.to_sym, request_uri, body: self.method_params)
|
45
47
|
|
46
|
-
$log.debug(sprintf("%s: response class %s
|
47
|
-
$log.debug(sprintf("%s: response
|
48
|
-
|
48
|
+
$log.debug(sprintf("%s: response class %s code %i", method_logname, response.class, response.code))
|
49
|
+
$log.debug(sprintf("%s: response headers '%s'", method_logname, response.headers.inspect))
|
50
|
+
|
51
|
+
if _valid_response?(response)
|
52
|
+
parsed = response.parsed_response
|
53
|
+
status = parsed.fetch('status')
|
54
|
+
$log.debug(sprintf("%s: API returned status %i", method_logname, status))
|
49
55
|
|
50
|
-
|
51
|
-
|
56
|
+
if status == 0
|
57
|
+
$log.debug(sprintf("%s: raw data: %s", method_logname, response.body.to_s))
|
58
|
+
$log.debug(sprintf("%s: parsed data: %s", method_logname, parsed.fetch('data', []).inspect))
|
59
|
+
parsed
|
60
|
+
else
|
61
|
+
raise Surveymonkey::Error.new(parsed)
|
62
|
+
end
|
52
63
|
|
53
|
-
if status == 0
|
54
|
-
parsed
|
55
64
|
else
|
56
|
-
$log.
|
57
|
-
|
65
|
+
$log.error sprintf("%s: API returned invalid HTTP response code from '%s'", method_logname, self)
|
66
|
+
|
67
|
+
mashery_error_code = $response.headers.fetch('x-mashery-error-code', 'UNKNOWN')
|
68
|
+
error_detail_header = $response.headers.fetch('x-error-detail-header', 'Unknown')
|
69
|
+
|
70
|
+
the_error = {
|
71
|
+
'status' => 3,
|
72
|
+
'errmsg' => sprintf("%s (%s)", mashery_error_code, error_detail_header)
|
73
|
+
}
|
74
|
+
raise Surveymonkey::Error.new(the_error)
|
58
75
|
end
|
59
76
|
|
60
77
|
rescue StandardError => e
|
61
|
-
$log.error
|
62
|
-
|
78
|
+
$log.error sprintf("%s: unable to execute API request: %s", method_logname, self)
|
79
|
+
$log.debug sprintf("%s: response: %s", method_logname, parsed.inspect)
|
80
|
+
raise e
|
63
81
|
end
|
64
82
|
end
|
65
83
|
|
@@ -73,9 +91,9 @@ class Surveymonkey::Request
|
|
73
91
|
|
74
92
|
def initialize(api_method, *args)
|
75
93
|
begin
|
76
|
-
$log.debug(sprintf("%s: enter
|
77
|
-
$log.debug(sprintf("%s: api_method: %s
|
78
|
-
$log.debug(sprintf("%s: args: %s
|
94
|
+
$log.debug(sprintf("%s: enter", __method__))
|
95
|
+
$log.debug(sprintf("%s: api_method: %s", __method__, api_method))
|
96
|
+
$log.debug(sprintf("%s: args: %s", __method__, args))
|
79
97
|
|
80
98
|
# store the API method name for stringification
|
81
99
|
@method_name = api_method
|
@@ -97,7 +115,7 @@ class Surveymonkey::Request
|
|
97
115
|
@api = Surveymonkey::API.new
|
98
116
|
|
99
117
|
rescue StandardError => e
|
100
|
-
$log.error(sprintf("%s: unable to initialize API request: %s
|
118
|
+
$log.error(sprintf("%s: unable to initialize API request: %s", __method__, e.message))
|
101
119
|
raise
|
102
120
|
end
|
103
121
|
end
|
@@ -107,7 +125,7 @@ class Surveymonkey::Request
|
|
107
125
|
#
|
108
126
|
|
109
127
|
def to_s
|
110
|
-
self.
|
128
|
+
sprintf("%s %s", self.api_method, self.method_params.inspect)
|
111
129
|
end
|
112
130
|
|
113
131
|
|
@@ -118,8 +136,8 @@ class Surveymonkey::Request
|
|
118
136
|
begin
|
119
137
|
@client = Surveymonkey::Client.new()
|
120
138
|
rescue StandardError => e
|
121
|
-
$log.fatal(sprintf("%s: %s
|
122
|
-
$log.debug(sprintf("%s: %s
|
139
|
+
$log.fatal(sprintf("%s: %s", "Unable to initialize REST client", e.message))
|
140
|
+
$log.debug(sprintf("%s: %s", __method__, e))
|
123
141
|
raise
|
124
142
|
end
|
125
143
|
end
|
@@ -128,53 +146,72 @@ class Surveymonkey::Request
|
|
128
146
|
begin
|
129
147
|
@api = Surveymonkey::API.new()
|
130
148
|
rescue StandardError => e
|
131
|
-
$log.fatal(sprintf("%s: %s
|
132
|
-
$log.debug(sprintf("%s: %s
|
149
|
+
$log.fatal(sprintf("%s: %s", "Unable to initialize SurveyMonkey API", e.message))
|
150
|
+
$log.debug(sprintf("%s: %s", __method__, e))
|
133
151
|
raise
|
134
152
|
end
|
135
153
|
end
|
136
154
|
|
137
155
|
def _http_headers(token) #:nodoc:
|
138
156
|
begin
|
139
|
-
$log.debug(sprintf("%s: constructing http headers with token '%s'
|
157
|
+
$log.debug(sprintf("%s: constructing http headers with token '%s'", __method__, token))
|
140
158
|
http_headers = {
|
141
159
|
"Content-Type" => "application/json",
|
142
160
|
"Authorization" => sprintf("bearer %s", token),
|
143
161
|
}
|
144
|
-
$log.debug(sprintf("%s: http headers: '%s'
|
162
|
+
$log.debug(sprintf("%s: http headers: '%s'", __method__, http_headers))
|
145
163
|
http_headers
|
146
164
|
|
147
|
-
rescue
|
148
|
-
$log.error(sprintf("%s: %s
|
149
|
-
raise
|
165
|
+
rescue StandardError => e
|
166
|
+
$log.error(sprintf("%s: %s", __method__, e.message))
|
167
|
+
raise e
|
150
168
|
end
|
151
169
|
end
|
152
170
|
|
153
171
|
def _from_env(key) #:nodoc:
|
154
172
|
begin
|
155
|
-
$log.debug(sprintf("%s: fetching '%s' from environment
|
173
|
+
$log.debug(sprintf("%s: fetching '%s' from environment", __method__, key))
|
156
174
|
value = ENV.fetch(key)
|
157
|
-
$log.debug(sprintf("%s: retrieved '%s'
|
175
|
+
$log.debug(sprintf("%s: retrieved '%s'", __method__, value))
|
158
176
|
value
|
159
177
|
|
160
178
|
rescue KeyError => e
|
161
|
-
$log.info(sprintf("%s: '%s' not found in environment
|
162
|
-
rescue
|
163
|
-
$log.error(sprintf("%s: %s
|
164
|
-
raise
|
179
|
+
$log.info(sprintf("%s: '%s' not found in environment", __method__, key))
|
180
|
+
rescue StandardError => e
|
181
|
+
$log.error(sprintf("%s: %s", __method__, e.message))
|
182
|
+
raise e
|
165
183
|
end
|
166
184
|
end
|
167
185
|
|
168
186
|
def _request_uri(path, api_key) #:nodoc:
|
169
187
|
begin
|
170
|
-
$log.debug(sprintf("%s: generating request uri fragment from '%s' and '%s'
|
188
|
+
$log.debug(sprintf("%s: generating request uri fragment from '%s' and '%s'", __method__, path, api_key))
|
171
189
|
request_uri = sprintf("%s?api_key=%s", path, api_key)
|
172
|
-
$log.debug(sprintf("%s: generated '%s'
|
190
|
+
$log.debug(sprintf("%s: generated '%s'", __method__, request_uri))
|
173
191
|
request_uri
|
174
192
|
|
175
193
|
rescue StandardError => e
|
176
|
-
$log.error(sprintf("%s: %s
|
177
|
-
raise
|
194
|
+
$log.error(sprintf("%s: %s", __method__, e.message))
|
195
|
+
raise e
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def _valid_response?(response) #:nodoc:
|
200
|
+
begin
|
201
|
+
code = response.code
|
202
|
+
$log.debug sprintf("%s: HTTP response code is %i", __method__, code)
|
203
|
+
# this claims to raise an exception if the response is not a 2XX
|
204
|
+
response.value
|
205
|
+
|
206
|
+
code
|
207
|
+
|
208
|
+
rescue Net::HTTPError => e
|
209
|
+
$log.error sprintf("%s: HTTP error: %s", __method__, e.message)
|
210
|
+
return nil
|
211
|
+
|
212
|
+
rescue StandardError => e
|
213
|
+
$log.error(sprintf("%s: %s", __method__, e.message))
|
214
|
+
raise e
|
178
215
|
end
|
179
216
|
end
|
180
217
|
end
|
data/lib/surveymonkey/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: surveymonkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Huff
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|