lib/pmp/link.rb in pmp-0.3.2 vs lib/pmp/link.rb in pmp-0.4.0
- old
+ new
@@ -7,11 +7,11 @@
# :href, # "https://api-sandbox.pmp.io/docs/af676335-21df-4486-ab43-e88c1b48f026"
# :href_template, # "https://api-sandbox.pmp.io/users{?limit,offset,tag,collection,text,searchsort,has}"
# :href_vars, # { "collection": "https://github.com/publicmediaplatform/pmpdocs/wiki/Content-Retrieval" }
# :hreflang, # Language of the linked document
# :hints, # Hints about interacting with the link, such as HTTP methods, e.g. "hints": { "allow": ["GET", "PUT", "DELETE"] }
-# :rels, # [ "urn:pmp:query:users" ]
+# :rels, # [ "urn:collectiondoc:query:users" ]
# :method, # http method - get, post, put, etc.
# :type, # 'image/png' - mime type of linked resource
# :title, # name/title of thing linked in
# :operation, # used by permissions link - read, write
# :blacklist, # used by permissions link
@@ -32,18 +32,12 @@
# puts "params: #{params.inspect}"
parse_attributes(link)
[:href, :href_template, :method].each{|m| self.send("#{m}=", nil) unless respond_to?(m)}
end
- def attributes
- attrs = HashWithIndifferentAccess.new(marshal_dump)
- attrs.delete(attrs[:href_template].blank? ? :href_template : :href)
- attrs
- end
-
def where(params={})
- self.class.new(attributes.merge({'params'=>params}), parent)
+ self.class.new(attributes_map.merge({'params'=>params}), parent)
end
def as_json(options={})
extract_attributes
end
@@ -57,9 +51,15 @@
def retrieve
# puts "retrieve method: #{method}"
# puts "retrieve url: #{url}"
# response = parent.request((method || 'get').to_sym, url)
@doc ||= PMP::CollectionDocument.new(parent.options.merge(href: url, root: parent.root))
+ end
+
+ def attributes_map
+ attrs = HashWithIndifferentAccess.new(marshal_dump)
+ attrs.delete(attrs[:href_template].blank? ? :href_template : :href)
+ attrs
end
def method_missing(method, *args)
# puts "mm: #{method}"
# this is a method the link supports, call the link