ar_http_wrapper 0.1.0 → 0.1.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,53 +8,53 @@ class ActiveRecordHttpWrapper
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.build
|
11
|
-
get(
|
11
|
+
get(to_path("/new"))
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.create(args={})
|
15
15
|
options = { :body => args[:params] }
|
16
|
-
post(
|
16
|
+
post(to_path("/"), options)
|
17
17
|
end
|
18
18
|
|
19
19
|
def update_attributes(args={})
|
20
20
|
options = { :body => args[:params] }
|
21
|
-
put(
|
21
|
+
put(to_path("/"), options)
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.find_by_id(_id)
|
25
|
-
get(new(:id => _id).send(:
|
25
|
+
get(new(:id => _id).send(:to_path))
|
26
26
|
end
|
27
27
|
|
28
28
|
def destroy
|
29
|
-
delete(send(:
|
29
|
+
delete(send(:to_path))
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.where(conditions)
|
33
33
|
options = {:body => {:conditions => conditions}}
|
34
|
-
get(
|
34
|
+
get(to_path("/"), options)
|
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(
|
41
|
+
records = get(to_path("/"), options)
|
42
42
|
yield records if block_given?
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
def self.count(params={})
|
47
47
|
options = {:body => {:count => true}.merge(params)}
|
48
|
-
get(
|
48
|
+
get(to_path("/"),options)
|
49
49
|
end
|
50
50
|
private
|
51
51
|
|
52
|
-
def self.
|
52
|
+
def self.to_path(_path=nil)
|
53
53
|
"/#{to_url}#{_path}"
|
54
54
|
end
|
55
55
|
|
56
|
-
def
|
57
|
-
"#{self.class.send(:
|
56
|
+
def to_path(_path=nil)
|
57
|
+
"#{self.class.send(:to_path)}/#{id}#{_path}"
|
58
58
|
end
|
59
59
|
|
60
60
|
def self.to_url
|