lib/almodovar/resource_collection.rb in almodovar-1.5.5 vs lib/almodovar/resource_collection.rb in almodovar-1.6.0
- old
+ new
@@ -1,26 +1,26 @@
module Almodovar
class ResourceCollection
include HttpAccessor
include Enumerable
-
+
PAGINATION_ENTITIES = ["self::total-entries", "self::link[@rel='next']", "self::link[@rel='prev']"].join('|').freeze
- delegate :inspect, :to => :resources
+ delegate :inspect, to: :resources
def initialize(url, auth, xml = nil, options = {})
@url = url
@auth = auth
@xml = xml if options.empty?
@options = options
end
-
+
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
- response = http.post(url_with_params, body.to_xml(:root => root, :convert_links => true, :skip_links_one_level => true), "Content-Type" => "application/xml")
- check_errors(response, url_with_params)
+ response = http.post(@url, body.to_xml(root: root, convert_links: true, skip_links_one_level: true), query_params, { "Content-Type" => "application/xml" })
+ check_errors(response, @url, query_params)
Resource.new(nil, @auth, Nokogiri::XML.parse(response.body).root)
end
def total_entries
@total_entries ||= xml.at_xpath("./total-entries").try(:text).try(:to_i) || resources.size
@@ -39,20 +39,20 @@
end
def prev_page
Resource.new(prev_url, @auth) if prev_url
end
-
+
private
-
+
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
-
+
def method_missing(meth, *args, &blk)
resources.send(meth, *args, &blk)
end
end
-end
\ No newline at end of file
+end