bandwidth-sdk 6.1.0 → 8.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +89 -12
- data/lib/bandwidth.rb +5 -2
- data/lib/bandwidth/api_helper.rb +5 -17
- data/lib/bandwidth/client.rb +23 -9
- data/lib/bandwidth/configuration.rb +54 -18
- data/lib/bandwidth/http/auth/{two_factor_auth_basic_auth.rb → multi_factor_auth_basic_auth.rb} +3 -3
- data/lib/bandwidth/http/auth/phone_number_lookup_basic_auth.rb +22 -0
- data/lib/bandwidth/http/faraday_client.rb +5 -2
- 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/phone_number_lookup_lib/phone_number_lookup.rb +20 -0
- data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/client.rb +60 -0
- data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/controllers/api_controller.rb +1551 -0
- data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/controllers/base_controller.rb +49 -0
- data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/exceptions/accounts_tnlookup400_error_exception.rb +29 -0
- data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/order_request.rb +35 -0
- data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/order_response.rb +45 -0
- data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/order_status.rb +74 -0
- data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb +107 -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/utils/web_rtc_transfer.rb +7 -2
- data/lib/bandwidth/web_rtc_lib/web_rtc/client.rb +14 -5
- data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb +14 -14
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/device_api_version_enum.rb +2 -2
- data/test/controllers/controller_test_base.rb +21 -0
- data/test/http_response_catcher.rb +19 -0
- data/test/integration/test_integration.rb +39 -13
- data/test/test_helper.rb +94 -0
- metadata +47 -37
- 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
@@ -0,0 +1,49 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# BaseController.
|
8
|
+
class BaseController
|
9
|
+
attr_accessor :config, :http_call_back
|
10
|
+
|
11
|
+
def initialize(config, http_call_back: nil)
|
12
|
+
@config = config
|
13
|
+
@http_call_back = http_call_back
|
14
|
+
|
15
|
+
@global_headers = {
|
16
|
+
'user-agent' => 'ruby-sdk'
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate_parameters(args)
|
21
|
+
args.each do |_name, value|
|
22
|
+
if value.nil?
|
23
|
+
raise ArgumentError, "Required parameter #{_name} cannot be nil."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def execute_request(request, binary: false)
|
29
|
+
@http_call_back.on_before_request(request) if @http_call_back
|
30
|
+
|
31
|
+
APIHelper.clean_hash(request.headers)
|
32
|
+
request.headers.merge!(@global_headers)
|
33
|
+
|
34
|
+
response = if binary
|
35
|
+
config.http_client.execute_as_binary(request)
|
36
|
+
else
|
37
|
+
config.http_client.execute_as_string(request)
|
38
|
+
end
|
39
|
+
@http_call_back.on_after_response(response) if @http_call_back
|
40
|
+
|
41
|
+
response
|
42
|
+
end
|
43
|
+
|
44
|
+
def validate_response(response)
|
45
|
+
raise APIException.new 'HTTP Response Not OK', response unless
|
46
|
+
response.status_code.between?(200, 208) # [200,208] = HTTP OK
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# Accounts Tnlookup 400 Error class.
|
8
|
+
class AccountsTnlookup400ErrorException < APIException
|
9
|
+
# A description of what validation error occurred.
|
10
|
+
# @return [String]
|
11
|
+
attr_accessor :message
|
12
|
+
|
13
|
+
# The constructor.
|
14
|
+
# @param [String] The reason for raising an exception.
|
15
|
+
# @param [HttpResponse] The HttpReponse of the API call.
|
16
|
+
def initialize(reason, response)
|
17
|
+
super(reason, response)
|
18
|
+
hash = APIHelper.json_deserialize(@response.raw_body)
|
19
|
+
unbox(hash)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Populates this object by extracting properties from a hash.
|
23
|
+
# @param [Hash] The deserialized response sent by the server in the
|
24
|
+
# response body.
|
25
|
+
def unbox(hash)
|
26
|
+
@message = hash['message']
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# Create TN Lookup Request
|
8
|
+
class OrderRequest < BaseModel
|
9
|
+
# TODO: Write general description for this method
|
10
|
+
# @return [List of String]
|
11
|
+
attr_accessor :tns
|
12
|
+
|
13
|
+
# A mapping from model property names to API property names.
|
14
|
+
def self.names
|
15
|
+
@_hash = {} if @_hash.nil?
|
16
|
+
@_hash['tns'] = 'tns'
|
17
|
+
@_hash
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(tns = nil)
|
21
|
+
@tns = tns
|
22
|
+
end
|
23
|
+
|
24
|
+
# Creates an instance of the object from a hash.
|
25
|
+
def self.from_hash(hash)
|
26
|
+
return nil unless hash
|
27
|
+
|
28
|
+
# Extract variables from the hash.
|
29
|
+
tns = hash['tns']
|
30
|
+
|
31
|
+
# Create object from extracted values.
|
32
|
+
OrderRequest.new(tns)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# The request has been accepted for processing but not yet finished and in a
|
8
|
+
# terminal state (COMPLETE, PARTIAL_COMPLETE, or FAILED)
|
9
|
+
class OrderResponse < BaseModel
|
10
|
+
# TODO: Write general description for this method
|
11
|
+
# @return [String]
|
12
|
+
attr_accessor :request_id
|
13
|
+
|
14
|
+
# TODO: Write general description for this method
|
15
|
+
# @return [String]
|
16
|
+
attr_accessor :status
|
17
|
+
|
18
|
+
# A mapping from model property names to API property names.
|
19
|
+
def self.names
|
20
|
+
@_hash = {} if @_hash.nil?
|
21
|
+
@_hash['request_id'] = 'requestId'
|
22
|
+
@_hash['status'] = 'status'
|
23
|
+
@_hash
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(request_id = nil,
|
27
|
+
status = nil)
|
28
|
+
@request_id = request_id
|
29
|
+
@status = status
|
30
|
+
end
|
31
|
+
|
32
|
+
# Creates an instance of the object from a hash.
|
33
|
+
def self.from_hash(hash)
|
34
|
+
return nil unless hash
|
35
|
+
|
36
|
+
# Extract variables from the hash.
|
37
|
+
request_id = hash['requestId']
|
38
|
+
status = hash['status']
|
39
|
+
|
40
|
+
# Create object from extracted values.
|
41
|
+
OrderResponse.new(request_id,
|
42
|
+
status)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# If requestId exists, the result for that request is returned. See the
|
8
|
+
# Examples for details on the various responses that you can receive.
|
9
|
+
# Generally, if you see a Response Code of 0 in a result for a TN, information
|
10
|
+
# will be available for it. Any other Response Code will indicate no
|
11
|
+
# information was available for the TN.
|
12
|
+
class OrderStatus < BaseModel
|
13
|
+
# The requestId.
|
14
|
+
# @return [String]
|
15
|
+
attr_accessor :request_id
|
16
|
+
|
17
|
+
# The status of the request (IN_PROGRESS, COMPLETE, PARTIAL_COMPLETE, or
|
18
|
+
# FAILED).
|
19
|
+
# @return [String]
|
20
|
+
attr_accessor :status
|
21
|
+
|
22
|
+
# The telephone numbers whose lookup failed
|
23
|
+
# @return [List of String]
|
24
|
+
attr_accessor :failed_telephone_numbers
|
25
|
+
|
26
|
+
# The carrier information results for the specified telephone number.
|
27
|
+
# @return [List of Result]
|
28
|
+
attr_accessor :result
|
29
|
+
|
30
|
+
# A mapping from model property names to API property names.
|
31
|
+
def self.names
|
32
|
+
@_hash = {} if @_hash.nil?
|
33
|
+
@_hash['request_id'] = 'requestId'
|
34
|
+
@_hash['status'] = 'status'
|
35
|
+
@_hash['failed_telephone_numbers'] = 'failedTelephoneNumbers'
|
36
|
+
@_hash['result'] = 'result'
|
37
|
+
@_hash
|
38
|
+
end
|
39
|
+
|
40
|
+
def initialize(request_id = nil,
|
41
|
+
status = nil,
|
42
|
+
failed_telephone_numbers = nil,
|
43
|
+
result = nil)
|
44
|
+
@request_id = request_id
|
45
|
+
@status = status
|
46
|
+
@failed_telephone_numbers = failed_telephone_numbers
|
47
|
+
@result = result
|
48
|
+
end
|
49
|
+
|
50
|
+
# Creates an instance of the object from a hash.
|
51
|
+
def self.from_hash(hash)
|
52
|
+
return nil unless hash
|
53
|
+
|
54
|
+
# Extract variables from the hash.
|
55
|
+
request_id = hash['requestId']
|
56
|
+
status = hash['status']
|
57
|
+
failed_telephone_numbers = hash['failedTelephoneNumbers']
|
58
|
+
# Parameter is an array, so we need to iterate through it
|
59
|
+
result = nil
|
60
|
+
unless hash['result'].nil?
|
61
|
+
result = []
|
62
|
+
hash['result'].each do |structure|
|
63
|
+
result << (Result.from_hash(structure) if structure)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Create object from extracted values.
|
68
|
+
OrderStatus.new(request_id,
|
69
|
+
status,
|
70
|
+
failed_telephone_numbers,
|
71
|
+
result)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# Result Model.
|
8
|
+
class Result < BaseModel
|
9
|
+
# Our vendor's response code.
|
10
|
+
# @return [Integer]
|
11
|
+
attr_accessor :response_code
|
12
|
+
|
13
|
+
# Message associated with the response code.
|
14
|
+
# @return [String]
|
15
|
+
attr_accessor :message
|
16
|
+
|
17
|
+
# The telephone number in E.164 format.
|
18
|
+
# @return [String]
|
19
|
+
attr_accessor :e_164_format
|
20
|
+
|
21
|
+
# The formatted version of the telephone number.
|
22
|
+
# @return [String]
|
23
|
+
attr_accessor :formatted
|
24
|
+
|
25
|
+
# The country of the telephone number.
|
26
|
+
# @return [String]
|
27
|
+
attr_accessor :country
|
28
|
+
|
29
|
+
# The line type of the telephone number.
|
30
|
+
# @return [String]
|
31
|
+
attr_accessor :line_type
|
32
|
+
|
33
|
+
# The service provider of the telephone number.
|
34
|
+
# @return [String]
|
35
|
+
attr_accessor :line_provider
|
36
|
+
|
37
|
+
# The first half of the Home Network Identity (HNI).
|
38
|
+
# @return [String]
|
39
|
+
attr_accessor :mobile_country_code
|
40
|
+
|
41
|
+
# The second half of the HNI.
|
42
|
+
# @return [String]
|
43
|
+
attr_accessor :mobile_network_code
|
44
|
+
|
45
|
+
# A mapping from model property names to API property names.
|
46
|
+
def self.names
|
47
|
+
@_hash = {} if @_hash.nil?
|
48
|
+
@_hash['response_code'] = 'Response Code'
|
49
|
+
@_hash['message'] = 'Message'
|
50
|
+
@_hash['e_164_format'] = 'E.164 Format'
|
51
|
+
@_hash['formatted'] = 'Formatted'
|
52
|
+
@_hash['country'] = 'Country'
|
53
|
+
@_hash['line_type'] = 'Line Type'
|
54
|
+
@_hash['line_provider'] = 'Line Provider'
|
55
|
+
@_hash['mobile_country_code'] = 'Mobile Country Code'
|
56
|
+
@_hash['mobile_network_code'] = 'Mobile Network Code'
|
57
|
+
@_hash
|
58
|
+
end
|
59
|
+
|
60
|
+
def initialize(response_code = nil,
|
61
|
+
message = nil,
|
62
|
+
e_164_format = nil,
|
63
|
+
formatted = nil,
|
64
|
+
country = nil,
|
65
|
+
line_type = nil,
|
66
|
+
line_provider = nil,
|
67
|
+
mobile_country_code = nil,
|
68
|
+
mobile_network_code = nil)
|
69
|
+
@response_code = response_code
|
70
|
+
@message = message
|
71
|
+
@e_164_format = e_164_format
|
72
|
+
@formatted = formatted
|
73
|
+
@country = country
|
74
|
+
@line_type = line_type
|
75
|
+
@line_provider = line_provider
|
76
|
+
@mobile_country_code = mobile_country_code
|
77
|
+
@mobile_network_code = mobile_network_code
|
78
|
+
end
|
79
|
+
|
80
|
+
# Creates an instance of the object from a hash.
|
81
|
+
def self.from_hash(hash)
|
82
|
+
return nil unless hash
|
83
|
+
|
84
|
+
# Extract variables from the hash.
|
85
|
+
response_code = hash['Response Code']
|
86
|
+
message = hash['Message']
|
87
|
+
e_164_format = hash['E.164 Format']
|
88
|
+
formatted = hash['Formatted']
|
89
|
+
country = hash['Country']
|
90
|
+
line_type = hash['Line Type']
|
91
|
+
line_provider = hash['Line Provider']
|
92
|
+
mobile_country_code = hash['Mobile Country Code']
|
93
|
+
mobile_network_code = hash['Mobile Network Code']
|
94
|
+
|
95
|
+
# Create object from extracted values.
|
96
|
+
Result.new(response_code,
|
97
|
+
message,
|
98
|
+
e_164_format,
|
99
|
+
formatted,
|
100
|
+
country,
|
101
|
+
line_type,
|
102
|
+
line_provider,
|
103
|
+
mobile_country_code,
|
104
|
+
mobile_network_code)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -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
|