bandwidth-sdk 6.2.0 → 7.0.0
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 +4 -4
- data/lib/bandwidth.rb +3 -2
- data/lib/bandwidth/api_helper.rb +0 -12
- data/lib/bandwidth/client.rb +8 -8
- data/lib/bandwidth/configuration.rb +15 -15
- data/lib/bandwidth/http/auth/{two_factor_auth_basic_auth.rb → multi_factor_auth_basic_auth.rb} +3 -3
- data/lib/bandwidth/messaging_lib/messaging/client.rb +14 -5
- data/lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb +25 -29
- data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message_item.rb +47 -2
- data/lib/bandwidth/messaging_lib/messaging/models/media.rb +5 -75
- data/lib/bandwidth/models/base_model.rb +19 -8
- data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth.rb +23 -0
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/client.rb +15 -6
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/controllers/base_controller.rb +0 -0
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/controllers/mfa_controller.rb +7 -7
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/exceptions/error_with_request_exception.rb +0 -0
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/exceptions/forbidden_request_exception.rb +0 -0
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/exceptions/unauthorized_request_exception.rb +0 -0
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_code_request_schema.rb +0 -0
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_messaging_response.rb +0 -0
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_verify_code_response.rb +0 -0
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_verify_request_schema.rb +0 -0
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_voice_response.rb +0 -0
- data/lib/bandwidth/utilities/date_time_helper.rb +156 -0
- data/lib/bandwidth/voice_lib/voice.rb +14 -18
- data/lib/bandwidth/voice_lib/voice/client.rb +14 -5
- data/lib/bandwidth/voice_lib/voice/controllers/api_controller.rb +248 -230
- data/lib/bandwidth/voice_lib/voice/exceptions/{api_error_response_exception.rb → api_error_exception.rb} +2 -2
- data/lib/bandwidth/voice_lib/voice/models/{recording_metadata_response.rb → call_recording_metadata.rb} +47 -28
- data/lib/bandwidth/voice_lib/voice/models/call_state.rb +232 -0
- data/lib/bandwidth/voice_lib/voice/models/callback_method_enum.rb +2 -20
- data/lib/bandwidth/voice_lib/voice/models/conference_event_method_enum.rb +2 -20
- data/lib/bandwidth/voice_lib/voice/models/{conference_member_detail.rb → conference_member_state.rb} +8 -8
- data/lib/bandwidth/voice_lib/voice/models/{conference_recording_metadata_response.rb → conference_recording_metadata.rb} +34 -18
- data/lib/bandwidth/voice_lib/voice/models/{conference_detail.rb → conference_state.rb} +22 -14
- data/lib/bandwidth/voice_lib/voice/models/{api_create_call_request.rb → create_call_request.rb} +35 -59
- data/lib/bandwidth/voice_lib/voice/models/{api_call_response.rb → create_call_response.rb} +28 -23
- data/lib/bandwidth/voice_lib/voice/models/{modify_call_recording_state.rb → modify_call_recording_request.rb} +4 -4
- data/lib/bandwidth/voice_lib/voice/models/{api_modify_call_request.rb → modify_call_request.rb} +25 -25
- data/lib/bandwidth/voice_lib/voice/models/{api_modify_conference_request.rb → modify_conference_request.rb} +11 -11
- data/lib/bandwidth/voice_lib/voice/models/state1_enum.rb +7 -4
- data/lib/bandwidth/voice_lib/voice/models/state_enum.rb +4 -7
- data/lib/bandwidth/voice_lib/voice/models/{api_transcribe_recording_request.rb → transcribe_recording_request.rb} +8 -8
- data/lib/bandwidth/voice_lib/voice/models/{transcription.rb → transcription_metadata.rb} +19 -10
- data/lib/bandwidth/web_rtc_lib/web_rtc/client.rb +4 -4
- data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb +14 -14
- data/test/integration/test_integration.rb +13 -13
- metadata +29 -32
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth.rb +0 -22
- data/lib/bandwidth/voice_lib/voice/models/api_call_state_response.rb +0 -164
- data/lib/bandwidth/voice_lib/voice/models/disconnect_cause_enum.rb +0 -47
- data/lib/bandwidth/voice_lib/voice/models/state2_enum.rb +0 -20
- data/lib/bandwidth/voice_lib/voice/models/status1_enum.rb +0 -29
- data/lib/bandwidth/voice_lib/voice/models/status3_enum.rb +0 -32
@@ -6,82 +6,33 @@
|
|
6
6
|
module Bandwidth
|
7
7
|
# Media Model.
|
8
8
|
class Media < BaseModel
|
9
|
-
# TODO: Write general description for this method
|
10
|
-
# @return [Object]
|
11
|
-
attr_accessor :input_stream
|
12
|
-
|
13
9
|
# TODO: Write general description for this method
|
14
10
|
# @return [String]
|
15
11
|
attr_accessor :content
|
16
12
|
|
17
13
|
# TODO: Write general description for this method
|
18
|
-
# @return [
|
19
|
-
attr_accessor :url
|
20
|
-
|
21
|
-
# TODO: Write general description for this method
|
22
|
-
# @return [String]
|
14
|
+
# @return [Integer]
|
23
15
|
attr_accessor :content_length
|
24
16
|
|
25
17
|
# TODO: Write general description for this method
|
26
18
|
# @return [String]
|
27
|
-
attr_accessor :content_type
|
28
|
-
|
29
|
-
# TODO: Write general description for this method
|
30
|
-
# @return [List of Tag]
|
31
|
-
attr_accessor :tags
|
32
|
-
|
33
|
-
# User's account ID
|
34
|
-
# @return [String]
|
35
|
-
attr_accessor :user_id
|
36
|
-
|
37
|
-
# User's account ID
|
38
|
-
# @return [String]
|
39
19
|
attr_accessor :media_name
|
40
20
|
|
41
|
-
# User's account ID
|
42
|
-
# @return [String]
|
43
|
-
attr_accessor :media_id
|
44
|
-
|
45
|
-
# User's account ID
|
46
|
-
# @return [String]
|
47
|
-
attr_accessor :cache_control
|
48
|
-
|
49
21
|
# A mapping from model property names to API property names.
|
50
22
|
def self.names
|
51
23
|
@_hash = {} if @_hash.nil?
|
52
|
-
@_hash['input_stream'] = 'inputStream'
|
53
24
|
@_hash['content'] = 'content'
|
54
|
-
@_hash['url'] = 'url'
|
55
25
|
@_hash['content_length'] = 'contentLength'
|
56
|
-
@_hash['content_type'] = 'contentType'
|
57
|
-
@_hash['tags'] = 'tags'
|
58
|
-
@_hash['user_id'] = 'userId'
|
59
26
|
@_hash['media_name'] = 'mediaName'
|
60
|
-
@_hash['media_id'] = 'mediaId'
|
61
|
-
@_hash['cache_control'] = 'cacheControl'
|
62
27
|
@_hash
|
63
28
|
end
|
64
29
|
|
65
|
-
def initialize(
|
66
|
-
content = nil,
|
67
|
-
url = nil,
|
30
|
+
def initialize(content = nil,
|
68
31
|
content_length = nil,
|
69
|
-
|
70
|
-
tags = nil,
|
71
|
-
user_id = nil,
|
72
|
-
media_name = nil,
|
73
|
-
media_id = nil,
|
74
|
-
cache_control = nil)
|
75
|
-
@input_stream = input_stream
|
32
|
+
media_name = nil)
|
76
33
|
@content = content
|
77
|
-
@url = url
|
78
34
|
@content_length = content_length
|
79
|
-
@content_type = content_type
|
80
|
-
@tags = tags
|
81
|
-
@user_id = user_id
|
82
35
|
@media_name = media_name
|
83
|
-
@media_id = media_id
|
84
|
-
@cache_control = cache_control
|
85
36
|
end
|
86
37
|
|
87
38
|
# Creates an instance of the object from a hash.
|
@@ -89,35 +40,14 @@ module Bandwidth
|
|
89
40
|
return nil unless hash
|
90
41
|
|
91
42
|
# Extract variables from the hash.
|
92
|
-
input_stream = hash['inputStream']
|
93
43
|
content = hash['content']
|
94
|
-
url = hash['url']
|
95
44
|
content_length = hash['contentLength']
|
96
|
-
content_type = hash['contentType']
|
97
|
-
# Parameter is an array, so we need to iterate through it
|
98
|
-
tags = nil
|
99
|
-
unless hash['tags'].nil?
|
100
|
-
tags = []
|
101
|
-
hash['tags'].each do |structure|
|
102
|
-
tags << (Tag.from_hash(structure) if structure)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
user_id = hash['userId']
|
106
45
|
media_name = hash['mediaName']
|
107
|
-
media_id = hash['mediaId']
|
108
|
-
cache_control = hash['cacheControl']
|
109
46
|
|
110
47
|
# Create object from extracted values.
|
111
|
-
Media.new(
|
112
|
-
content,
|
113
|
-
url,
|
48
|
+
Media.new(content,
|
114
49
|
content_length,
|
115
|
-
|
116
|
-
tags,
|
117
|
-
user_id,
|
118
|
-
media_name,
|
119
|
-
media_id,
|
120
|
-
cache_control)
|
50
|
+
media_name)
|
121
51
|
end
|
122
52
|
end
|
123
53
|
end
|
@@ -13,15 +13,26 @@ module Bandwidth
|
|
13
13
|
value = instance_variable_get(name)
|
14
14
|
name = name[1..-1]
|
15
15
|
key = self.class.names.key?(name) ? self.class.names[name] : name
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
|
17
|
+
hash[key] = nil
|
18
|
+
unless value.nil?
|
19
|
+
if respond_to?("to_#{name}")
|
20
|
+
if (value.instance_of? Array) || (value.instance_of? Hash)
|
21
|
+
params = [hash, key]
|
22
|
+
hash[key] = send("to_#{name}", *params)
|
23
|
+
else
|
24
|
+
hash[key] = send("to_#{name}")
|
25
|
+
end
|
26
|
+
elsif value.instance_of? Array
|
27
|
+
hash[key] = value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
|
28
|
+
elsif value.instance_of? Hash
|
29
|
+
hash[key] = {}
|
30
|
+
value.each do |k, v|
|
31
|
+
hash[key][k] = v.is_a?(BaseModel) ? v.to_hash : v
|
32
|
+
end
|
33
|
+
else
|
34
|
+
hash[key] = value.is_a?(BaseModel) ? value.to_hash : value
|
22
35
|
end
|
23
|
-
else
|
24
|
-
hash[key] = value.is_a?(BaseModel) ? value.to_hash : value
|
25
36
|
end
|
26
37
|
end
|
27
38
|
hash
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
|
7
|
+
require_relative 'multi_factor_auth/client.rb'
|
8
|
+
|
9
|
+
# Models
|
10
|
+
require_relative 'multi_factor_auth/models/two_factor_code_request_schema.rb'
|
11
|
+
require_relative 'multi_factor_auth/models/two_factor_voice_response.rb'
|
12
|
+
require_relative 'multi_factor_auth/models/two_factor_messaging_response.rb'
|
13
|
+
require_relative 'multi_factor_auth/models/two_factor_verify_request_schema.rb'
|
14
|
+
require_relative 'multi_factor_auth/models/two_factor_verify_code_response.rb'
|
15
|
+
|
16
|
+
# Exceptions
|
17
|
+
require_relative 'multi_factor_auth/exceptions/error_with_request_exception.rb'
|
18
|
+
require_relative 'multi_factor_auth/exceptions/unauthorized_request' \
|
19
|
+
'_exception.rb'
|
20
|
+
require_relative 'multi_factor_auth/exceptions/forbidden_request_exception.rb'
|
21
|
+
# Controllers
|
22
|
+
require_relative 'multi_factor_auth/controllers/base_controller.rb'
|
23
|
+
require_relative 'multi_factor_auth/controllers/mfa_controller.rb'
|
@@ -4,7 +4,7 @@
|
|
4
4
|
# ( https://apimatic.io ).
|
5
5
|
|
6
6
|
module Bandwidth
|
7
|
-
module
|
7
|
+
module MultiFactorAuth
|
8
8
|
# bandwidth client class.
|
9
9
|
class Client
|
10
10
|
attr_reader :config
|
@@ -16,12 +16,17 @@ module Bandwidth
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
|
19
|
-
backoff_factor:
|
19
|
+
backoff_factor: 2,
|
20
|
+
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524, 408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
21
|
+
retry_methods: %i[get put get put],
|
22
|
+
environment: Environment::PRODUCTION,
|
20
23
|
base_url: 'https://www.example.com',
|
21
24
|
messaging_basic_auth_user_name: 'TODO: Replace',
|
22
25
|
messaging_basic_auth_password: 'TODO: Replace',
|
23
|
-
|
24
|
-
|
26
|
+
multi_factor_auth_basic_auth_user_name: 'TODO: Replace',
|
27
|
+
multi_factor_auth_basic_auth_password: 'TODO: Replace',
|
28
|
+
phone_number_lookup_basic_auth_user_name: 'TODO: Replace',
|
29
|
+
phone_number_lookup_basic_auth_password: 'TODO: Replace',
|
25
30
|
voice_basic_auth_user_name: 'TODO: Replace',
|
26
31
|
voice_basic_auth_password: 'TODO: Replace',
|
27
32
|
web_rtc_basic_auth_user_name: 'TODO: Replace',
|
@@ -32,12 +37,16 @@ module Bandwidth
|
|
32
37
|
max_retries: max_retries,
|
33
38
|
retry_interval: retry_interval,
|
34
39
|
backoff_factor: backoff_factor,
|
40
|
+
retry_statuses: retry_statuses,
|
41
|
+
retry_methods: retry_methods,
|
35
42
|
environment: environment,
|
36
43
|
base_url: base_url,
|
37
44
|
messaging_basic_auth_user_name: messaging_basic_auth_user_name,
|
38
45
|
messaging_basic_auth_password: messaging_basic_auth_password,
|
39
|
-
|
40
|
-
|
46
|
+
multi_factor_auth_basic_auth_user_name: multi_factor_auth_basic_auth_user_name,
|
47
|
+
multi_factor_auth_basic_auth_password: multi_factor_auth_basic_auth_password,
|
48
|
+
phone_number_lookup_basic_auth_user_name: phone_number_lookup_basic_auth_user_name,
|
49
|
+
phone_number_lookup_basic_auth_password: phone_number_lookup_basic_auth_password,
|
41
50
|
voice_basic_auth_user_name: voice_basic_auth_user_name,
|
42
51
|
voice_basic_auth_password: voice_basic_auth_password,
|
43
52
|
web_rtc_basic_auth_user_name: web_rtc_basic_auth_user_name,
|
File without changes
|
@@ -4,7 +4,7 @@
|
|
4
4
|
# ( https://apimatic.io ).
|
5
5
|
|
6
6
|
module Bandwidth
|
7
|
-
module
|
7
|
+
module MultiFactorAuth
|
8
8
|
# MFAController
|
9
9
|
class MFAController < BaseController
|
10
10
|
def initialize(config, http_call_back: nil)
|
@@ -19,7 +19,7 @@ module TwoFactorAuth
|
|
19
19
|
def create_voice_two_factor(account_id,
|
20
20
|
body)
|
21
21
|
# Prepare query url.
|
22
|
-
_query_builder = config.get_base_uri(Server::
|
22
|
+
_query_builder = config.get_base_uri(Server::MULTIFACTORAUTHDEFAULT)
|
23
23
|
_query_builder << '/accounts/{accountId}/code/voice'
|
24
24
|
_query_builder = APIHelper.append_url_with_template_parameters(
|
25
25
|
_query_builder,
|
@@ -39,7 +39,7 @@ module TwoFactorAuth
|
|
39
39
|
headers: _headers,
|
40
40
|
parameters: body.to_json
|
41
41
|
)
|
42
|
-
|
42
|
+
MultiFactorAuthBasicAuth.apply(config, _request)
|
43
43
|
_response = execute_request(_request)
|
44
44
|
|
45
45
|
# Validate response against endpoint and global error codes.
|
@@ -81,7 +81,7 @@ module TwoFactorAuth
|
|
81
81
|
def create_messaging_two_factor(account_id,
|
82
82
|
body)
|
83
83
|
# Prepare query url.
|
84
|
-
_query_builder = config.get_base_uri(Server::
|
84
|
+
_query_builder = config.get_base_uri(Server::MULTIFACTORAUTHDEFAULT)
|
85
85
|
_query_builder << '/accounts/{accountId}/code/messaging'
|
86
86
|
_query_builder = APIHelper.append_url_with_template_parameters(
|
87
87
|
_query_builder,
|
@@ -101,7 +101,7 @@ module TwoFactorAuth
|
|
101
101
|
headers: _headers,
|
102
102
|
parameters: body.to_json
|
103
103
|
)
|
104
|
-
|
104
|
+
MultiFactorAuthBasicAuth.apply(config, _request)
|
105
105
|
_response = execute_request(_request)
|
106
106
|
|
107
107
|
# Validate response against endpoint and global error codes.
|
@@ -144,7 +144,7 @@ module TwoFactorAuth
|
|
144
144
|
def create_verify_two_factor(account_id,
|
145
145
|
body)
|
146
146
|
# Prepare query url.
|
147
|
-
_query_builder = config.get_base_uri(Server::
|
147
|
+
_query_builder = config.get_base_uri(Server::MULTIFACTORAUTHDEFAULT)
|
148
148
|
_query_builder << '/accounts/{accountId}/code/verify'
|
149
149
|
_query_builder = APIHelper.append_url_with_template_parameters(
|
150
150
|
_query_builder,
|
@@ -164,7 +164,7 @@ module TwoFactorAuth
|
|
164
164
|
headers: _headers,
|
165
165
|
parameters: body.to_json
|
166
166
|
)
|
167
|
-
|
167
|
+
MultiFactorAuthBasicAuth.apply(config, _request)
|
168
168
|
_response = execute_request(_request)
|
169
169
|
|
170
170
|
# Validate response against endpoint and global error codes.
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
require 'date'
|
7
|
+
module Bandwidth
|
8
|
+
# A utility that supports dateTime conversion to different formats
|
9
|
+
class DateTimeHelper
|
10
|
+
# Safely converts a DateTime object into a rfc1123 format string
|
11
|
+
# @param [DateTime] The DateTime object
|
12
|
+
# @return [String] The rfc1123 formatted datetime string
|
13
|
+
def self.to_rfc1123(date_time)
|
14
|
+
date_time.httpdate unless date_time.nil?
|
15
|
+
end
|
16
|
+
|
17
|
+
# Safely converts a map of DateTime objects into a map of rfc1123 format string
|
18
|
+
# @param [hash] a map of DateTime objects
|
19
|
+
# @return [hash] a map of rfc1123 formatted datetime string
|
20
|
+
def self.to_rfc1123_map(date_time, hash, key)
|
21
|
+
return if date_time.nil?
|
22
|
+
|
23
|
+
hash[key] = {}
|
24
|
+
date_time.each do |k, v|
|
25
|
+
hash[key][k] =
|
26
|
+
if v.is_a?(BaseModel)
|
27
|
+
v.to_hash
|
28
|
+
else
|
29
|
+
v.is_a?(DateTime) ? DateTimeHelper.to_rfc1123(v) : v
|
30
|
+
end
|
31
|
+
end
|
32
|
+
hash[key]
|
33
|
+
end
|
34
|
+
|
35
|
+
# Safely converts an array of DateTime objects into an array of rfc1123 format string
|
36
|
+
# @param [Array] an array of DateTime objects
|
37
|
+
# @return [Array] an array of rfc1123 formatted datetime string
|
38
|
+
def self.to_rfc1123_array(date_time, hash, key)
|
39
|
+
return if date_time.nil?
|
40
|
+
|
41
|
+
hash[key] = date_time.map do |v|
|
42
|
+
if v.is_a?(BaseModel)
|
43
|
+
v.to_hash
|
44
|
+
else
|
45
|
+
v.is_a?(DateTime) ? DateTimeHelper.to_rfc1123(v) : v
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Safely converts a DateTime object into a unix format string
|
51
|
+
# @param [DateTime] The DateTime object
|
52
|
+
# @return [String] The unix formatted datetime string
|
53
|
+
def self.to_unix(date_time)
|
54
|
+
date_time.to_time.utc.to_i unless date_time.nil?
|
55
|
+
end
|
56
|
+
|
57
|
+
# Safely converts a map of DateTime objects into a map of unix format string
|
58
|
+
# @param [hash] a map of DateTime objects
|
59
|
+
# @return [hash] a map of unix formatted datetime string
|
60
|
+
def self.to_unix_map(date_time, hash, key)
|
61
|
+
return if date_time.nil?
|
62
|
+
|
63
|
+
hash[key] = {}
|
64
|
+
date_time.each do |k, v|
|
65
|
+
hash[key][k] =
|
66
|
+
if v.is_a?(BaseModel)
|
67
|
+
v.to_hash
|
68
|
+
else
|
69
|
+
v.is_a?(DateTime) ? DateTimeHelper.to_unix(v) : v
|
70
|
+
end
|
71
|
+
end
|
72
|
+
hash[key]
|
73
|
+
end
|
74
|
+
|
75
|
+
# Safely converts an array of DateTime objects into a map of unix format string
|
76
|
+
# @param [hash] an array of DateTime objects
|
77
|
+
# @return [hash] an array of unix formatted datetime string
|
78
|
+
def self.to_unix_array(date_time, hash, key)
|
79
|
+
return if date_time.nil?
|
80
|
+
|
81
|
+
hash[key] = date_time.map do |v|
|
82
|
+
if v.is_a?(BaseModel)
|
83
|
+
v.to_hash
|
84
|
+
else
|
85
|
+
v.is_a?(DateTime) ? DateTimeHelper.to_unix(v) : v
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Safely converts a DateTime object into a rfc3339 format string
|
91
|
+
# @param [DateTime] The DateTime object
|
92
|
+
# @return [String] The rfc3339 formatted datetime string
|
93
|
+
def self.to_rfc3339(date_time)
|
94
|
+
date_time.rfc3339 unless date_time.nil?
|
95
|
+
end
|
96
|
+
|
97
|
+
# Safely converts a map of DateTime objects into a map of rfc1123 format string
|
98
|
+
# @param [hash] a map of DateTime objects
|
99
|
+
# @return [hash] a map of rfc1123 formatted datetime string
|
100
|
+
def self.to_rfc3339_map(date_time, hash, key)
|
101
|
+
return if date_time.nil?
|
102
|
+
|
103
|
+
hash[key] = {}
|
104
|
+
date_time.each do |k, v|
|
105
|
+
hash[key][k] =
|
106
|
+
if v.is_a?(BaseModel)
|
107
|
+
v.to_hash
|
108
|
+
else
|
109
|
+
v.is_a?(DateTime) ? DateTimeHelper.to_rfc3339(v) : v
|
110
|
+
end
|
111
|
+
end
|
112
|
+
hash[key]
|
113
|
+
end
|
114
|
+
|
115
|
+
# Safely converts an array of DateTime objects into an array of rfc1123 format string
|
116
|
+
# @param [Array] an array of DateTime objects
|
117
|
+
# @return [Array] an array of rfc1123 formatted datetime string
|
118
|
+
def self.to_rfc3339_array(date_time, hash, key)
|
119
|
+
return if date_time.nil?
|
120
|
+
|
121
|
+
hash[key] = date_time.map do |v|
|
122
|
+
if v.is_a?(BaseModel)
|
123
|
+
v.to_hash
|
124
|
+
else
|
125
|
+
v.is_a?(DateTime) ? DateTimeHelper.to_rfc3339(v) : v
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# Safely converts a rfc1123 format string into a DateTime object
|
131
|
+
# @param [String] The rfc1123 formatted datetime string
|
132
|
+
# @return [DateTime] A DateTime object
|
133
|
+
def self.from_rfc1123(date_time)
|
134
|
+
DateTime.httpdate(date_time)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Safely converts a unix format string into a DateTime object
|
138
|
+
# @param [String] The unix formatted datetime string
|
139
|
+
# @return [DateTime] A DateTime object
|
140
|
+
def self.from_unix(date_time)
|
141
|
+
Time.at(date_time.to_i).utc.to_datetime
|
142
|
+
end
|
143
|
+
|
144
|
+
# Safely converts a rfc3339 format string into a DateTime object
|
145
|
+
# @param [String] The rfc3339 formatted datetime string
|
146
|
+
# @return [DateTime] A DateTime object
|
147
|
+
def self.from_rfc3339(date_time)
|
148
|
+
# missing timezone information
|
149
|
+
if date_time.end_with?('Z') || date_time.index('+')
|
150
|
+
DateTime.rfc3339(date_time)
|
151
|
+
else
|
152
|
+
DateTime.rfc3339("#{date_time}Z")
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|