Module: Gupshup
- Extended by:
- SingleForwardable
- Defined in:
- lib/gupshup-rb.rb,
lib/gupshup-rb/version.rb,
lib/gupshup-rb/rest/api.rb,
lib/gupshup-rb/rest/api/v1.rb,
lib/gupshup-rb/rest/client.rb,
lib/gupshup-rb/framework/values.rb,
lib/gupshup-rb/http/http_client.rb,
lib/gupshup-rb/framework/request.rb,
lib/gupshup-rb/framework/response.rb,
lib/gupshup-rb/util/configuration.rb,
lib/gupshup-rb/framework/rest/page.rb,
lib/gupshup-rb/framework/serialize.rb,
lib/gupshup-rb/rest/api/v1/message.rb,
lib/gupshup-rb/framework/rest/error.rb,
lib/gupshup-rb/framework/rest/domain.rb,
lib/gupshup-rb/framework/rest/helper.rb,
lib/gupshup-rb/framework/rest/version.rb,
lib/gupshup-rb/framework/rest/resource.rb,
lib/gupshup-rb/framework/gupshup_response.rb,
lib/gupshup-rb/framework/rest/obsolete_client.rb
Defined Under Namespace
Modules: HTTP, REST, Util
Classes: GupshupResponse, Request, Response, Values
Constant Summary
collapse
- VERSION =
'0.2.1'
Class Method Summary
collapse
Class Method Details
Pre-configure with account SID and auth token so that you don’t need to pass them to various initializers each time.
29
30
31
|
# File 'lib/gupshup-rb.rb', line 29
def self.configure(&block)
yield configuration
end
|
.deserialize_iso8601_date(date) ⇒ Object
32
33
34
|
# File 'lib/gupshup-rb/framework/serialize.rb', line 32
def self.deserialize_iso8601_date(date)
Date.parse(date) unless date.nil?
end
|
.deserialize_iso8601_datetime(date) ⇒ Object
36
37
38
|
# File 'lib/gupshup-rb/framework/serialize.rb', line 36
def self.deserialize_iso8601_datetime(date)
Time.parse(date) unless date.nil?
end
|
.deserialize_rfc2822(date) ⇒ Object
28
29
30
|
# File 'lib/gupshup-rb/framework/serialize.rb', line 28
def self.deserialize_rfc2822(date)
Time.rfc2822(date) unless date.nil?
end
|
.flatten(map, result = {}, previous = []) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/gupshup-rb/framework/serialize.rb', line 48
def self.flatten(map, result = {}, previous = [])
map.each do |key, value|
if value.is_a? Hash
self.flatten(value, result, previous + [key])
else
result[(previous + [key]).join('.')] = value
end
end
result
end
|
.prefixed_collapsible_map(map, prefix) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/gupshup-rb/framework/serialize.rb', line 60
def self.prefixed_collapsible_map(map, prefix)
result = {}
if map.is_a? Hash
flattened = self.flatten(map)
result = {}
flattened.each do |key, value|
result[prefix + '.' + key] = value
end
end
result
end
|
.serialize_iso8601_date(date) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/gupshup-rb/framework/serialize.rb', line 4
def self.serialize_iso8601_date(date)
if date.eql?(:unset)
date
elsif date.is_a?(Date)
date.iso8601
elsif date.is_a?(Time)
date.strftime('%Y-%m-%d')
elsif date.is_a?(String)
date
end
end
|
.serialize_iso8601_datetime(date) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/gupshup-rb/framework/serialize.rb', line 16
def self.serialize_iso8601_datetime(date)
if date.eql?(:unset)
date
elsif date.is_a?(Date)
Time.new(date.year, date.month, date.day).utc.iso8601
elsif date.is_a?(Time)
date.utc.iso8601
elsif date.is_a?(String)
date
end
end
|
.serialize_list(input_list) ⇒ Object
73
74
75
76
77
78
79
80
|
# File 'lib/gupshup-rb/framework/serialize.rb', line 73
def self.serialize_list(input_list)
return input_list unless input_list.is_a? Array
result = []
input_list.each do |e|
result.push yield e
end
result
end
|
.serialize_object(object) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/gupshup-rb/framework/serialize.rb', line 40
def self.serialize_object(object)
if object.is_a?(Hash) || object.is_a?(Array)
JSON.generate(object)
else
object
end
end
|