class Poptart::Model
Attributes
id[RW]
links[RW]
params[RW]
root[RW]
Public Class Methods
new(response)
click to toggle source
# 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 = [] if @params['_links'] @params['_links'].each do |link| @links << Link.new(href: link['href'], rel: link['rel'], method: link['method']) end end end
root()
click to toggle source
# File lib/poptart/model.rb, line 25 def self.root return @root if @root response = get("/") @root = Poptart::Root.new(response) end
Public Instance Methods
url(relation: , method: 'GET', query: nil, survey_id: nil, id: nil)
click to toggle source
# File lib/poptart/model.rb, line 35 def url(relation: , method: 'GET', query: nil, survey_id: nil, id: nil) link = find_link(relation, method) template = Addressable::Template.new(link.href) template.expand(survey_id: survey_id, id: id, query: query).to_s end
Private Instance Methods
find_link(relation, method)
click to toggle source
# File lib/poptart/model.rb, line 43 def find_link(relation, method) links.find { |link| link.rel == relation && link.method == method } end