Class: Poptart::User
Instance Attribute Summary collapse
Attributes inherited from Model
#id, #links, #params, #root
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Request
connection, get, post, put
Methods inherited from Model
#questions_url, root, #survey_questions_url, #surveys_url, #users_url
Constructor Details
#initialize(response) ⇒ User
Returns a new instance of User.
7
8
9
10
11
|
# File 'lib/poptart/user.rb', line 7
def initialize(response)
super
@service_user_id = params['service_user_id']
@token = params['token']
end
|
Instance Attribute Details
#service_user_id ⇒ Object
Returns the value of attribute service_user_id.
5
6
7
|
# File 'lib/poptart/user.rb', line 5
def service_user_id
@service_user_id
end
|
#token ⇒ Object
Returns the value of attribute token.
5
6
7
|
# File 'lib/poptart/user.rb', line 5
def token
@token
end
|
Class Method Details
.create ⇒ Object
13
14
15
16
|
# File 'lib/poptart/user.rb', line 13
def self.create
response = post(root.users_url)
Poptart::User.new(response)
end
|
.for_id(service_user_id) ⇒ Object
18
19
20
21
22
|
# File 'lib/poptart/user.rb', line 18
def self.for_id(service_user_id)
url = root.users_url(id: service_user_id)
response = get(url)
Poptart::User.new(response)
end
|
Instance Method Details
#create_random_survey ⇒ Object
29
30
31
32
33
|
# File 'lib/poptart/user.rb', line 29
def create_random_survey
url = root.surveys_url(query: {random: true})
response = post(url, { survey: { service_user_id: service_user_id } })
Poptart::Survey.new(response)
end
|
#create_survey ⇒ Object
24
25
26
27
|
# File 'lib/poptart/user.rb', line 24
def create_survey
response = post(root.surveys_url, { survey: { service_user_id: service_user_id } })
Poptart::Survey.new(response)
end
|
#survey_for_id(id) ⇒ Object
35
36
37
38
39
|
# File 'lib/poptart/user.rb', line 35
def survey_for_id(id)
url = root.surveys_url(id: id)
response = get(url)
Poptart::Survey.new(response)
end
|
#survey_questions_for_key(key) ⇒ Object
47
48
49
|
# File 'lib/poptart/user.rb', line 47
def survey_questions_for_key(key)
survey_questions_for_question_id(key)
end
|
#survey_questions_for_question_id(question_id) ⇒ Object
41
42
43
44
45
|
# File 'lib/poptart/user.rb', line 41
def survey_questions_for_question_id(question_id)
url = root.survey_questions_url(question_id: question_id)
response = get(url)
JSON.parse(response.body)["survey_questions"].map { |response_body| Poptart::SurveyQuestion.new(response_body) }
end
|
#surveys ⇒ Object
51
52
53
54
|
# File 'lib/poptart/user.rb', line 51
def surveys
response = get(root.surveys_url)
JSON.parse(response.body)["surveys"].map { |response_body| Poptart::Survey.new(response_body) }
end
|