lib/lazy_resource/resource.rb in lazy_resource-0.4.0 vs lib/lazy_resource/resource.rb in lazy_resource-0.5.0
- old
+ new
@@ -67,15 +67,16 @@
def from=(from)
@from = from
end
def request_queue
- Thread.current[:request_queue] ||= Typhoeus::Hydra.new
+ Thread.current[:request_queue] ||= Typhoeus::Hydra.new(:max_concurrency => LazyResource.max_concurrency)
end
def find(id, params={}, options={})
- self.new(self.primary_key_name => id).tap do |resource|
+ self.new.tap do |resource|
+ resource.instance_variable_set("@#{self.primary_key_name}", id)
resource.fetched = false
resource.persisted = true
options[:headers] ||= {}
options[:headers].reverse_merge!(default_headers)
request = Request.new(resource.element_url(params), resource, options)
@@ -96,11 +97,11 @@
end
def offset(offset_value)
Relation.new(self, :offset_value => offset_value)
end
-
+
def page(page_value)
Relation.new(self, :page_value => page_value)
end
def all
@@ -161,19 +162,19 @@
end
end
def create
run_callbacks :create do
- request = Request.new(self.collection_url, self, { :method => :post, :params => attribute_params })
+ request = Request.new(self.collection_url, self, { :method => :post, :body => attribute_params.to_json })
self.class.request_queue.queue(request)
self.class.fetch_all
self.changed_attributes.clear
end
end
def update
run_callbacks :update do
- request = Request.new(self.element_url, self, { :method => :put, :params => attribute_params })
+ request = Request.new(self.element_url, self, { :method => :put, :body => attribute_params.to_json })
self.class.request_queue.queue(request)
self.class.fetch_all
self.changed_attributes.clear
end
end