surveymonkey 0.4.2 → 0.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01090e5bb2cc9905f723fc8cd3ba440b0d7557bf
4
- data.tar.gz: 800fa9a973a283ba9dd36053a88c6bdc66eb2285
3
+ metadata.gz: 3d2814fc1738a375a5877e74006dd10d1070c862
4
+ data.tar.gz: 20e69559cdf751d6b6d90cdda9e9782f46fc124e
5
5
  SHA512:
6
- metadata.gz: f75ee597a09ad0fab36c1a15063abef4dda45d0c6e0ccf0a8442076c6e7778ebb8666809643cdfb381f2f67060f8618bf0d809f8ba3d486cfbd730f14e4b4bc5
7
- data.tar.gz: bdc3c2d2e98e212bc4671edf973c274d58e4eacbf30c341fe468a689ae59f4c97dabb1e0182430ca78cc33c807a340fff2d02e72285ab443c044dbaa1b3cc0e7
6
+ metadata.gz: c080bd3a46005a2b4f5a9aaaf48f7a8aca9ac7dc74111228056cce8a96117545c6831d1219fdd95894d58dde542ff6603a4df8afe140cf6de6515ff2ced3c15c
7
+ data.tar.gz: 5b6eb53aa49367fd987fa50e55bc8fa7aa19903b1e35a627b2db5af3a2f229b1f964b624470173301dd5c9007936404ee85e70dc8b9f91421010ed8f2777210d
@@ -5,6 +5,7 @@ require "surveymonkey/version"
5
5
  require "surveymonkey/logging"
6
6
  require "surveymonkey/error"
7
7
  require "surveymonkey/request"
8
+ require "surveymonkey/datestring"
8
9
 
9
10
  ##
10
11
  # Top-level module, holds the user-facing methods
@@ -46,7 +47,7 @@ module Surveymonkey
46
47
  page_size = the_args.delete('page_size') { |key| DefaultPageSize }.to_i
47
48
  $log.debug sprintf("%s: page_size: %i", __method__, page_size)
48
49
 
49
- method_params = the_args
50
+ method_params = parse_datestrings(the_args)
50
51
  $log.debug sprintf("%s: method_params: %s", __method__, method_params.inspect)
51
52
 
52
53
  # is this a paginated method?
@@ -130,6 +131,31 @@ module Surveymonkey
130
131
  end
131
132
  end
132
133
 
134
+ ##
135
+ # Parse and validate DateStrings in method parameters
136
+ def parse_datestrings(method_params = {}) # :nodoc:
137
+ begin
138
+ ['start_date', 'end_date'].each do |date_param|
139
+ if method_params.has_key?(date_param)
140
+ raw = method_params.fetch(date_param)
141
+ $log.debug(sprintf("%s: parsing '%s' as %s param", __method__, raw, date_param))
142
+
143
+ parsed = Surveymonkey::DateString.new(raw).to_s
144
+ $log.debug(sprintf("%s: parsed '%s' to '%s'", __method__, raw, parsed))
145
+
146
+ method_params.store(date_param, parsed)
147
+ end
148
+ end
149
+
150
+ method_params
151
+
152
+ rescue StandardError => e
153
+ $log.error(sprintf("%s: %s", __method__, e.message))
154
+ raise e
155
+
156
+ end
157
+ end
158
+
133
159
  ##
134
160
  # Execute a single API request.
135
161
  def execute_request(method_name, method_params = {}) # :nodoc:
@@ -0,0 +1,63 @@
1
+ require "timeliness"
2
+
3
+ require "surveymonkey/logging"
4
+
5
+ module Surveymonkey
6
+ class DateString
7
+ attr_reader :raw
8
+ attr_reader :time
9
+
10
+ # SurveyMonkey DateStrings are always in UTC
11
+ Timeliness.default_timezone = :utc
12
+
13
+ # and have a specific format
14
+ TimelinessFormat = 'yyyy-mm-dd hh:nn:ss'
15
+
16
+ # but for stringification we have to use strftime format
17
+ TimeFormat = '%Y-%m-%d %H:%M:%S'
18
+
19
+ def to_s
20
+ self.time.strftime(TimeFormat)
21
+ end
22
+
23
+ def <=>(other)
24
+ self.time.<=>(other)
25
+ end
26
+
27
+ def initialize(datestring, args = {})
28
+ begin
29
+ $log.debug(sprintf("%s: parsing '%s'", __method__, datestring))
30
+
31
+ @raw = datestring
32
+
33
+ timeliness_args = { :format => TimelinessFormat }
34
+
35
+ # merge additional args if provided
36
+ begin
37
+ timeliness_args.merge(args)
38
+ rescue TypeError => e
39
+ $log.error(sprintf("%s: '%s' (%s) is not a valid arguments hash", __method__, args.inspect, args.class))
40
+ end
41
+
42
+ parsed = Timeliness.parse(datestring, timeliness_args)
43
+
44
+ if parsed.nil?
45
+ # add a time component and try again
46
+ $log.info(sprintf("%s: '%s' cannot be parsed as a datetime, adding a time component", __method__, datestring))
47
+ datestring.concat(' 00:00:00')
48
+ parsed = Timeliness.parse(datestring, timeliness_args)
49
+ end
50
+
51
+ if parsed.nil?
52
+ raise StandardError, sprintf("'%s' is not a valid DateString", datestring)
53
+ else
54
+ @time = parsed
55
+ end
56
+
57
+ rescue StandardError => e
58
+ $log.error(sprintf("%s: unable to parse '%s' as DateString", __method__, datestring))
59
+ raise e
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,14 @@
1
+ require 'date'
2
+
3
+ module Surveymonkey::DateTime
4
+
5
+ # Constants
6
+
7
+ ## Offset
8
+ # Default offset from UTC (all SurveyMonkey DateStrings are in UTC)
9
+ Offset = 0
10
+
11
+ class DateString
12
+
13
+ end
14
+ end
@@ -2,5 +2,5 @@
2
2
  # Specify the version of the surveymonkey gem.
3
3
 
4
4
  module Surveymonkey
5
- VERSION = "0.4.2"
5
+ VERSION = "0.4.3"
6
6
  end
@@ -32,4 +32,5 @@ Gem::Specification.new do |spec|
32
32
  spec.add_runtime_dependency "httparty", "~> 0.13"
33
33
  spec.add_runtime_dependency "json", "~> 1.8"
34
34
  spec.add_runtime_dependency "logging", "~> 2"
35
+ spec.add_runtime_dependency "timeliness", "~> 0.3"
35
36
  end
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.2
4
+ version: 0.4.3
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-06-17 00:00:00.000000000 Z
11
+ date: 2015-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ~>
151
151
  - !ruby/object:Gem::Version
152
152
  version: '2'
153
+ - !ruby/object:Gem::Dependency
154
+ name: timeliness
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ~>
158
+ - !ruby/object:Gem::Version
159
+ version: '0.3'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ~>
165
+ - !ruby/object:Gem::Version
166
+ version: '0.3'
153
167
  description: Interact with SurveyMonkey's REST API. Requires an API token.
154
168
  email:
155
169
  - shuff@vecna.org
@@ -172,6 +186,8 @@ files:
172
186
  - lib/surveymonkey/api.rb
173
187
  - lib/surveymonkey/api/method.rb
174
188
  - lib/surveymonkey/client.rb
189
+ - lib/surveymonkey/datestring.rb
190
+ - lib/surveymonkey/datetime.rb
175
191
  - lib/surveymonkey/error.rb
176
192
  - lib/surveymonkey/logging.rb
177
193
  - lib/surveymonkey/request.rb