motion_model_resource 0.1.8 → 0.1.9
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.
- checksums.yaml +8 -8
- data/motion/resource/data_parser.rb +2 -1
- data/motion/resource/wrapper.rb +32 -2
- data/motion/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTc1MTZkYTZhM2QyYjFkMjViN2VjNDNlNDhmMmUxNzhlZjdhZjMyZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDEyNzY4ZjVmZTc0ODQ4MzY4Y2EzNmM4YWM0ZDMyZDYyMDc3NGE5Yg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzhiMjcxNjEwMjZkYjZiYjIxMTRiM2FjNTc0ZmNhYTAzODBmZDc0NjZlOTMx
|
10
|
+
ZWM2MDY4ZTcyYTIzODM4MzMzYWY3YzYzM2NlMGQ0YTUwZDAzYWY2NmM5MjIz
|
11
|
+
ZDdhNWE3ODcwMTk2MDdmOTcxYTBiNjdiZjY3NjJmMThhM2U3NjI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDg5ZTg0N2IzZDA4NzA2NGM4Y2M3MTNhMzdkNDJkNmEyZWY0NzdlZmQxNmFh
|
14
|
+
YjE2MjE1MGZlNzYxMjZiYzg5MDYyNjNmNDkzMzUwNDBlY2JlZDhjNzRiNDJk
|
15
|
+
MzMyZWI1ZTY2YmFlNzYzMjBmYmRjYjNlYjY1MjcxZTQ4ODY5YTg=
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module MotionModelResource
|
2
2
|
module DateParser
|
3
3
|
def self.parseDate(arg)
|
4
|
+
additional_parsestring = arg.include?(".") ? ".SSS" : ""
|
4
5
|
date_formatter = NSDateFormatter.alloc.init
|
5
|
-
date_formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:
|
6
|
+
date_formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss#{additional_parsestring}ZZZZ"
|
6
7
|
date = date_formatter.dateFromString arg
|
7
8
|
|
8
9
|
return nil if date.blank?
|
data/motion/resource/wrapper.rb
CHANGED
@@ -121,6 +121,36 @@ module MotionModelResource
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
alias_method :save_remote, :save
|
124
|
+
|
125
|
+
# Destroys a remote model
|
126
|
+
# UNTESTED # TODO write a test
|
127
|
+
def destroy(options = {}, &block)
|
128
|
+
if block.present?
|
129
|
+
raise MotionModelResource::URLNotDefinedError.new "URL is not defined for #{self.class.name}!" unless self.class.respond_to?(:url)
|
130
|
+
|
131
|
+
model = self
|
132
|
+
|
133
|
+
BW::HTTP.delete("#{self.try(:url)}" || "#{self.class.url}/#{model.id}", {payload: options[:params]}) do |response|
|
134
|
+
if response.ok? || options[:force] == true
|
135
|
+
model.delete
|
136
|
+
end
|
137
|
+
|
138
|
+
block.call if block.present? && block.respond_to?(:call)
|
139
|
+
end
|
140
|
+
else
|
141
|
+
super
|
142
|
+
end
|
143
|
+
end
|
144
|
+
alias_method :destroy_remote, :destroy
|
145
|
+
|
146
|
+
# Takes no care of the server response.
|
147
|
+
# UNTESTED # TODO write a test
|
148
|
+
def destroy!(options = {}, &block)
|
149
|
+
options.merge!(force: true)
|
150
|
+
|
151
|
+
destroy(options, &block)
|
152
|
+
end
|
153
|
+
alias_method :destroy_remote!, :destroy!
|
124
154
|
|
125
155
|
# Returns a hash with given model
|
126
156
|
def buildHashFromModel(mainKey, model)
|
@@ -153,7 +183,7 @@ module MotionModelResource
|
|
153
183
|
# Loads the given URL and parse the JSON for a model.
|
154
184
|
# If the model is present, the model will updates.
|
155
185
|
# If block given, the block will called, when the the model is saved. The model will be passed as an argument to the block.
|
156
|
-
def fetch(site, params, &block)
|
186
|
+
def fetch(site, params = {}, &block)
|
157
187
|
raise MotionModelResource::WrapperNotDefinedError.new "Wrapper is not defined!" unless self.class.respond_to?(:wrapper)
|
158
188
|
model = self
|
159
189
|
BW::HTTP.get(site, params) do |response|
|
@@ -199,7 +229,7 @@ module MotionModelResource
|
|
199
229
|
# Currently only Date/Time support needed
|
200
230
|
def parseValue(key, value)
|
201
231
|
case self.column_type(key.to_sym)
|
202
|
-
when :
|
232
|
+
when :time then MotionModelResource::DateParser.parseDate value
|
203
233
|
else value
|
204
234
|
end
|
205
235
|
end
|
data/motion/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion_model_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Torben Toepper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bubble-wrap
|