class Almodovar::ResourceCollection
Constants
- PAGINATION_ENTITIES
Public Class Methods
new(url, auth, xml = nil, options = {})
click to toggle source
# File lib/almodovar/resource_collection.rb, line 10 def initialize(url, auth, xml = nil, options = {}) @url = url @auth = auth @xml = xml if options.empty? @options = options end
Public Instance Methods
create(attrs = {})
click to toggle source
# File lib/almodovar/resource_collection.rb, line 17 def create(attrs = {}) raise ArgumentError.new("You must specify one only root element which is the type of resource (e.g. `:project => { :name => 'Wadus' }` instead of just `:name => 'Wadus'`)") if attrs.size > 1 root, body = attrs.first if body.is_a?(Array) body = body.to_xml(root: root) else body = body.to_xml(root: root, convert_links: true, skip_links_one_level: true) end response = http.post(@url, body, query_params, { "Content-Type" => "application/xml" }) check_errors(response, @url, query_params) Resource.new(nil, @auth, Nokogiri::XML.parse(response.body).root) end
next_page()
click to toggle source
# File lib/almodovar/resource_collection.rb, line 42 def next_page Resource.new(next_url, @auth) if next_url end
next_url()
click to toggle source
# File lib/almodovar/resource_collection.rb, line 34 def next_url @next_url ||= xml.at_xpath("./link[@rel='next']").try(:[], "href") end
prev_page()
click to toggle source
# File lib/almodovar/resource_collection.rb, line 46 def prev_page Resource.new(prev_url, @auth) if prev_url end
prev_url()
click to toggle source
# File lib/almodovar/resource_collection.rb, line 38 def prev_url @prev_url ||= xml.at_xpath("./link[@rel='prev']").try(:[], "href") end
total_entries()
click to toggle source
# File lib/almodovar/resource_collection.rb, line 30 def total_entries @total_entries ||= xml.at_xpath("./total-entries").try(:text).try(:to_i) || resources.size end
Private Instance Methods
method_missing(meth, *args, &blk)
click to toggle source
# File lib/almodovar/resource_collection.rb, line 59 def method_missing(meth, *args, &blk) resources.send(meth, *args, &blk) end
resources()
click to toggle source
# File lib/almodovar/resource_collection.rb, line 52 def resources @resources ||= begin xml.xpath("./*[not(#{PAGINATION_ENTITIES})]"). map { |subnode| Resource.new(subnode.at_xpath("./link[@rel='self']").try(:[], "href"), @auth, subnode, @options) } end end