Module: Mobilywscli
- Defined in:
- lib/mobilywscli.rb,
lib/mobilywscli/version.rb
Constant Summary collapse
- API_BASE_URI =
"http://mobily.ws/api/"- SETTING_FILE_PATH =
File.join(File.dirname(__FILE__),"settings.yaml")
- VERSION =
"0.0.2"
Class Attribute Summary collapse
-
.current_result_message ⇒ Object
Returns the value of attribute current_result_message.
Class Method Summary collapse
-
.convert_to_unicode(message) ⇒ Object
.
-
.get_balance ⇒ Object
Check for balance.
-
.get_mobily_credential(credential_type) ⇒ Object
Get current mobily setting.
-
.result_messages(q, op_type) ⇒ Object
Result messages handler.
-
.send(numbers, message) ⇒ Object
Send message.
-
.send_status ⇒ Object
Check for mobilyws gateway status.
-
.setup(muname, mpassword, msender) ⇒ Object
Add & modify mobily credentials.
Class Attribute Details
.current_result_message ⇒ Object
Returns the value of attribute current_result_message.
18 19 20 |
# File 'lib/mobilywscli.rb', line 18 def end |
Class Method Details
.convert_to_unicode(message) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/mobilywscli.rb', line 146 def convert_to_unicode() chrarray = { "،" => "060D" , "؛"=> "061B", "؟"=> "061F", "ء"=> "0621", "آ"=> "0622", "أ"=> "0623", "ؤ"=> "0624", "إ"=> "0625", "ئ"=> "0626", "ا"=> "0627", "ب"=> "0628", "ة"=> "0629", "ت"=> "062A", "ث"=> "062B", "ج"=> "062C", "ح"=> "062D", "خ"=> "062E", "د"=> "062F", "ذ" => "0630", "ر"=> "0631", "ز"=> "0632", "س"=> "0633", "ش"=> "0634", "ص"=> "0635", "ض"=> "0636", "ط"=> "0637", "ظ"=> "0638", "ع"=> "0639", "غ"=> "063A", "ف"=> "0641", "ق"=> "0642", "ك"=> "0643", "ل"=> "0644", "م"=> "0645", "ن"=> "0646", "ه"=> "0647", "و"=> "0648", "ى"=> "0649", "ي"=> "064A", "ـ" => "0640", "ً" => "064B", "ٌ"=> "064C", "ٍ"=> "064D", "َ"=> "064E", "ُ"=> "064F", "ِ"=> "0650", "ّ"=> "0651", "ْ"=> "0652", "!"=> "0021", '""'=> "0022", "#"=> "0023", "$"=> "0024", "%"=> "0025", "&"=> "0026", "'"=> "0027", "("=> "0028", ")"=> "0029", "*"=> "002A", "+"=> "002B", ","=> "002C", "-"=> "002D", "."=> "002E", "/"=> "002F", "0"=> "0030", "1"=> "0031", "2"=> "0032", "3"=> "0033", "4"=> "0034", "5"=> "0035", "6"=> "0036", "7"=> "0037", "8"=> "0038", "9"=> "0039", ":"=> "003A", ""=> "003B", "<"=> "003C", "="=> "003D", ">"=> "003E", "?"=> "003F", "@"=> "0040", "A"=> "0041", "B"=> "0042", "C"=> "0043", "D"=> "0044", "E"=> "0045", "F"=> "0046", "G"=> "0047", "H"=> "0048", "I"=> "0049", "J"=> "004A", "K"=> "004B", "L"=> "004C", "M"=> "004D", "N"=> "004E", "O"=> "004F", "P"=> "0050", "Q"=> "0051", "R"=> "0052", "S"=> "0053", "T"=> "0054", "U"=> "0055", "V"=> "0056", "W"=> "0057", "X"=> "0058", "Y"=> "0059", "Z"=> "005A", '[" "('=> "005B", "\\"=> "005C", ']" ")'=> "005D", "^"=> "005E", "_"=> "005F", "`"=> "0060", "a"=> "0061", "b"=> "0062", "c"=> "0063", "d"=> "0064", "e"=> "0065", "f"=> "0066", "g"=> "0067", "h"=> "0068", "i"=> "0069", "j"=> "006A", "k"=> "006B", "l"=> "006C", "m"=> "006D", "n"=> "006E", "o"=> "006F", "p"=> "0070", "q"=> "0071", "r"=> "0072", "s"=> "0073", "t"=> "0074", "u"=> "0075", "v"=> "0076", "w"=> "0077", "x"=> "0078", "y"=> "0079", "z"=> "007A", "{"=> "007B", "|"=> "007C", "}"=> "007D", "~"=> "007E", "©"=> "00A9", "®"=> "00AE", "÷"=> "00F7", "×"=> "00F7", "§"=> "00A7", "\r"=> "000A", " " => "0020" } result = '' .chars.to_a.map { |x| if chrarray.has_key?(x) result += chrarray[x] else x end }.join result end |
.get_balance ⇒ Object
Check for balance
62 63 64 65 |
# File 'lib/mobilywscli.rb', line 62 def get_balance url = URI.parse("#{API_BASE_URI}balance.php?mobile=#{get_mobily_credential(:username)}&password=#{get_mobily_credential(:password)}") = (Net::HTTP.get(url), 1) end |
.get_mobily_credential(credential_type) ⇒ Object
Get current mobily setting
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mobilywscli.rb', line 48 def get_mobily_credential(credential_type) mobily_credential_yaml = YAML.load_file(SETTING_FILE_PATH) case credential_type when :username then return mobily_credential_yaml['mobily_username'] when :password then return mobily_credential_yaml['mobily_password'] when :sender then return mobily_credential_yaml['mobily_sender'] else return "unknown request" end end |
.result_messages(q, op_type) ⇒ Object
Result messages handler
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/mobilywscli.rb', line 77 def (q, op_type) # Get current sttaus of mobily gateway if op_type == 0 if q == '1' result = "Service is available" else result = "Service is not available" end # Get current balance elsif op_type == 1 case q when '1' result = "username is incorrect, please make sure that the username is the same name that you use to access mobily.ws" when '2' result = "password is incorrect, please make sure that the password is the same passowrd that you use to access mobily.ws" when '-1' result = "Communication with Server Failed." when '-2' result = "Communication with Database Failed." else current_balance = q.split('/') result = "Mobily current balance: #{current_balance[1]} of #{current_balance[0]}" end # Send message elsif op_type == 2 case q when '1' result = "Message has been sent successfully." when '2' result = "Balance = 0" when '3' result = "insufficient balance" when '4' result = "Mobile Number Not Available" when '5' result = "Password is incorrect" when '6' result = "Web page ineffective, try sending again" when '13' result = "The sender name is not acceptable" when '14' result = "The sender name is not active" when '15' result = "Invalid or empty numbers" when '16' result = "Sender name is empty" when '17' result = "The text of the message is not encrypted properly" when '-1' result = "Communication with Database Failed." when '-2' result = "Communication with Server Failed." else result = q end end end |
.send(numbers, message) ⇒ Object
Send message
69 70 71 72 73 |
# File 'lib/mobilywscli.rb', line 69 def send(numbers, ) = convert_to_unicode() url = URI.parse(URI.encode("#{API_BASE_URI}msgSend.php?mobile=#{get_mobily_credential(:username)}&password=#{get_mobily_credential(:password)}&numbers=#{numbers}&msg=#{message}&sender=#{get_mobily_credential(:sender)}&applicationType=24")) = (Net::HTTP.get(url), 2) end |
.send_status ⇒ Object
Check for mobilyws gateway status
22 23 24 25 |
# File 'lib/mobilywscli.rb', line 22 def send_status url = URI.parse("#{API_BASE_URI}sendStatus.php") = (Net::HTTP.get(url), 0) end |
.setup(muname, mpassword, msender) ⇒ Object
Add & modify mobily credentials
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mobilywscli.rb', line 29 def setup(muname, mpassword, msender) mobily_credential_yaml = YAML.load_file(SETTING_FILE_PATH) mobily_credential_yaml['mobily_username'] = muname.to_s mobily_credential_yaml['mobily_password'] = mpassword.to_s mobily_credential_yaml['mobily_sender'] = msender.to_s begin File.open(SETTING_FILE_PATH,'w') do |h| h.write mobily_credential_yaml.to_yaml end rescue SystemCallError raise StandardError end end |