emailvision 2.1.4 → 2.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/emailvision/api.rb +9 -1
- data/lib/emailvision/tools.rb +39 -0
- metadata +1 -1
data/lib/emailvision/api.rb
CHANGED
@@ -71,6 +71,9 @@ module Emailvision
|
|
71
71
|
raise Emailvision::Exception.new "Cannot make an API call without a server name and an endpoint !"
|
72
72
|
end
|
73
73
|
|
74
|
+
# == Sanitize parameters ==
|
75
|
+
parameters = Emailvision::Tools.sanitize_parameters(parameters)
|
76
|
+
|
74
77
|
# == Build uri ==
|
75
78
|
uri = base_uri + method
|
76
79
|
if parameters[:uri]
|
@@ -98,7 +101,12 @@ module Emailvision
|
|
98
101
|
|
99
102
|
# == Parse response ==
|
100
103
|
http_code = response.header.code
|
101
|
-
content =
|
104
|
+
content = {}
|
105
|
+
begin
|
106
|
+
content = Crack::XML.parse response.body
|
107
|
+
rescue MultiXml::ParseError => e
|
108
|
+
logger.send "#{uri} Error when parsing response body (#{e.to_s})"
|
109
|
+
end
|
102
110
|
logger.receive content.inspect
|
103
111
|
|
104
112
|
# Return response or raise an exception if request failed
|
data/lib/emailvision/tools.rb
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
module Emailvision
|
2
2
|
class Tools
|
3
|
+
|
4
|
+
def self.sanitize_parameters(parameters)
|
5
|
+
r_each(parameters) do |value|
|
6
|
+
if value.kind_of?(DateTime) or value.kind_of?(Time)
|
7
|
+
date_time_format(value)
|
8
|
+
elsif value.kind_of?(Date)
|
9
|
+
date_format(value)
|
10
|
+
else
|
11
|
+
value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.date_time_format(datetime)
|
17
|
+
datetime.utc.strftime("%Y-%m-%dT%H:%M:%S")
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.date_format(datetime)
|
21
|
+
date.strftime('%Y-%m-%d')
|
22
|
+
end
|
3
23
|
|
4
24
|
def self.r_camelize(obj)
|
5
25
|
if obj.is_a?(Hash)
|
@@ -30,6 +50,25 @@ module Emailvision
|
|
30
50
|
|
31
51
|
obj_xml
|
32
52
|
end
|
53
|
+
|
54
|
+
def self.r_each(hash, &block)
|
55
|
+
return enum_for(:dfs, hash) unless block
|
56
|
+
|
57
|
+
result = {}
|
58
|
+
hash.map do |k,v|
|
59
|
+
result[k] = if v.is_a? Array
|
60
|
+
v.map do |elm|
|
61
|
+
r_each(elm, &block)
|
62
|
+
end
|
63
|
+
elsif v.is_a? Hash
|
64
|
+
r_each(v, &block)
|
65
|
+
else
|
66
|
+
yield(v)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
result
|
71
|
+
end
|
33
72
|
|
34
73
|
private
|
35
74
|
|