RubyGlobe 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/rubyglobe.rb +275 -0
  2. metadata +55 -0
data/rubyglobe.rb ADDED
@@ -0,0 +1,275 @@
1
+ =begin
2
+ ***********************************************
3
+ * @author: Ferdinand E. Silva
4
+ * @email: ferdinandsilva@ferdinandsilva.com
5
+ * @title: PyGlobe
6
+ * @description: Ruby interface for Globe Labs API
7
+ * @notes: sendMMS coming soon.. ;)
8
+ ***********************************************
9
+ =end
10
+
11
+ require 'soap/wsdlDriver'
12
+
13
+ WSDL_URL = 'http://iplaypen.globelabs.com.ph:1881/axis2/services/Platform?wsdl'
14
+
15
+ class RubyGlobeInvalidURLException < Exception
16
+ end
17
+
18
+ class RubyGlobeInvalidServiceException < Exception
19
+ end
20
+
21
+ class RubyGlobeServerFaultException < Exception
22
+ end
23
+
24
+ class RubyGlobeDisplay
25
+
26
+ @@SEND_DIRECTLY_TO_DISPLAY = "0"
27
+ @@SEND_TO_PHONE = "1"
28
+ @@SEND_TO_SIM = "2"
29
+
30
+ def self.SEND_DIRECTLY_TO_DISPLAY
31
+ @@SEND_DIRECTLY_TO_DISPLAY
32
+ end
33
+
34
+ def self.SEND_TO_PHONE
35
+ @@SEND_TO_PHONE
36
+ end
37
+
38
+ def self.SEND_TO_SIM
39
+ @@SEND_TO_SIM
40
+ end
41
+
42
+ end
43
+
44
+ class RubyGlobeMWI
45
+
46
+ @@NONE = ""
47
+ @@VOICE_MAIL_ICON_ACTIVATE = "0"
48
+ @@FAX_ICON_ACTIVATE = "1"
49
+ @@EMAIL_ICON_ACTIVATE = "2"
50
+ @@OTHER_ACTIVATION = "3"
51
+ @@DEACTIVATE_VOICE_MAIL_ICON = "4"
52
+ @@DEACTIVATE_FAX_ICON = "5"
53
+ @@DEACTIVATE_EMAIL_ICON = "6"
54
+ @@DEACTIVATE_OTHER_ICON = "7"
55
+
56
+ def self.NONE
57
+ @@NONE
58
+ end
59
+
60
+ def self.VOICE_MAIL_ICON_ACTIVATE
61
+ @@VOICE_MAIL_ICON_ACTIVATE
62
+ end
63
+
64
+ def self.FAX_ICON_ACTIVATE
65
+ @@FAX_ICON_ACTIVATE
66
+ end
67
+
68
+ def self.EMAIL_ICON_ACTIVATE
69
+ @@EMAIL_ICON_ACTIVATE
70
+ end
71
+
72
+ def self.OTHER_ACTIVATION
73
+ @@OTHER_ACTIVATION
74
+ end
75
+
76
+ def self.DEACTIVATE_VOICE_MAIL_ICON
77
+ @@DEACTIVATE_VOICE_MAIL_ICON
78
+ end
79
+
80
+ def self.DEACTIVATE_FAX_ICON
81
+ @@DEACTIVATE_FAX_ICON
82
+ end
83
+
84
+ def self.DEACTIVATE_EMAIL_ICON
85
+ @@DEACTIVATE_EMAIL_ICON
86
+ end
87
+
88
+ def self.DEACTIVATE_OTHER_ICON
89
+ @@DEACTIVATE_OTHER_ICON
90
+ end
91
+
92
+ end
93
+
94
+ class RubyGlobeCoding
95
+
96
+ @@BIT_7 = "0"
97
+ @@BIT_8 = "1"
98
+ @@USC_2 = "2"
99
+
100
+ def self.BIT_7
101
+ @@BIT_7
102
+ end
103
+
104
+ def self.BIT_8
105
+ @@BIT_8
106
+ end
107
+
108
+ def self.USC_2
109
+ @@USC_2
110
+ end
111
+
112
+ end
113
+
114
+ class RubyGlobeReturnCode
115
+
116
+ @@NOT_ALLOWED = "301"
117
+ @@EXCEEDED_DAILY_CAP = "302"
118
+ @@INVALID_MESSAGE_LENGTH = "303"
119
+ @@MAX_NUMBER_CONNECTION = "304"
120
+ @@INVALID_LOGIN_CREDENTIALS = "305"
121
+ @@SMS_SENDING_FAILED = "401"
122
+ @@MMS_SENDING_FAILED = "402"
123
+ @@INVALID_TARGET = "501"
124
+ @@INVALID_DISPLAY = "502"
125
+ @@INVALID_MWI = "503"
126
+ @@BAD_XML = "506"
127
+ @@INVALID_CODING = "504"
128
+ @@EMPTY_VALUE = "505"
129
+ @@ARGUMENT_TOO_LARGE = "507"
130
+ @@SMS_ACCEPTED = "201"
131
+ @@MMS_ACCEPTED = "202"
132
+
133
+ def self.NOT_ALLOWED
134
+ @@NOT_ALLOWED
135
+ end
136
+
137
+ def self.EXCEEDED_DAILY_CAP
138
+ @@EXCEEDED_DAILY_CAP
139
+ end
140
+
141
+ def self.INVALID_MESSAGE_LENGTH
142
+ @@INVALID_MESSAGE_LENGTH
143
+ end
144
+
145
+ def self.MAX_NUMBER_CONNECTION
146
+ @@MAX_NUMBER_CONNECTION
147
+ end
148
+
149
+ def self.INVALID_LOGIN_CREDENTIALS
150
+ @@INVALID_LOGIN_CREDENTIALS
151
+ end
152
+
153
+ def self.SMS_SENDING_FAILED
154
+ @@SMS_SENDING_FAILED
155
+ end
156
+
157
+ def self.MMS_SENDING_FAILED
158
+ @@MMS_SENDING_FAILED
159
+ end
160
+
161
+ def self.INVALID_TARGET
162
+ @@INVALID_TARGET
163
+ end
164
+
165
+ def self.INVALID_DISPLAY
166
+ @@INVALID_DISPLAY
167
+ end
168
+
169
+ def self.INVALID_MWI
170
+ @@INVALID_MWI
171
+ end
172
+
173
+ def self.BAD_XML
174
+ @@BAD_XML
175
+ end
176
+
177
+ def self.INVALID_CODING
178
+ @@INVALID_CODING
179
+ end
180
+
181
+ def self.EMPTY_VALUE
182
+ @@EMPTY_VALUE
183
+ end
184
+
185
+ def self.ARGUMENT_TOO_LARGE
186
+ @@ARGUMENT_TOO_LARGE
187
+ end
188
+
189
+ def self.SMS_ACCEPTED
190
+ @@SMS_ACCEPTED
191
+ end
192
+
193
+ def self.MMS_ACCEPTED
194
+ @@MMS_ACCEPTED
195
+ end
196
+
197
+ end
198
+
199
+ class RubyGlobe
200
+
201
+ @@__VERSION__ = "1.0"
202
+ @@__AUTHOR__ = "Ferdinand E. Silva"
203
+
204
+ def self.__VERSION__
205
+ @@__VERSION__
206
+ end
207
+
208
+ def self.__AUTHOR__
209
+ @@__AUTHOR__
210
+ end
211
+
212
+ def initialize(uname, pin, msisdn, wsdl = WSDL_URL, display = RubyGlobeDisplay.SEND_TO_PHONE, udh = "", mwi = RubyGlobeMWI.NONE, coding = RubyGlobeCoding.BIT_7)
213
+
214
+ @wsdl = wsdl
215
+ @uname = uname
216
+ @pin = pin
217
+ @msisdn = msisdn
218
+ @display = display
219
+ @udh = udh
220
+ @mwi = mwi
221
+ @coding = coding
222
+ @service = nil
223
+
224
+ begin
225
+ @service = SOAP::WSDLDriverFactory.new(@wsdl).create_rpc_driver
226
+ rescue RuntimeError
227
+ raise RubyGlobeInvalidURLException, "Invalid URL"
228
+ rescue SocketError
229
+ raise RubyGlobeInvalidServiceException, "Service Unknown"
230
+ end
231
+
232
+ end
233
+
234
+ def sendSMS(message)
235
+
236
+ begin
237
+ ret = @service.sendSMS(:uName => @uname, :uPin => @pin, :MSISDN => @msisdn, :messageString => message, :Display => @display, :udh => @udh, :mwi => @mwi, :coding => @coding).return.to_s
238
+
239
+ if ret == RubyGlobeReturnCode.SMS_ACCEPTED
240
+ return true
241
+ elsif ret == RubyGlobeReturnCode.NOT_ALLOWED
242
+ raise RubyGlobeServerFaultException, "User is not allowed to access this service"
243
+ elsif ret == RubyGlobeReturnCode.EXCEEDED_DAILY_CAP
244
+ raise RubyGlobeServerFaultException, "User exceeded daily cap"
245
+ elsif ret == RubyGlobeReturnCode.INVALID_MESSAGE_LENGTH
246
+ raise RubyGlobeServerFaultException, "Invalid message length"
247
+ elsif ret == RubyGlobeReturnCode.MAX_NUMBER_CONNECTION
248
+ raise RubyGlobeServerFaultException, "Maximum Number of simultaneous connections reached"
249
+ elsif ret == RubyGlobeReturnCode.INVALID_LOGIN_CREDENTIALS
250
+ raise RubyGlobeServerFaultException, "Invalid login credentials"
251
+ elsif ret == RubyGlobeReturnCode.SMS_SENDING_FAILED
252
+ raise RubyGlobeServerFaultException, "SMS sending failed"
253
+ elsif ret == RubyGlobeReturnCode.INVALID_TARGET
254
+ raise RubyGlobeServerFaultException, "Invalid target MSISDN"
255
+ elsif ret == RubyGlobeReturnCode.INVALID_DISPLAY
256
+ raise RubyGlobeServerFaultException, "Invalid display type"
257
+ elsif ret == RubyGlobeReturnCode.INVALID_MWI
258
+ raise RubyGlobeServerFaultException, "Invalid MWI"
259
+ elsif ret == RubyGlobeReturnCode.BAD_XML
260
+ raise RubyGlobeServerFaultException, "Badly formed XML in SOAP request"
261
+ elsif ret == RubyGlobeReturnCode.INVALID_CODING
262
+ raise RubyGlobeServerFaultException, "Invalid Coding"
263
+ elsif ret == RubyGlobeReturnCode.EMPTY_VALUE
264
+ raise RubyGlobeServerFaultException, "Empty value given in required argument"
265
+ elsif ret == RubyGlobeReturnCode.ARGUMENT_TOO_LARGE
266
+ raise RubyGlobeServerFaultException, "Argument given too large"
267
+ end
268
+
269
+ rescue SocketError
270
+ raise RubyGlobeInvalidServiceException, "Service Unknown"
271
+ end
272
+
273
+ end
274
+
275
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: RubyGlobe
3
+ version: !ruby/object:Gem::Version
4
+ version: "1.0"
5
+ platform: ruby
6
+ authors:
7
+ - Ferdinand E. Silva
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2012-09-03 00:00:00 +08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Ruby interface for Globe Labs API
17
+ email: ferdinandsilva@ferdinandsilva.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - rubyglobe.rb
26
+ has_rdoc: true
27
+ homepage: http://ferdinandsilva.com
28
+ licenses: []
29
+
30
+ post_install_message:
31
+ rdoc_options: []
32
+
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ version:
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ requirements: []
48
+
49
+ rubyforge_project:
50
+ rubygems_version: 1.3.5
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: Ruby interface for Globe Labs API
54
+ test_files: []
55
+