ar_http_wrapper 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,37 +8,37 @@ class ActiveRecordHttpWrapper
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.build
|
11
|
-
|
11
|
+
_parsed get(to_path(nil,"/new"))
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.create(args={})
|
15
15
|
options = { :body => args[:params] }
|
16
|
-
|
16
|
+
_parsed post(to_path(nil,"/"), options)
|
17
17
|
end
|
18
18
|
|
19
|
-
def update_attributes(args={})
|
19
|
+
def self.update_attributes(_syncable, args={})
|
20
20
|
options = { :body => args[:params] }
|
21
|
-
|
21
|
+
_parsed put(to_path(_syncable.id, "/"), options)
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.find_by_id(_id)
|
25
|
-
|
25
|
+
_parsed get(to_path(_id))
|
26
26
|
end
|
27
27
|
|
28
|
-
def destroy
|
29
|
-
|
28
|
+
def self.destroy(_syncable)
|
29
|
+
_parsed delete(to_path(_syncable.id))
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.where(conditions)
|
33
33
|
options = {:body => {:conditions => conditions}}
|
34
|
-
get(to_path("/"), options).try(:map) { |h|
|
34
|
+
get(to_path(nil,"/"), options).try(:map) { |h| _parsed(h) }
|
35
35
|
end
|
36
36
|
|
37
37
|
def self.find_each(batch_size=1000,&block)
|
38
38
|
n_batches = (count / batch_size).to_i + 1
|
39
39
|
n_batches.times do |i|
|
40
40
|
options = {:body => {:offset => i * batch_size, :limit => batch_size}}
|
41
|
-
records = get(to_path("/"), options).try(:map) { |h|
|
41
|
+
records = get(to_path(nil,"/"), options).try(:map) { |h| _parsed(h) }
|
42
42
|
records.each do |r|
|
43
43
|
yield r if block_given?
|
44
44
|
end
|
@@ -47,16 +47,17 @@ class ActiveRecordHttpWrapper
|
|
47
47
|
|
48
48
|
def self.count(params={})
|
49
49
|
options = {:body => {:count => true}.merge(params)}
|
50
|
-
get(to_path("/"),options).body.try(:to_i)
|
50
|
+
get(to_path(nil,"/"),options).body.try(:to_i)
|
51
51
|
end
|
52
|
+
|
52
53
|
private
|
53
54
|
|
54
|
-
def self.
|
55
|
-
|
55
|
+
def self._parsed(to_parse)
|
56
|
+
JSON.parse(to_parse).symbolize_keys
|
56
57
|
end
|
57
58
|
|
58
|
-
def to_path(_path=nil)
|
59
|
-
"#{
|
59
|
+
def self.to_path(_id=nil,_path=nil)
|
60
|
+
"/#{to_url}#{_id ? '/'+_id.to_s : nil}#{_path}"
|
60
61
|
end
|
61
62
|
|
62
63
|
def self.to_url
|