bluevia 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,256 @@
1
+ require 'xsd/qname'
2
+
3
+ module Schemas; module Sms_types
4
+
5
+
6
+ # {http://www.telefonica.com/schemas/UNICA/REST/sms/v1/}SMSTextType
7
+ # address - Schemas::Sms_types::UserIdType
8
+ # message - SOAP::SOAPString
9
+ # receiptRequest - Schemas::Sms_types::SimpleReferenceType
10
+ # originAddress - Schemas::Sms_types::UserIdType
11
+ # encode - SOAP::SOAPString
12
+ # sourceport - SOAP::SOAPInt
13
+ # destinationport - SOAP::SOAPInt
14
+ # esm_class - SOAP::SOAPInt
15
+ # data_coding - SOAP::SOAPInt
16
+ class SMSTextType
17
+ attr_accessor :address
18
+ attr_accessor :message
19
+ attr_accessor :receiptRequest
20
+ attr_accessor :originAddress
21
+ attr_accessor :encode
22
+ attr_accessor :sourceport
23
+ attr_accessor :destinationport
24
+ attr_accessor :esm_class
25
+ attr_accessor :data_coding
26
+
27
+ def initialize(address = [], message = nil, receiptRequest = nil, originAddress = nil, encode = nil, sourceport = nil, destinationport = nil, esm_class = nil, data_coding = nil)
28
+ @address = address
29
+ @message = message
30
+ @receiptRequest = receiptRequest
31
+ @originAddress = originAddress
32
+ @encode = encode
33
+ @sourceport = sourceport
34
+ @destinationport = destinationport
35
+ @esm_class = esm_class
36
+ @data_coding = data_coding
37
+ end
38
+ end
39
+
40
+ # {http://www.telefonica.com/schemas/UNICA/REST/sms/v1/}SMSDeliveryStatusType
41
+ class SMSDeliveryStatusType < ::Array
42
+ end
43
+
44
+
45
+ # {http://www.telefonica.com/schemas/UNICA/REST/sms/v1/}ReceivedSMSType
46
+ class ReceivedSMSType < ::Array
47
+ end
48
+
49
+
50
+
51
+ # {http://www.telefonica.com/schemas/UNICA/REST/sms/v1/}DeliveryInformationType
52
+ # address - Schemas::Sms_types::UserIdType
53
+ # deliveryStatus - (any)
54
+ # description - SOAP::SOAPString
55
+ class DeliveryInformationType
56
+ attr_accessor :address
57
+ attr_accessor :deliveryStatus
58
+ attr_accessor :description
59
+
60
+ def initialize(address = nil, deliveryStatus = nil, description = nil)
61
+ @address = address
62
+ @deliveryStatus = deliveryStatus
63
+ @description = description
64
+ end
65
+ end
66
+
67
+ # {http://www.telefonica.com/schemas/UNICA/REST/sms/v1/}SMSMessageType
68
+ # message - SOAP::SOAPString
69
+ # originAddress - Schemas::Sms_types::UserIdType
70
+ # destinationAddress - Schemas::Sms_types::UserIdType
71
+ # dateTime - SOAP::SOAPDateTime
72
+ class SMSMessageType
73
+ attr_accessor :message
74
+ attr_accessor :originAddress
75
+ attr_accessor :destinationAddress
76
+ attr_accessor :dateTime
77
+
78
+ def initialize(message = nil, originAddress = nil, destinationAddress = nil, dateTime = nil)
79
+ @message = message
80
+ @originAddress = originAddress
81
+ @destinationAddress = destinationAddress
82
+ @dateTime = dateTime
83
+ end
84
+ end
85
+
86
+ # {http://www.telefonica.com/schemas/UNICA/REST/common/v1}AddressType
87
+ # street - SOAP::SOAPString
88
+ # streetNumber - SOAP::SOAPUnsignedInt
89
+ # locality - SOAP::SOAPString
90
+ # region - SOAP::SOAPString
91
+ # postalCode - SOAP::SOAPUnsignedInt
92
+ # country - SOAP::SOAPString
93
+ # ext - SOAP::SOAPString
94
+ class AddressType
95
+ attr_accessor :street
96
+ attr_accessor :streetNumber
97
+ attr_accessor :locality
98
+ attr_accessor :region
99
+ attr_accessor :postalCode
100
+ attr_accessor :country
101
+ attr_accessor :ext
102
+
103
+ def initialize(street = nil, streetNumber = nil, locality = nil, region = nil, postalCode = nil, country = nil, ext = nil)
104
+ @street = street
105
+ @streetNumber = streetNumber
106
+ @locality = locality
107
+ @region = region
108
+ @postalCode = postalCode
109
+ @country = country
110
+ @ext = ext
111
+ end
112
+ end
113
+
114
+ # {http://www.telefonica.com/schemas/UNICA/REST/common/v1}UserIdType
115
+ # phoneNumber - (any)
116
+ # anyUri - SOAP::SOAPAnyURI
117
+ # ipAddress - Schemas::Sms_types::IpAddressType
118
+ # m_alias - (any)
119
+ # otherId - Schemas::Sms_types::OtherIdType
120
+ class UserIdType
121
+ attr_accessor :phoneNumber
122
+ attr_accessor :anyUri
123
+ attr_accessor :ipAddress
124
+ attr_accessor :otherId
125
+
126
+ def m_alias
127
+ @v_alias
128
+ end
129
+
130
+ def m_alias=(value)
131
+ @v_alias = value
132
+ end
133
+
134
+ def initialize(phoneNumber = nil, anyUri = nil, ipAddress = nil, v_alias = nil, otherId = nil)
135
+ @phoneNumber = phoneNumber
136
+ @anyUri = anyUri
137
+ @ipAddress = ipAddress
138
+ @v_alias = v_alias
139
+ @otherId = otherId
140
+ end
141
+ end
142
+
143
+ # {http://www.telefonica.com/schemas/UNICA/REST/common/v1}IpAddressType
144
+ # ipv4 - (any)
145
+ # ipv6 - (any)
146
+ class IpAddressType
147
+ attr_accessor :ipv4
148
+ attr_accessor :ipv6
149
+
150
+ def initialize(ipv4 = nil, ipv6 = nil)
151
+ @ipv4 = ipv4
152
+ @ipv6 = ipv6
153
+ end
154
+ end
155
+
156
+ # {http://www.telefonica.com/schemas/UNICA/REST/common/v1}OtherIdType
157
+ # type - SOAP::SOAPString
158
+ # value - SOAP::SOAPString
159
+ class OtherIdType
160
+ attr_accessor :type
161
+ attr_accessor :value
162
+
163
+ def initialize(type = nil, value = nil)
164
+ @type = type
165
+ @value = value
166
+ end
167
+ end
168
+
169
+ # {http://www.telefonica.com/schemas/UNICA/REST/common/v1}ClientExceptionType
170
+ # exceptionCategory - SOAP::SOAPString
171
+ # exceptionId - SOAP::SOAPInt
172
+ # text - SOAP::SOAPString
173
+ # variables - SOAP::SOAPString
174
+ class ClientExceptionType
175
+ attr_accessor :exceptionCategory
176
+ attr_accessor :exceptionId
177
+ attr_accessor :text
178
+ attr_accessor :variables
179
+
180
+ def initialize(exceptionCategory = nil, exceptionId = nil, text = nil, variables = [])
181
+ @exceptionCategory = exceptionCategory
182
+ @exceptionId = exceptionId
183
+ @text = text
184
+ @variables = variables
185
+ end
186
+ end
187
+
188
+ # {http://www.telefonica.com/schemas/UNICA/REST/common/v1}ServerExceptionType
189
+ # exceptionCategory - SOAP::SOAPString
190
+ # exceptionId - SOAP::SOAPInt
191
+ # text - SOAP::SOAPString
192
+ # variables - SOAP::SOAPString
193
+ class ServerExceptionType
194
+ attr_accessor :exceptionCategory
195
+ attr_accessor :exceptionId
196
+ attr_accessor :text
197
+ attr_accessor :variables
198
+
199
+ def initialize(exceptionCategory = nil, exceptionId = nil, text = nil, variables = [])
200
+ @exceptionCategory = exceptionCategory
201
+ @exceptionId = exceptionId
202
+ @text = text
203
+ @variables = variables
204
+ end
205
+ end
206
+
207
+ # {http://www.telefonica.com/schemas/UNICA/REST/common/v1}SimpleReferenceType
208
+ # endpoint - SOAP::SOAPAnyURI
209
+ # correlator - SOAP::SOAPString
210
+ class SimpleReferenceType
211
+ attr_accessor :endpoint
212
+ attr_accessor :correlator
213
+
214
+ def initialize(endpoint = nil, correlator = nil)
215
+ @endpoint = endpoint
216
+ @correlator = correlator
217
+ end
218
+ end
219
+
220
+ # {http://www.telefonica.com/schemas/UNICA/REST/common/v1}ExtensionType
221
+ class ExtensionType
222
+ attr_reader :__xmlele_any
223
+
224
+ def set_any(elements)
225
+ @__xmlele_any = elements
226
+ end
227
+
228
+ def initialize
229
+ @__xmlele_any = nil
230
+ end
231
+ end
232
+
233
+ # {http://www.telefonica.com/schemas/UNICA/REST/sms/v1/}DeliveryStatusType
234
+ class DeliveryStatusType < ::String
235
+ DeliveredToNetwork = DeliveryStatusType.new("DeliveredToNetwork")
236
+ DeliveredToTerminal = DeliveryStatusType.new("DeliveredToTerminal")
237
+ DeliveryImpossible = DeliveryStatusType.new("DeliveryImpossible")
238
+ DeliveryNotificationNotSupported = DeliveryStatusType.new("DeliveryNotificationNotSupported")
239
+ DeliveryUncertain = DeliveryStatusType.new("DeliveryUncertain")
240
+ MessageWaiting = DeliveryStatusType.new("MessageWaiting")
241
+ end
242
+
243
+ # {http://www.telefonica.com/schemas/UNICA/REST/common/v1}FlagType
244
+ class FlagType < ::String
245
+ No = FlagType.new("no")
246
+ Yes = FlagType.new("yes")
247
+ end
248
+
249
+ # {http://www.telefonica.com/schemas/UNICA/REST/common/v1}GenderType
250
+ class GenderType < ::String
251
+ Female = GenderType.new("female")
252
+ Male = GenderType.new("male")
253
+ end
254
+
255
+
256
+ end; end
@@ -0,0 +1,91 @@
1
+ #
2
+ # BlueVia is a global iniciative of Telefonica delivered by Movistar and O2.
3
+ # Please, check out www.bluevia.com and if you need more information
4
+ # contact us at mailto:support@bluevia.com
5
+
6
+ require 'bluevia/messaging'
7
+ require 'bluevia/schemas/sms_types'
8
+
9
+ module Bluevia
10
+ #
11
+ # This class is in charge of access Bluevia SMS API
12
+ #
13
+
14
+ class Sms < BaseClient
15
+ include Messaging
16
+
17
+ include Schemas::Sms_types
18
+
19
+ # Basepath for SMS API
20
+ BASEPATH_API = "/SMS"
21
+
22
+ def initialize(params = nil)
23
+ super(params)
24
+ #super.extend(Schemas::Sms_types)
25
+ end
26
+
27
+ #
28
+ # This method sends a SMS to a list of destination numbers.
29
+ # [*dest_number*] array, fixnum or string with the destination numbers
30
+ # [*origin*] originator number the SMS will be send in name of. Should be a
31
+ # valid access_token.
32
+ # [*text*] short message text
33
+ # returns the location where the delivery status can be checked
34
+ #
35
+ def send_sms (dest_number, origin, text)
36
+ Utils.check_attribute dest_number, "Destination number cannot be null"
37
+ Utils.check_attribute text, "SMS text cannot be null"
38
+ Utils.check_attribute origin, "Origin number cannot be null"
39
+
40
+ # Set destination array
41
+ @dest_phones = Array.new
42
+ if (dest_number.instance_of?(Array))
43
+ dest_number.each { |i|
44
+ @dest_phones << UserIdType.new(i, nil, nil, nil, nil)
45
+ }
46
+ else
47
+ @dest_phones << UserIdType.new(dest_number, nil, nil, nil, nil)
48
+ end
49
+
50
+ @orig = UserIdType.new(nil, nil, nil, origin, nil)
51
+
52
+ # Create Message and convert to JSON
53
+ @msg = SMSTextType.new(@dest_phones, text, nil, @orig, nil, nil, nil, nil, nil)
54
+ message = Utils.object_to_json(@msg)
55
+
56
+ logger.debug "SMS Send this message:"
57
+ logger.debug message << "\n"
58
+
59
+ POST("#{get_basepath}/outbound/requests", message.to_s, nil, nil, "location")
60
+ end
61
+
62
+ #
63
+ # This method is used to retrieve MO messages that belongs to a specific registration ID
64
+ # [*registration_id*] MO Registration Identifier Mandatory
65
+ # returns a collection of messages
66
+ #
67
+ def get_received_sms(registration_id)
68
+ response = get_received_message(registration_id)
69
+ key = "receivedSMS"
70
+
71
+ # Fetch ["receivedSMS"]["receivedSMS"]
72
+ unless response.nil?
73
+ if response.respond_to?(:has_key?) && response.has_key?(key)
74
+ response = response[key]
75
+ if response.respond_to?(:has_key?) && response.has_key?(key)
76
+ return response[key]
77
+ else
78
+ return Hash.new
79
+ end
80
+ else
81
+ return Hash.new
82
+ end
83
+ else
84
+ return Hash.new
85
+ end
86
+
87
+ end
88
+
89
+
90
+ end
91
+ end
@@ -0,0 +1,110 @@
1
+ #
2
+ # BlueVia is a global iniciative of Telefonica delivered by Movistar and O2.
3
+ # Please, check out www.bluevia.com and if you need more information
4
+ # contact us at mailto:support@bluevia.com
5
+
6
+ require 'net/http'
7
+ require 'multipartable'
8
+ require 'bluevia/errors/client_error'
9
+
10
+ module Bluevia
11
+ #
12
+ # Helper to enable internal features
13
+ #
14
+
15
+ module Utils
16
+
17
+ class Multipart < Net::HTTP::Post
18
+ include Multipartable
19
+
20
+ def set_content_type(type, params = {})
21
+
22
+ end
23
+
24
+ def content_length=(len)
25
+
26
+ end
27
+ end
28
+
29
+ def Utils.get_file_mime_type(file)
30
+ unless file.nil?
31
+ Magic.guess_file_mime_type(file)
32
+ else
33
+ nil
34
+ end
35
+ end
36
+
37
+ #
38
+ # Helper to parse an objet to an equivalent JSON format
39
+ # used to serialize body data
40
+ #
41
+ def Utils.object_to_json(object)
42
+ name = object.class.to_s
43
+ name = name[name.rindex(":")+1..name.size].sub(/Type$/,"").sub(/^SMS/, "sms")
44
+ name = name[0..0].to_s.downcase << name[1..name.size]
45
+ result = Hash.new
46
+ result[name] = _object_to_json(object)
47
+ return result.to_json
48
+
49
+ #return _object_to_json(object).to_json
50
+ end
51
+
52
+ #
53
+ # Check if an attribute is not null
54
+ # Raise an exception in case of param.nil?
55
+ #
56
+ def Utils.check_attribute(attribute, message)
57
+ if attribute.nil?
58
+ raise ClientError, message
59
+ elsif attribute.instance_of?(String)
60
+ if attribute.empty?
61
+ raise ClientError, message
62
+ end
63
+ else
64
+ if attribute.respond_to?(:size)
65
+ if attribute.size == 0
66
+ raise ClientError, message
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+
73
+ private
74
+
75
+ def Utils._object_to_json(object)
76
+ result = Hash.new
77
+ #result_aux = []
78
+ object.instance_variables.each do |column|
79
+ aux = object.instance_variable_get(column)
80
+ unless aux.nil?
81
+ if aux.instance_of?(String) or aux.kind_of?(String)
82
+ # It's required to erase any '_' character because
83
+ # soap4r has included it (not idea about the reason)
84
+ result[get_column_value(column)] = aux.to_s
85
+ else
86
+ if aux.instance_of?(Array)
87
+ result_aux = Array.new
88
+ aux.each do |elem|
89
+ result_aux << _object_to_json(elem)
90
+ end
91
+ else
92
+ result_aux = _object_to_json(aux)
93
+ end
94
+ result[get_column_value(column)] = result_aux
95
+ #result_aux =[]
96
+ end
97
+ end
98
+ end
99
+ return result
100
+ end
101
+
102
+ def Utils.get_column_value(column)
103
+ column = column.to_s.sub(/@/,'')
104
+ unless column.index('_').nil?
105
+ column = column.split('_')[1]
106
+ end
107
+ column
108
+ end
109
+ end
110
+ end