Class: Poptart::Model
- Inherits:
-
Object
- Object
- Poptart::Model
- Extended by:
- Request
- Defined in:
- lib/poptart/model.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#links ⇒ Object
Returns the value of attribute links.
-
#params ⇒ Object
Returns the value of attribute params.
-
#root ⇒ Object
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(response) ⇒ Model
constructor
A new instance of Model.
- #questions_url(id: nil, query: nil) ⇒ Object
- #survey_questions_url(question_id: nil, query: nil) ⇒ Object
- #surveys_url(id: nil, query: nil) ⇒ Object
- #users_url(id: nil, query: nil) ⇒ Object
Methods included from Request
connection, get, post, put
Constructor Details
#initialize(response) ⇒ Model
Returns a new instance of Model.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/poptart/model.rb', line 7 def initialize(response) if response.respond_to?(:has_key?) @params = response else raise "Unauthorized"if response.status == 401 @params = JSON.parse(response.body) end @id = @params['id'] @links = Hashie::Mash.new(@params['_links']) end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/poptart/model.rb', line 5 def id @id end |
#links ⇒ Object
Returns the value of attribute links.
5 6 7 |
# File 'lib/poptart/model.rb', line 5 def links @links end |
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/poptart/model.rb', line 5 def params @params end |
#root ⇒ Object
Returns the value of attribute root.
5 6 7 |
# File 'lib/poptart/model.rb', line 5 def root @root end |
Class Method Details
.root ⇒ Object
19 20 21 22 23 |
# File 'lib/poptart/model.rb', line 19 def self.root return @root if @root response = get("/") @root = Poptart::Root.new(response) end |
Instance Method Details
#questions_url(id: nil, query: nil) ⇒ Object
39 40 41 42 |
# File 'lib/poptart/model.rb', line 39 def questions_url(id: nil, query: nil) template = Addressable::Template.new(links.questions.href) template.(id: id, query: query).to_s end |
#survey_questions_url(question_id: nil, query: nil) ⇒ Object
44 45 46 47 |
# File 'lib/poptart/model.rb', line 44 def survey_questions_url(question_id: nil, query: nil) template = Addressable::Template.new(links.survey_questions.href) template.(question_id: question_id, query: query).to_s end |
#surveys_url(id: nil, query: nil) ⇒ Object
34 35 36 37 |
# File 'lib/poptart/model.rb', line 34 def surveys_url(id: nil, query: nil) template = Addressable::Template.new(links.surveys.href) template.(id: id, query: query).to_s end |
#users_url(id: nil, query: nil) ⇒ Object
29 30 31 32 |
# File 'lib/poptart/model.rb', line 29 def users_url(id: nil, query: nil) template = Addressable::Template.new(links.users.href) template.(id: id, query: query).to_s end |