Module: UnifonicSms
- Defined in:
- lib/unifonic_sms.rb,
lib/unifonic_sms/version.rb,
lib/unifonic_sms/error_code.rb,
lib/unifonic_sms/normalizer.rb,
lib/unifonic_sms/configuration.rb
Defined Under Namespace
Modules: ErrorCode, Normalizer Classes: Configuration
Constant Summary collapse
- VERSION =
Gem Version
"1.0.0"
Class Attribute Summary collapse
-
.configuration ⇒ QiwaSms::Configuration
Get the Configurations or Reset.
Class Method Summary collapse
-
.api_key ⇒ String
Get the api key from the configurations.
-
.balance ⇒ String
Get Account’s Current Balance.
-
.base_path(method_url) ⇒ String
Get the base url for api call.
-
.configure {|configuration| ... } ⇒ Object
Holds the configurtion block.
-
.inbox(number, keyword = nil, date_from = nil, date_to = nil) ⇒ String, Array<Hash>
The Keyword method enables you to manage your numbers, create auto replies to incoming messages or set a webhook directly from your API, Check Keywords Management to view and edit your keywords.
-
.keyword(number, keyword, rule, message = nil, webhook_url = nil, message_parameter = nil, recipient_parameter = nil, request_type = nil, resource_number = nil) ⇒ String
The Keyword method enables you to manage your numbers, create auto replies to incoming messages or set a webhook directly from your API, Check Keywords Management to view and edit your keywords.
-
.message_status(message_id) ⇒ String
Get Message Status.
-
.messages_details(message_id = nil, date_from = nil, date_to = nil, status = nil, dlr = nil, country = nil, limit = nil) ⇒ String, Array<Hash>
Get latest 10,000 messages details if no message id was provided.
-
.messages_report(date_from = nil, date_to = nil, status = nil, dlr = nil, country = nil) ⇒ String
To get a summarized report for sent messages within a specific timer interval.
-
.pricing(country_code = nil) ⇒ Hash, String
The Keyword method enables you to manage your numbers, create auto replies to incoming messages or set a webhook directly from your API, Check Keywords Management to view and edit your keywords.
-
.reset ⇒ Object
Reset Configuration to nil.
-
.schedualed_messages(message_id = nil) ⇒ String
Get a summarized report for scheduled sent messages.
-
.send_bulk(phones, message, time_schedualed = nil) ⇒ Array<Hash>, String
Send Bulk SMS messages Max is 1,000 recipents per request.
-
.send_message(phone, message, time_schedualed = nil) ⇒ String
Send SMS message.
-
.sender_phone ⇒ String
Get the phone number of the sender from the configurations.
-
.stop_schedualed_messages(message_id) ⇒ String
Get a summarized report for scheduled sent messages.
Class Attribute Details
.configuration ⇒ QiwaSms::Configuration
Get the Configurations or Reset.
15 16 17 |
# File 'lib/unifonic_sms.rb', line 15 def configuration @configuration end |
Class Method Details
.api_key ⇒ String
Get the api key from the configurations.
32 33 34 |
# File 'lib/unifonic_sms.rb', line 32 def api_key configuration.api_key end |
.balance ⇒ String
Get Account’s Current Balance.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/unifonic_sms.rb', line 57 def balance # Initialize Request http = Net::HTTP.new('api.unifonic.com', 80) path = base_path("Account/GetBalance") headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } # Add Body Parameters to request body = "AppSid=#{api_key}" # Send Call Request response = http.post(path, body, headers) response_body = JSON.parse(response.body) if response.code.to_i == 200 && !response_body["data"].nil? return { balance: response_body["data"]["Balance"], currency_code: response_body["data"]["CurrencyCode"], shared_balance: response_body["data"]["SharedBalance"], code: 0 } else result = ErrorCode.get_error_code(response_body["errorCode"]) return result end end |
.base_path(method_url) ⇒ String
Get the base url for api call.
47 48 49 |
# File 'lib/unifonic_sms.rb', line 47 def base_path (method_url) "/rest/#{method_url}" end |
.configure {|configuration| ... } ⇒ Object
Holds the configurtion block.
25 26 27 |
# File 'lib/unifonic_sms.rb', line 25 def configure yield(configuration) end |
.inbox(number, keyword = nil, date_from = nil, date_to = nil) ⇒ String, Array<Hash>
The Keyword method enables you to manage your numbers, create auto replies to incoming messages or set a webhook directly from your API, Check Keywords Management to view and edit your keywords.
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 |
# File 'lib/unifonic_sms.rb', line 459 def inbox (number, keyword = nil, date_from = nil, date_to = nil) # Initialize Request http = Net::HTTP.new('api.unifonic.com', 80) path = base_path("Messages/Inbox") headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } # Add Body Parameters to request body = "AppSid=#{api_key}" body += "&Number=#{number}" body += "&Keyword=#{keyword}" unless keyword.nil? body += "&FromDate=#{date_from}" unless date_from.nil? body += "&ToDate=#{date_to}" unless date_to.nil? # Send Call Request response = http.post(path, body, headers) response_body = JSON.parse(response.body) if response.code.to_i == 200 && !response_body["data"].nil? return { number_of_messages: response_body["data"]["NumberOfMessages"], message_from: response_body["data"]["MessageFrom"], message: response_body["data"]["Message"], date_recieved: response_body["data"]["DateReceived"], code: 0 } else result = ErrorCode.get_error_code(response_body["errorCode"]) return result end end |
.keyword(number, keyword, rule, message = nil, webhook_url = nil, message_parameter = nil, recipient_parameter = nil, request_type = nil, resource_number = nil) ⇒ String
The Keyword method enables you to manage your numbers, create auto replies to incoming messages or set a webhook directly from your API, Check Keywords Management to view and edit your keywords.
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
# File 'lib/unifonic_sms.rb', line 411 def keyword (number, keyword, rule, = nil, webhook_url = nil, = nil, recipient_parameter = nil, request_type = nil, resource_number = nil) # Initialize Request http = Net::HTTP.new('api.unifonic.com', 80) path = base_path("Messages/Keyword") headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } # Add Body Parameters to request body = "AppSid=#{api_key}" body += "&Number=#{number}" body += "&Keyword=#{keyword}" body += "&Rule=#{rule}" body += "&SenderID=#{sender_phone}" unless sender_phone.nil? body += "&Message=#{}" unless .nil? body += "&WebhookURL=#{webhook_url}" unless webhook_url.nil? body += "&MessageParameter=#{}" unless .nil? body += "&RecipientParameter=#{recipient_parameter}" unless recipient_parameter.nil? body += "&RequestType =#{request_type}" unless request_type.nil? body += "&ResourceNumber =#{resource_number}" unless resource_number.nil? # Send Call Request response = http.post(path, body, headers) response_body = JSON.parse(response.body) if response.code.to_i == 200 return { success: response_body["Success"], code: 0 } else result = ErrorCode.get_error_code(response_body["errorCode"]) return result end end |
.message_status(message_id) ⇒ String
Get Message Status.
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/unifonic_sms.rb', line 207 def () # Initialize Request http = Net::HTTP.new('api.unifonic.com', 80) path = base_path("Messages/GetMessageIDStatus") headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } # Add Body Parameters to request body = "AppSid=#{api_key}&MessageID=#{}" # Send Call Request response = http.post(path, body, headers) response_body = JSON.parse(response.body) if response.code.to_i == 200 && !response_body["Status"].nil? return { status: response_body["Status"], code: 0 } else result = ErrorCode.get_error_code(response_body["errorCode"]) return result end end |
.messages_details(message_id = nil, date_from = nil, date_to = nil, status = nil, dlr = nil, country = nil, limit = nil) ⇒ String, Array<Hash>
Get latest 10,000 messages details if no message id was provided.
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 316 317 318 319 320 321 |
# File 'lib/unifonic_sms.rb', line 289 def ( = nil, date_from = nil, date_to = nil, status = nil, dlr = nil, country = nil, limit = nil) # Initialize Request http = Net::HTTP.new('api.unifonic.com', 80) path = base_path("Messages/GetMessagesDetails") headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } # Add Body Parameters to request body = "AppSid=#{api_key}" body += "&MessageID=#{}" unless .nil? body += "&SenderID=#{sender_phone}" unless sender_phone.nil? body += "&DateFrom=#{date_from}" unless date_from.nil? body += "&DateTo=#{date_to}" unless date_to.nil? body += "&Status=#{status}" unless status.nil? body += "&DLR=#{dlr}" unless dlr.nil? body += "&Country=#{country}" unless country.nil? body += "&Limit=#{limit}" unless limit.nil? # Send Call Request response = http.post(path, body, headers) response_body = JSON.parse(response.body) if response.code.to_i == 200 && !response_body["data"].nil? return { total_text_messages: response_body["data"]["TotalTextMessages"], page: response_body["data"]["Page"], messages: response_body["data"]["messages"], code: 0 } else result = ErrorCode.get_error_code(response_body["errorCode"]) return result end end |
.messages_report(date_from = nil, date_to = nil, status = nil, dlr = nil, country = nil) ⇒ String
To get a summarized report for sent messages within a specific timer interval
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 |
# File 'lib/unifonic_sms.rb', line 242 def (date_from = nil, date_to = nil, status = nil, dlr = nil, country = nil) # Initialize Request http = Net::HTTP.new('api.unifonic.com', 80) path = base_path("Messages/GetMessagesReport") headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } # Add Body Parameters to request body = "AppSid=#{api_key}" body += "&SenderID=#{sender_phone}" unless sender_phone.nil? body += "&DateFrom=#{date_from}" unless date_from.nil? body += "&DateTo=#{date_to}" unless date_to.nil? body += "&Status=#{status}" unless status.nil? body += "&DLR=#{dlr}" unless dlr.nil? body += "&Country=#{country}" unless country.nil? # Send Call Request response = http.post(path, body, headers) response_body = JSON.parse(response.body) if response.code.to_i == 200 && !response_body["TotalTextMessages"].nil? return { total_text_messages: response_body["TotalTextMessages"], number_of_units: response_body["NumberOfUnits"], cost: response_body["Cost"], currency_code: response_body["CurrencyCode"], code: 0 } else result = ErrorCode.get_error_code(response_body["errorCode"]) return result end end |
.pricing(country_code = nil) ⇒ Hash, String
The Keyword method enables you to manage your numbers, create auto replies to incoming messages or set a webhook directly from your API, Check Keywords Management to view and edit your keywords.
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
# File 'lib/unifonic_sms.rb', line 500 def pricing (country_code = nil) # Initialize Request http = Net::HTTP.new('api.unifonic.com', 80) path = base_path("Messages/Pricing") headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } # Add Body Parameters to request body = "AppSid=#{api_key}" body += "&CountryCode=#{country_code}" unless country_code.nil? # Send Call Request response = http.post(path, body, headers) response_body = JSON.parse(response.body) if response.code.to_i == 200 && !response_body["data"].nil? return { country: response_body["data"]["CountryCode"], country_name: response_body["data"]["CountryName"], code: 0 } else result = ErrorCode.get_error_code(response_body["errorCode"]) return result end end |
.reset ⇒ Object
Reset Configuration to nil.
20 21 22 |
# File 'lib/unifonic_sms.rb', line 20 def reset @configuration = Configuration.new end |
.schedualed_messages(message_id = nil) ⇒ String
Get a summarized report for scheduled sent messages.
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/unifonic_sms.rb', line 334 def ( = nil) # Initialize Request http = Net::HTTP.new('api.unifonic.com', 80) path = base_path("Messages/GetScheduled") headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } # Add Body Parameters to request body = "AppSid=#{api_key}" body += "&MessageID=#{}" unless .nil? # Send Call Request response = http.post(path, body, headers) response_body = JSON.parse(response.body) if response.code.to_i == 200 return { message_id: response_body["MessageID"], message_body: response_body["MessageBody"], sender_id: response_body["SenderID"], recipient: response_body["Recipient"], time_schedualed: response_body["TimeScheduled"], status: response_body["Status"], code: 0 } else result = ErrorCode.get_error_code(response_body["errorCode"]) return result end end |
.send_bulk(phones, message, time_schedualed = nil) ⇒ Array<Hash>, String
Send Bulk SMS messages Max is 1,000 recipents per request.
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 |
# File 'lib/unifonic_sms.rb', line 150 def send_bulk (phones, , time_schedualed = nil) # Adjust Parameters recipients = [] phone_numbers = phones.split(",") phone_numbers.each do |phone| recipients.push(Normalizer.normalize_number(phone)) end = Normalizer.() # Initialize Request http = Net::HTTP.new('api.unifonic.com', 80) path = base_path("Messages/SendBulk") headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } # Add Body Parameters to request body = "AppSid=#{api_key}&Recipient=" # Add Recipents to body attributes recipients.each_with_index do |phone, index| body += phone if index != (recipients.count - 1) body += "," end end body += "&Body=#{}" body += "&SenderID=#{sender_phone}" unless sender_phone.nil? body += '&TimeScheduled=#{time_schedualed}' unless time_schedualed.nil? # Send Call Request response = http.post(path, body, headers) response_body = JSON.parse(response.body) if response.code.to_i == 200 && !response_body["data"].nil? return { messages: response_body["data"]["Messages"], status: response_body["data"]["Status"], number_of_units: response_body["data"]["NumberOfUnits"], cost: response_body["data"]["Cost"], currency_code: response_body["data"]["CurrencyCode"], balance: response_body["data"]["Balance"], recipient: response_body["data"]["Recipient"], time_created: response_body["data"]["TimeCreated"], code: 0 } else result = ErrorCode.get_error_code(response_body["errorCode"]) return result end end |
.send_message(phone, message, time_schedualed = nil) ⇒ String
Send SMS message.
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 |
# File 'lib/unifonic_sms.rb', line 97 def (phone, , time_schedualed = nil) # Adjust Parameters recipient = Normalizer.normalize_number(phone) = Normalizer.() # Initialize Request http = Net::HTTP.new('api.unifonic.com', 80) path = base_path("Messages/Send") headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } # Add Body Parameters to request body = "AppSid=#{api_key}&Recipient=#{recipient}&Body=#{}" body += "&SenderID=#{sender_phone}" unless sender_phone.nil? body += '&Priority=High' body += '&TimeScheduled=#{time_schedualed}' unless time_schedualed.nil? # Send Call Request response = http.post(path, body, headers) response_body = JSON.parse(response.body) if response.code.to_i == 200 && !response_body["data"].nil? return { message_id: response_body["data"]["MessageID"], status: response_body["data"]["Status"], number_of_units: response_body["data"]["NumberOfUnits"], cost: response_body["data"]["Cost"], currency_code: response_body["data"]["CurrencyCode"], balance: response_body["data"]["Balance"], recipient: response_body["data"]["Recipient"], time_created: response_body["data"]["TimeCreated"], code: 0 } else result = ErrorCode.get_error_code(response_body["errorCode"]) return result end end |
.sender_phone ⇒ String
Get the phone number of the sender from the configurations.
39 40 41 |
# File 'lib/unifonic_sms.rb', line 39 def sender_phone configuration.sender_phone end |
.stop_schedualed_messages(message_id) ⇒ String
Get a summarized report for scheduled sent messages.
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/unifonic_sms.rb', line 369 def () # Initialize Request http = Net::HTTP.new('api.unifonic.com', 80) path = base_path("Messages/StopScheduled") headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } # Add Body Parameters to request body = "AppSid=#{api_key}" body += "&MessageID=#{}" # Send Call Request response = http.post(path, body, headers) response_body = JSON.parse(response.body) if response.code.to_i == 200 return { success: response_body["Success"], code: 0 } else result = ErrorCode.get_error_code(response_body["errorCode"]) return result end end |