Class: Bluevia::Sms
- Inherits:
-
BaseClient
- Object
- BaseClient
- Bluevia::Sms
- Includes:
- Messaging, Schemas::Sms_types
- Defined in:
- lib/bluevia/sms.rb
Overview
This class is in charge of access Bluevia SMS API
Constant Summary collapse
- BASEPATH_API =
Basepath for SMS API
"/SMS"
Constants inherited from BaseClient
BaseClient::BASEPATH, BaseClient::BASEPATH_COMMERCIAL, BaseClient::BASEPATH_SANDBOX, BaseClient::BASEURI, BaseClient::DEFAULT_PARAMS, BaseClient::PROXY
Instance Attribute Summary
Attributes inherited from BaseClient
Instance Method Summary collapse
-
#get_received_sms(registration_id) ⇒ Object
This method is used to retrieve MO messages that belongs to a specific registration ID [registration_id] MO Registration Identifier Mandatory returns a collection of messages.
-
#initialize(params = nil) ⇒ Sms
constructor
A new instance of Sms.
-
#send_sms(dest_number, origin, text) ⇒ Object
This method sends a SMS to a list of destination numbers.
Methods included from Messaging
#get_attachment, #get_delivery_status, #get_received_message
Methods inherited from BaseClient
#DELETE, #GET, #POST, #[]=, #authorized_client, create_rest_client, #get_basepath, #get_headers, #include_params, #set_http_client, #set_path, #set_timeout
Methods included from BlueviaLogger
#create_logger, #log_level=, #logger, #logger=
Constructor Details
#initialize(params = nil) ⇒ Sms
Returns a new instance of Sms.
22 23 24 25 |
# File 'lib/bluevia/sms.rb', line 22 def initialize(params = nil) super(params) #super.extend(Schemas::Sms_types) end |
Instance Method Details
#get_received_sms(registration_id) ⇒ Object
This method is used to retrieve MO messages that belongs to a specific registration ID
- registration_id
-
MO Registration Identifier Mandatory
returns a collection of messages
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/bluevia/sms.rb', line 67 def get_received_sms(registration_id) response = (registration_id) key = "receivedSMS" # Fetch ["receivedSMS"]["receivedSMS"] unless response.nil? if response.respond_to?(:has_key?) && response.has_key?(key) response = response[key] if response.respond_to?(:has_key?) && response.has_key?(key) return response[key] else return Hash.new end else return Hash.new end else return Hash.new end end |
#send_sms(dest_number, origin, text) ⇒ Object
This method sends a SMS to a list of destination numbers.
- dest_number
-
array, fixnum or string with the destination numbers
- origin
-
originator number the SMS will be send in name of. Should be a
valid access_token.
- text
-
short message text
returns the location where the delivery status can be checked
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 |
# File 'lib/bluevia/sms.rb', line 35 def send_sms (dest_number, origin, text) Utils.check_attribute dest_number, "Destination number cannot be null" Utils.check_attribute text, "SMS text cannot be null" Utils.check_attribute origin, "Origin number cannot be null" # Set destination array @dest_phones = Array.new if (dest_number.instance_of?(Array)) dest_number.each { |i| @dest_phones << UserIdType.new(i, nil, nil, nil, nil) } else @dest_phones << UserIdType.new(dest_number, nil, nil, nil, nil) end @orig = UserIdType.new(nil, nil, nil, origin, nil) # Create Message and convert to JSON @msg = SMSTextType.new(@dest_phones, text, nil, @orig, nil, nil, nil, nil, nil) = Utils.object_to_json(@msg) logger.debug "SMS Send this message:" logger.debug << "\n" POST("#{get_basepath}/outbound/requests", .to_s, nil, nil, "location") end |