poptart 0.0.10 → 0.0.11
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/Gemfile.lock +1 -1
- data/lib/poptart/request.rb +6 -0
- data/lib/poptart/user.rb +9 -2
- data/lib/poptart.rb +18 -0
- data/lib/version.rb +1 -1
- data/spec/requests/answering_survey_questions_spec.rb +6 -0
- data/spec/requests/answers_spec.rb +2 -0
- data/spec/requests/surveys_spec.rb +11 -0
- data/spec/requests/user_management_spec.rb +1 -0
- data/spec/vcr/answering/survey_questions_answers_a_multiple_choice_question.yml +3407 -626
- data/spec/vcr/answering/survey_questions_answers_a_survey_question.yml +6035 -1352
- data/spec/vcr/answering/survey_questions_creates_and_returns_a_random_question_survey.yml +75 -240
- data/spec/vcr/answering/survey_questions_creates_and_returns_an_empty_survey.yml +35 -27
- data/spec/vcr/answering/survey_questions_finds_survey_question_for_id.yml +73 -235
- data/spec/vcr/creating/quesitons_returns_boolean_question.yml +19 -15
- data/spec/vcr/creating/quesitons_returns_multiple_question.yml +76 -60
- data/spec/vcr/creating/quesitons_returns_range_question.yml +75 -59
- data/spec/vcr/retrieving/answers_returns_all_answered_survey_questions_for_a_question.yml +6923 -442
- data/spec/vcr/retrieving/answers_returns_all_answered_survey_questions_for_a_question_by_key.yml +2055 -329
- data/spec/vcr/surveys/fetchs_all_surveys_for_a_user.yml +476 -0
- data/spec/vcr/user/management_creates_a_user.yml +55 -48
- data/spec/vcr/user/management_returns_a_user.yml +468 -17
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc12cebbe207a435469fe38dc5f7781d00be45e3
|
4
|
+
data.tar.gz: ab116eb8585c9d8e5b3e57d65bd6ad536590ee7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb4cd23dec6506200b7c1d0fde890007188426281ca8a33752167e7d80b0210de75f89044ac9ef0e44ddd2f6d4185bf140184e179a2942e01f41c9164fc6c37d
|
7
|
+
data.tar.gz: 032353296870f84e5e4721b32ac4dfe3dee480a8aa1e123e22594e65d8e411f92849f483150014d41ca4dd8c7fe606c4208fbb012abb508c5ccc04b862371b17
|
data/Gemfile.lock
CHANGED
data/lib/poptart/request.rb
CHANGED
@@ -5,6 +5,8 @@ module Poptart
|
|
5
5
|
req.url(url)
|
6
6
|
req.headers['Content-Type'] = 'application/json'
|
7
7
|
req.headers['API-TOKEN'] = Poptart.api_token if Poptart.api_token
|
8
|
+
req.headers['USER-TOKEN'] = Poptart.user_token if Poptart.user_token
|
9
|
+
req.headers['SERVICE-USER-ID'] = Poptart.service_user_id if Poptart.service_user_id
|
8
10
|
req.headers.merge!(headers)
|
9
11
|
end
|
10
12
|
end
|
@@ -15,6 +17,8 @@ module Poptart
|
|
15
17
|
req.body = data.to_json if data
|
16
18
|
req.headers['Content-Type'] = 'application/json'
|
17
19
|
req.headers['API-TOKEN'] = Poptart.api_token if Poptart.api_token
|
20
|
+
req.headers['USER-TOKEN'] = Poptart.user_token if Poptart.user_token
|
21
|
+
req.headers['SERVICE-USER-ID'] = Poptart.service_user_id if Poptart.service_user_id
|
18
22
|
req.headers.merge!(headers)
|
19
23
|
end
|
20
24
|
end
|
@@ -25,6 +29,8 @@ module Poptart
|
|
25
29
|
req.body = data.to_json if data
|
26
30
|
req.headers['Content-Type'] = 'application/json'
|
27
31
|
req.headers['API-TOKEN'] = Poptart.api_token if Poptart.api_token
|
32
|
+
req.headers['USER-TOKEN'] = Poptart.user_token if Poptart.user_token
|
33
|
+
req.headers['SERVICE-USER-ID'] = Poptart.service_user_id if Poptart.service_user_id
|
28
34
|
req.headers.merge!(headers)
|
29
35
|
end
|
30
36
|
end
|
data/lib/poptart/user.rb
CHANGED
@@ -22,13 +22,13 @@ module Poptart
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def create_survey
|
25
|
-
response = post(root.surveys_url, survey: { service_user_id: service_user_id })
|
25
|
+
response = post(root.surveys_url, { survey: { service_user_id: service_user_id } })
|
26
26
|
Poptart::Survey.new(response)
|
27
27
|
end
|
28
28
|
|
29
29
|
def create_random_survey
|
30
30
|
url = root.surveys_url(query: {random: true})
|
31
|
-
response = post(url, survey: { service_user_id: service_user_id })
|
31
|
+
response = post(url, { survey: { service_user_id: service_user_id } })
|
32
32
|
Poptart::Survey.new(response)
|
33
33
|
end
|
34
34
|
|
@@ -47,5 +47,12 @@ module Poptart
|
|
47
47
|
def survey_questions_for_key(key)
|
48
48
|
survey_questions_for_question_id(key)
|
49
49
|
end
|
50
|
+
|
51
|
+
def surveys
|
52
|
+
response = get(root.surveys_url)
|
53
|
+
JSON.parse(response.body)["surveys"].map { |response_body| Poptart::Survey.new(response_body) }
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
50
57
|
end
|
51
58
|
end
|
data/lib/poptart.rb
CHANGED
@@ -14,6 +14,24 @@ module Poptart
|
|
14
14
|
def self.url
|
15
15
|
@url || 'http://localhost:3000'
|
16
16
|
end
|
17
|
+
|
18
|
+
def self.service_user_id
|
19
|
+
@service_user_id
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.user_token
|
23
|
+
@user_token
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.authorize(service_user_id:, user_token:)
|
27
|
+
@service_user_id = service_user_id
|
28
|
+
@user_token = user_token
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.reset_authorization
|
32
|
+
@service_user_id = nil
|
33
|
+
@user_token = nil
|
34
|
+
end
|
17
35
|
end
|
18
36
|
|
19
37
|
require 'faraday'
|
data/lib/version.rb
CHANGED
@@ -3,6 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe 'Answering survey questions' do
|
4
4
|
it "creates and returns an empty survey", :vcr do
|
5
5
|
user = Poptart::User.create
|
6
|
+
Poptart.authorize(service_user_id: user.service_user_id, user_token: user.token)
|
6
7
|
survey = user.create_survey
|
7
8
|
survey.service_user_id.should == user.service_user_id
|
8
9
|
survey.survey_questions.count.should == 0
|
@@ -10,6 +11,7 @@ describe 'Answering survey questions' do
|
|
10
11
|
|
11
12
|
it "creates and returns a random question survey", :vcr do
|
12
13
|
user = Poptart::User.create
|
14
|
+
Poptart.authorize(service_user_id: user.service_user_id, user_token: user.token)
|
13
15
|
survey = user.create_random_survey
|
14
16
|
survey.service_user_id.should == user.service_user_id
|
15
17
|
survey.survey_questions.count.should > 0
|
@@ -17,6 +19,7 @@ describe 'Answering survey questions' do
|
|
17
19
|
|
18
20
|
it "answers a survey question", :vcr do
|
19
21
|
user = Poptart::User.create
|
22
|
+
Poptart.authorize(service_user_id: user.service_user_id, user_token: user.token)
|
20
23
|
survey = user.create_random_survey
|
21
24
|
survey_question = survey.survey_questions.first
|
22
25
|
survey_question.text.should be
|
@@ -30,6 +33,7 @@ describe 'Answering survey questions' do
|
|
30
33
|
it "answers a survey question", :vcr do
|
31
34
|
boolean_questions = Poptart::Question.all(type: 'boolean')
|
32
35
|
user = Poptart::User.create
|
36
|
+
Poptart.authorize(service_user_id: user.service_user_id, user_token: user.token)
|
33
37
|
survey = user.create_survey
|
34
38
|
survey_question = survey.add_question(boolean_questions.first)
|
35
39
|
|
@@ -48,6 +52,7 @@ describe 'Answering survey questions' do
|
|
48
52
|
questions = Poptart::Question.all(type: 'multiple')
|
49
53
|
question = questions.find { |question| question.responses.include?('At Home') }
|
50
54
|
user = Poptart::User.create
|
55
|
+
Poptart.authorize(service_user_id: user.service_user_id, user_token: user.token)
|
51
56
|
survey = user.create_survey
|
52
57
|
survey_question = survey.add_question(question)
|
53
58
|
|
@@ -64,6 +69,7 @@ describe 'Answering survey questions' do
|
|
64
69
|
|
65
70
|
it "finds survey question for id", :vcr do
|
66
71
|
user = Poptart::User.create
|
72
|
+
Poptart.authorize(service_user_id: user.service_user_id, user_token: user.token)
|
67
73
|
survey = user.create_random_survey
|
68
74
|
first_survey_question = survey.survey_questions.first
|
69
75
|
survey_question = survey.survey_question_for_id(first_survey_question.id)
|
@@ -4,6 +4,7 @@ describe 'retrieving answers' do
|
|
4
4
|
it "returns all answered survey questions for a question", :vcr do
|
5
5
|
question = Poptart::BooleanQuestion.create("Do you like poptarts?")
|
6
6
|
user = Poptart::User.create
|
7
|
+
Poptart.authorize(service_user_id: user.service_user_id, user_token: user.token)
|
7
8
|
|
8
9
|
survey = user.create_survey
|
9
10
|
first_survey_question = survey.add_question(question)
|
@@ -24,6 +25,7 @@ describe 'retrieving answers' do
|
|
24
25
|
key = 'testingooptarts'
|
25
26
|
question = Poptart::BooleanQuestion.create("Do you like poptarts?", key: key)
|
26
27
|
user = Poptart::User.create
|
28
|
+
Poptart.authorize(service_user_id: user.service_user_id, user_token: user.token)
|
27
29
|
|
28
30
|
survey = user.create_survey
|
29
31
|
first_survey_question = survey.add_question(question)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'surveys' do
|
4
|
+
it 'fetchs all surveys for a user', :vcr do
|
5
|
+
user = Poptart::User.create
|
6
|
+
Poptart.authorize(service_user_id: user.service_user_id, user_token: user.token)
|
7
|
+
survey1 = user.create_survey
|
8
|
+
survey2 = user.create_survey
|
9
|
+
expect(user.surveys.map(&:id)).to eq([survey1.id, survey2.id])
|
10
|
+
end
|
11
|
+
end
|
@@ -9,6 +9,7 @@ describe "User Management" do
|
|
9
9
|
|
10
10
|
it "returns a user", :vcr do
|
11
11
|
user = Poptart::User.create
|
12
|
+
Poptart.authorize(service_user_id: user.service_user_id, user_token: user.token)
|
12
13
|
other_user = Poptart::User.for_id(user.service_user_id)
|
13
14
|
user.service_user_id.should == other_user.service_user_id
|
14
15
|
end
|