motion-rails-model 0.0.1.2 → 0.0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/motion-rails-model/model.rb +15 -4
- data/lib/motion-rails-model/version.rb +1 -1
- metadata +1 -1
@@ -38,6 +38,13 @@ module RM
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
def destory(url="#{self.class.to_s.downcase}/#{self.id}", &block)
|
42
|
+
data = { credentials: {username: @@username, password: @@password}}
|
43
|
+
connect(url, data, :delete) do |result|
|
44
|
+
block.call(result)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
41
48
|
def self.set_url(url)
|
42
49
|
@@url = url
|
43
50
|
end
|
@@ -66,11 +73,15 @@ module RM
|
|
66
73
|
def connect(url, data, http_verb, &block)
|
67
74
|
BW::HTTP.send(http_verb, "#{@@url}#{url}", data) do |response|
|
68
75
|
if response.ok?
|
69
|
-
|
70
|
-
|
71
|
-
block.call(json.map {|y| self.class.new(y) })
|
76
|
+
if response.body.nil?
|
77
|
+
block.call(response.status_code)
|
72
78
|
else
|
73
|
-
|
79
|
+
json = BW::JSON.parse(response.body.to_str)
|
80
|
+
if json.instance_of?(Array)
|
81
|
+
block.call(json.map {|y| self.class.new(y) })
|
82
|
+
else
|
83
|
+
block.call(self.class.new(json))
|
84
|
+
end
|
74
85
|
end
|
75
86
|
else
|
76
87
|
block.call(nil)
|