poptart 0.0.9 → 0.0.10

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: 9562c2a9cbf777cce16a855129ecbdeeb6de4446
4
- data.tar.gz: 9172f17c4db0b7f8a0ef1d5ea773d051f2c47eb8
3
+ metadata.gz: bfdbd0d66b974cabcf6e62b2df97b1e8017f3ccc
4
+ data.tar.gz: 7d33626b2410a15a1d33a49455846131ce25a5e4
5
5
  SHA512:
6
- metadata.gz: 1cc2c2527997928f3011d9939919277387e6c7c0844d5fdb0366dcf804f5e9ba1f6365eadd77653a93111ec21d8acf3fb619776d85e9567607cddf4387ecf3ab
7
- data.tar.gz: b66de0f765cb2302d86f7018f4e53661c61b8f6e7af0d4cf82d5cfcdb133e03edacc2923c67823c669da7278414ed141ba17fa926e0637e1bf16ee16d17da786
6
+ metadata.gz: a6ecfbc52ffb2defa46563ebe922aa3af6fb0b6e6e8ad140c40d307d034c40245daf2913f6e880f57998f51ef8eba0aa2740b2f2a478cfe929ce74b0db2f5f41
7
+ data.tar.gz: f723bb03523ad36b01100504f443bc8ecfb9a74c314a1720a98f095356ec93bf81b21656ec5a5021a9f959cd92aa522788877886f060a4642931768d9984b638
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- poptart (0.0.8)
4
+ poptart (0.0.10)
5
5
  activesupport
6
6
  addressable
7
7
  faraday
@@ -2,9 +2,9 @@ module Poptart
2
2
  class BooleanQuestion < Question
3
3
  extend Poptart::Request
4
4
 
5
- def self.create(text, freeform: false, absolute_index: nil, parent_question_id: nil)
5
+ def self.create(text, freeform: false, absolute_index: nil, parent_question_id: nil, key: nil)
6
6
  super(text, responses: [true, false], freeform: freeform,
7
- absolute_index: absolute_index, parent_question_id: parent_question_id)
7
+ absolute_index: absolute_index, parent_question_id: parent_question_id, key: key)
8
8
  end
9
9
 
10
10
  def self.question_type
@@ -2,7 +2,7 @@ module Poptart
2
2
  class Question < Model
3
3
  extend Poptart::Request
4
4
 
5
- attr_accessor :responses, :freeform, :question_type, :absolute_index, :parent_question_id
5
+ attr_accessor :responses, :freeform, :question_type, :absolute_index, :parent_question_id, :key
6
6
 
7
7
  def initialize(response)
8
8
  super
@@ -11,15 +11,17 @@ module Poptart
11
11
  @question_type = params['question_type']
12
12
  @absolute_index = params['absolute_index']
13
13
  @parent_question_id = params['parent_question_id']
14
+ @key = params['key']
14
15
  end
15
16
 
16
- def self.create(text, responses: [], freeform: false, absolute_index: nil, parent_question_id: nil)
17
+ def self.create(text, responses: [], freeform: false, absolute_index: nil, parent_question_id: nil, key: nil)
17
18
  response = post(root.questions_url, question: { question_type: question_type,
18
19
  responses: responses,
19
20
  text: text,
20
21
  freeform: freeform,
21
22
  absolute_index: absolute_index,
22
- parent_question_id: parent_question_id })
23
+ parent_question_id: parent_question_id,
24
+ key: key})
23
25
  new(response)
24
26
  end
25
27
 
@@ -12,6 +12,7 @@ module Poptart
12
12
  @freeform = params['freeform']
13
13
  @responses = params['responses']
14
14
  @answer = params['answer']
15
+ @created_at = params['created_at']
15
16
 
16
17
  if @answer == 't'
17
18
  @answer = true
@@ -40,6 +41,10 @@ module Poptart
40
41
  @freeform == true
41
42
  end
42
43
 
44
+ def created_at
45
+ DateTime.parse(@created_at)
46
+ end
47
+
43
48
  def submit
44
49
  response = put(links.put.href, { id: id, survey_question: { answer: answer} })
45
50
  response.status == 204
data/lib/poptart/user.rb CHANGED
@@ -43,5 +43,9 @@ module Poptart
43
43
  response = get(url)
44
44
  JSON.parse(response.body)["survey_questions"].map { |response_body| Poptart::SurveyQuestion.new(response_body) }
45
45
  end
46
+
47
+ def survey_questions_for_key(key)
48
+ survey_questions_for_question_id(key)
49
+ end
46
50
  end
47
51
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Poptart
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -19,4 +19,24 @@ describe 'retrieving answers' do
19
19
  survey_questions = user.survey_questions_for_question_id(question.id)
20
20
  survey_questions.map(&:answer).should =~ [true, false]
21
21
  end
22
+
23
+ it "returns all answered survey questions for a question by key", :vcr do
24
+ key = 'testingooptarts'
25
+ question = Poptart::BooleanQuestion.create("Do you like poptarts?", key: key)
26
+ user = Poptart::User.create
27
+
28
+ survey = user.create_survey
29
+ first_survey_question = survey.add_question(question)
30
+ second_survey = user.create_survey
31
+ second_survey_question = second_survey.add_question(question)
32
+
33
+ first_survey_question.answer = true
34
+ first_survey_question.submit.should be
35
+
36
+ second_survey_question.answer = false
37
+ second_survey_question.submit.should be
38
+
39
+ survey_questions = user.survey_questions_for_key(key)
40
+ survey_questions.map(&:answer).should =~ [true, false]
41
+ end
22
42
  end
@@ -2,13 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe 'creating quesitons' do
4
4
  it 'returns boolean question', :vcr do
5
- question = Poptart::BooleanQuestion.create("Do you like poptarts?", freeform: true, absolute_index: 10, parent_question_id: 42)
5
+ question = Poptart::BooleanQuestion.create("Do you like poptarts?", freeform: true, absolute_index: 10, parent_question_id: 42, key: 'poptarts')
6
6
  question.should be
7
7
  question.question_type.should == 'boolean'
8
8
  question.responses.should =~ [true, false]
9
9
  question.absolute_index.should == 10
10
10
  question.parent_question_id.should == 42
11
11
  question.freeform?.should be
12
+ question.key.should == 'poptarts'
12
13
  end
13
14
 
14
15
  it 'returns multiple question', :vcr do
@@ -21,7 +22,7 @@ describe 'creating quesitons' do
21
22
 
22
23
  it 'returns range question', :vcr do
23
24
  responses = [0, 10]
24
- question = Poptart::RangeResponseQuestion.create("Do you like poptarts?", responses: responses)
25
+ question = Poptart::RangeQuestion.create("Do you like poptarts?", responses: responses)
25
26
  question.should be
26
27
  question.question_type.should == 'range'
27
28
  question.responses.should =~ [0, 10]
@@ -1,11 +1,12 @@
1
1
  ---
2
2
  http_interactions:
3
3
  - request:
4
- method: get
5
- uri: http://localhost:3000/
4
+ method: post
5
+ uri: http://localhost:3000/api/questions/
6
6
  body:
7
- encoding: US-ASCII
8
- string: ''
7
+ encoding: UTF-8
8
+ string: '{"question":{"question_type":"boolean","responses":[true,false],"text":"Do
9
+ you like poptarts?","freeform":true,"absolute_index":10,"parent_question_id":42}}'
9
10
  headers:
10
11
  User-Agent:
11
12
  - Faraday v0.9.0
@@ -19,8 +20,8 @@ http_interactions:
19
20
  - "*/*"
20
21
  response:
21
22
  status:
22
- code: 200
23
- message: 'OK '
23
+ code: 201
24
+ message: 'Created '
24
25
  headers:
25
26
  X-Frame-Options:
26
27
  - SAMEORIGIN
@@ -33,39 +34,35 @@ http_interactions:
33
34
  Content-Type:
34
35
  - application/json; charset=utf-8
35
36
  Etag:
36
- - '"c4942090acbc96722cba50e4cecfde73"'
37
+ - '"9bb1824fd410009f8953d82200a3a249"'
37
38
  Cache-Control:
38
39
  - max-age=0, private, must-revalidate
39
40
  X-Request-Id:
40
- - 113c8f43-e501-443b-b60b-675bf5686eea
41
+ - 3678c0eb-c31c-436b-af09-c4d82f0bddda
41
42
  X-Runtime:
42
- - '0.004541'
43
+ - '0.007781'
43
44
  Server:
44
45
  - WEBrick/1.3.1 (Ruby/2.1.2/2014-05-08)
45
46
  Date:
46
47
  - Sun, 28 Sep 2014 14:43:00 GMT
47
48
  Content-Length:
48
- - '236'
49
+ - '193'
49
50
  Connection:
50
51
  - Keep-Alive
51
52
  body:
52
53
  encoding: UTF-8
53
54
  string: |-
54
55
  {
55
- "_links": {
56
- "self": {
57
- "href": "http://localhost:3000/"
58
- },
59
- "surveys": {
60
- "href": "api/surveys"
61
- },
62
- "users": {
63
- "href": "api/users"
64
- },
65
- "questions": {
66
- "href": "api/questions"
67
- }
68
- }
56
+ "id": 82,
57
+ "question_type": "boolean",
58
+ "text": "Do you like poptarts?",
59
+ "responses": [
60
+ true,
61
+ false
62
+ ],
63
+ "freeform": true,
64
+ "absolute_index": 10,
65
+ "parent_question_id": 42
69
66
  }
70
67
  http_version:
71
68
  recorded_at: Sun, 28 Sep 2014 14:43:00 GMT
@@ -102,19 +99,19 @@ http_interactions:
102
99
  Content-Type:
103
100
  - application/json; charset=utf-8
104
101
  Etag:
105
- - '"c4942090acbc96722cba50e4cecfde73"'
102
+ - '"2aa11a1ab77b139e58f765299f923a01"'
106
103
  Cache-Control:
107
104
  - max-age=0, private, must-revalidate
108
105
  X-Request-Id:
109
- - ab5f8312-c1d4-4382-bdd6-8520bab6e9e8
106
+ - 7e53c3b0-a044-4cc9-abc0-4793c59a8ed8
110
107
  X-Runtime:
111
- - '0.003987'
108
+ - '0.032272'
112
109
  Server:
113
110
  - WEBrick/1.3.1 (Ruby/2.1.2/2014-05-08)
114
111
  Date:
115
- - Sun, 28 Sep 2014 14:43:00 GMT
112
+ - Wed, 08 Oct 2014 02:15:37 GMT
116
113
  Content-Length:
117
- - '236'
114
+ - '469'
118
115
  Connection:
119
116
  - Keep-Alive
120
117
  body:
@@ -126,25 +123,27 @@ http_interactions:
126
123
  "href": "http://localhost:3000/"
127
124
  },
128
125
  "surveys": {
129
- "href": "api/surveys"
126
+ "href": "http://localhost:3000/api/surveys{/id}{?query*}"
130
127
  },
131
128
  "users": {
132
- "href": "api/users"
129
+ "href": "http://localhost:3000/api/users{/id}{?query*}"
133
130
  },
134
131
  "questions": {
135
- "href": "api/questions"
132
+ "href": "http://localhost:3000/api/questions{/id}{?query*}"
133
+ },
134
+ "survey_questions": {
135
+ "href": "http://localhost:3000/api/questions{/question_id}/survey_questions{?query*}"
136
136
  }
137
137
  }
138
138
  }
139
139
  http_version:
140
- recorded_at: Sun, 28 Sep 2014 14:43:00 GMT
140
+ recorded_at: Wed, 08 Oct 2014 02:15:37 GMT
141
141
  - request:
142
- method: post
143
- uri: http://localhost:3000/api/questions/
142
+ method: get
143
+ uri: http://localhost:3000/
144
144
  body:
145
- encoding: UTF-8
146
- string: '{"question":{"question_type":"boolean","responses":[true,false],"text":"Do
147
- you like poptarts?","freeform":true,"absolute_index":10,"parent_question_id":42}}'
145
+ encoding: US-ASCII
146
+ string: ''
148
147
  headers:
149
148
  User-Agent:
150
149
  - Faraday v0.9.0
@@ -158,8 +157,8 @@ http_interactions:
158
157
  - "*/*"
159
158
  response:
160
159
  status:
161
- code: 201
162
- message: 'Created '
160
+ code: 200
161
+ message: 'OK '
163
162
  headers:
164
163
  X-Frame-Options:
165
164
  - SAMEORIGIN
@@ -172,45 +171,52 @@ http_interactions:
172
171
  Content-Type:
173
172
  - application/json; charset=utf-8
174
173
  Etag:
175
- - '"9bb1824fd410009f8953d82200a3a249"'
174
+ - '"2aa11a1ab77b139e58f765299f923a01"'
176
175
  Cache-Control:
177
176
  - max-age=0, private, must-revalidate
178
177
  X-Request-Id:
179
- - 3678c0eb-c31c-436b-af09-c4d82f0bddda
178
+ - f3f12516-1a80-478c-9d43-16848831e5c7
180
179
  X-Runtime:
181
- - '0.007781'
180
+ - '0.029369'
182
181
  Server:
183
182
  - WEBrick/1.3.1 (Ruby/2.1.2/2014-05-08)
184
183
  Date:
185
- - Sun, 28 Sep 2014 14:43:00 GMT
184
+ - Wed, 08 Oct 2014 02:16:10 GMT
186
185
  Content-Length:
187
- - '193'
186
+ - '469'
188
187
  Connection:
189
188
  - Keep-Alive
190
189
  body:
191
190
  encoding: UTF-8
192
191
  string: |-
193
192
  {
194
- "id": 82,
195
- "question_type": "boolean",
196
- "text": "Do you like poptarts?",
197
- "responses": [
198
- true,
199
- false
200
- ],
201
- "freeform": true,
202
- "absolute_index": 10,
203
- "parent_question_id": 42
193
+ "_links": {
194
+ "self": {
195
+ "href": "http://localhost:3000/"
196
+ },
197
+ "surveys": {
198
+ "href": "http://localhost:3000/api/surveys{/id}{?query*}"
199
+ },
200
+ "users": {
201
+ "href": "http://localhost:3000/api/users{/id}{?query*}"
202
+ },
203
+ "questions": {
204
+ "href": "http://localhost:3000/api/questions{/id}{?query*}"
205
+ },
206
+ "survey_questions": {
207
+ "href": "http://localhost:3000/api/questions{/question_id}/survey_questions{?query*}"
208
+ }
209
+ }
204
210
  }
205
211
  http_version:
206
- recorded_at: Sun, 28 Sep 2014 14:43:00 GMT
212
+ recorded_at: Wed, 08 Oct 2014 02:16:10 GMT
207
213
  - request:
208
214
  method: post
209
215
  uri: http://localhost:3000/api/questions
210
216
  body:
211
217
  encoding: UTF-8
212
218
  string: '{"question":{"question_type":"boolean","responses":[true,false],"text":"Do
213
- you like poptarts?","freeform":true,"absolute_index":10,"parent_question_id":42}}'
219
+ you like poptarts?","freeform":true,"absolute_index":10,"parent_question_id":42,"key":"poptarts"}}'
214
220
  headers:
215
221
  User-Agent:
216
222
  - Faraday v0.9.0
@@ -238,26 +244,26 @@ http_interactions:
238
244
  Content-Type:
239
245
  - application/json; charset=utf-8
240
246
  Etag:
241
- - '"3130a99e318b2e14b38856d2053fffc7"'
247
+ - '"5df8e0fd01cd48f8c251e4b1420d0070"'
242
248
  Cache-Control:
243
249
  - max-age=0, private, must-revalidate
244
250
  X-Request-Id:
245
- - 021a1834-9370-4af6-bf2e-80cf242e039f
251
+ - d550e167-b88c-4d8b-8180-1d31aa7c99c5
246
252
  X-Runtime:
247
- - '0.009701'
253
+ - '0.022491'
248
254
  Server:
249
255
  - WEBrick/1.3.1 (Ruby/2.1.2/2014-05-08)
250
256
  Date:
251
- - Sun, 05 Oct 2014 12:55:10 GMT
257
+ - Wed, 08 Oct 2014 02:16:10 GMT
252
258
  Content-Length:
253
- - '194'
259
+ - '214'
254
260
  Connection:
255
261
  - Keep-Alive
256
262
  body:
257
263
  encoding: UTF-8
258
264
  string: |-
259
265
  {
260
- "id": 110,
266
+ "id": 40,
261
267
  "question_type": "boolean",
262
268
  "text": "Do you like poptarts?",
263
269
  "responses": [
@@ -266,8 +272,9 @@ http_interactions:
266
272
  ],
267
273
  "freeform": true,
268
274
  "absolute_index": 10,
269
- "parent_question_id": 42
275
+ "parent_question_id": 42,
276
+ "key": "poptarts"
270
277
  }
271
278
  http_version:
272
- recorded_at: Sun, 05 Oct 2014 12:55:10 GMT
279
+ recorded_at: Wed, 08 Oct 2014 02:16:10 GMT
273
280
  recorded_with: VCR 2.6.0