Class: Itexmo::Message
- Inherits:
-
Object
- Object
- Itexmo::Message
- Defined in:
- lib/itexmo/message.rb
Overview
message class
Constant Summary collapse
- PARAMS =
{}
- API_ENDPOINT =
'https://www.itexmo.com/php_api'.freeze
Instance Attribute Summary collapse
-
#api_code ⇒ Object
Returns the value of attribute api_code.
-
#message ⇒ Object
Returns the value of attribute message.
-
#to ⇒ Object
Returns the value of attribute to.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Message
constructor
A new instance of Message.
-
#priority ⇒ Object
default is NORMAL.
- #send ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Message
Returns a new instance of Message.
13 14 15 16 17 18 |
# File 'lib/itexmo/message.rb', line 13 def initialize( = {}) @api_code = Itexmo.configuration.api_code @message = [:message] @priority = [:priority] @to = [:to] end |
Instance Attribute Details
#api_code ⇒ Object
Returns the value of attribute api_code.
8 9 10 |
# File 'lib/itexmo/message.rb', line 8 def api_code @api_code end |
#message ⇒ Object
Returns the value of attribute message.
8 9 10 |
# File 'lib/itexmo/message.rb', line 8 def @message end |
#to ⇒ Object
Returns the value of attribute to.
8 9 10 |
# File 'lib/itexmo/message.rb', line 8 def to @to end |
Class Method Details
.send(options = {}) ⇒ Object
63 64 65 66 |
# File 'lib/itexmo/message.rb', line 63 def self.send( = {}) instance = new() instance.send end |
Instance Method Details
#priority ⇒ Object
default is NORMAL
21 22 23 |
# File 'lib/itexmo/message.rb', line 21 def priority @priority ||= Itexmo.configuration.priority end |
#send ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/itexmo/message.rb', line 25 def send uri = URI(API_ENDPOINT + '/api.php') request = Net::HTTP.post_form(uri, parameters) response = request.body case response when '0' { code: 200, message: 'Success! Message is now on queue and will be sent soon.' } when '1' raise Errors::BadRequest, 'Invalid value for parameter to' when '2' raise Errors::BadRequest, 'Number prefix not supported. Please contact itexmo' when '3' raise Errors::Authentication, 'Invalid api_code' when '4' { code: 400, message: 'Maximum Message per day reached. This will be reset every 12MN' } when '5' raise Errors::BadRequest, 'Maximum allowed characters for message reached' when '6' { code: 422, message: 'System OFFLINE' } when '7' raise Errors::Authentication, 'Expired ApiCode' when '8' { code: 500, message: 'iTexMo Error. Please try again later.' } when '9' raise Errors::BadRequest, 'Invalid Function Parameters' when '10' { code: 422, message: "Recipient's number is blocked due to FLOODING, message was ignored" } when '11' { code: 422, message: "Recipient's number is blocked temporarily due to HARD sending (after 3 retries of sending and message still failed to send) and the message was ignored. Try again after an hour. " } when '12' raise Errors::BadRequest, "Invalid request. You can't set message priorities on non corporate apicodes" when '13' raise Errors::BadRequest, 'Invalid or Not Registered Custom Sender ID.' end end |