Class: ActiveRecordHttpWrapper
- Inherits:
-
Object
- Object
- ActiveRecordHttpWrapper
- Includes:
- HTTParty
- Defined in:
- lib/ar_http_wrapper/active_record_http_wrapper.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
- .build ⇒ Object
- .count(params = {}) ⇒ Object
- .create(args = {}) ⇒ Object
- .destroy(_syncable) ⇒ Object
- .find_by_id(_id) ⇒ Object
- .find_each(batch_size = 1000, &block) ⇒ Object
- .update_attributes(_syncable, args = {}) ⇒ Object
- .where(conditions) ⇒ Object
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ ActiveRecordHttpWrapper
constructor
A new instance of ActiveRecordHttpWrapper.
Constructor Details
#initialize(args = {}) ⇒ ActiveRecordHttpWrapper
Returns a new instance of ActiveRecordHttpWrapper.
6 7 8 |
# File 'lib/ar_http_wrapper/active_record_http_wrapper.rb', line 6 def initialize(args={}) @id = args[:id] end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/ar_http_wrapper/active_record_http_wrapper.rb', line 4 def id @id end |
Class Method Details
.build ⇒ Object
10 11 12 |
# File 'lib/ar_http_wrapper/active_record_http_wrapper.rb', line 10 def self.build _parsed get(to_path(nil,"/new")) end |
.count(params = {}) ⇒ Object
48 49 50 51 |
# File 'lib/ar_http_wrapper/active_record_http_wrapper.rb', line 48 def self.count(params={}) = {:body => {:count => true}.merge(params)} get(to_path(nil,"/"),).body.try(:to_i) end |
.create(args = {}) ⇒ Object
14 15 16 17 |
# File 'lib/ar_http_wrapper/active_record_http_wrapper.rb', line 14 def self.create(args={}) = { :body => prepared_params(args) } _parsed post(to_path(nil,"/"), ) end |
.destroy(_syncable) ⇒ Object
28 29 30 |
# File 'lib/ar_http_wrapper/active_record_http_wrapper.rb', line 28 def self.destroy(_syncable) _parsed delete(to_path(_syncable.id)) end |
.find_by_id(_id) ⇒ Object
24 25 26 |
# File 'lib/ar_http_wrapper/active_record_http_wrapper.rb', line 24 def self.find_by_id(_id) _parsed get(to_path(_id)) end |
.find_each(batch_size = 1000, &block) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ar_http_wrapper/active_record_http_wrapper.rb', line 37 def self.find_each(batch_size=1000,&block) n_batches = (count / batch_size).to_i + 1 n_batches.times do |i| = {:body => {:offset => i * batch_size, :limit => batch_size}} records = _parsed get(to_path(nil,"/"), ) records.each do |r| yield r if block_given? end end end |
.update_attributes(_syncable, args = {}) ⇒ Object
19 20 21 22 |
# File 'lib/ar_http_wrapper/active_record_http_wrapper.rb', line 19 def self.update_attributes(_syncable, args={}) = { :body => prepared_params(args) } _parsed put(to_path(_syncable.id, "/"), ) end |
.where(conditions) ⇒ Object
32 33 34 35 |
# File 'lib/ar_http_wrapper/active_record_http_wrapper.rb', line 32 def self.where(conditions) = {:body => {:conditions => conditions}} _parsed get(to_path(nil,"/"), ) end |