Class: ActiveRecordHttpWrapper

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/ar_http_wrapper/active_record_http_wrapper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#idObject

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

.buildObject



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={})
  options = {:body => {:count => true}.merge(params)}
  get(to_path(nil,"/"),options).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={})
  options = { :body => args[:params] }
  _parsed post(to_path(nil,"/"), options)
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|
    options = {:body => {:offset => i * batch_size, :limit => batch_size}}
    records = get(to_path(nil,"/"), options).try(:map) { |h| _parsed(h) }
    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={})
  options = { :body => args[:params] }
  _parsed put(to_path(_syncable.id, "/"), options)
end

.where(conditions) ⇒ Object



32
33
34
35
# File 'lib/ar_http_wrapper/active_record_http_wrapper.rb', line 32

def self.where(conditions)
  options = {:body => {:conditions => conditions}}
  get(to_path(nil,"/"), options).try(:map) { |h| _parsed(h) }
end