diff --git a/README.md b/README.md index e00c062..05f0a32 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,25 @@ But numbers like *987654321* (less than 10 digit) or *98765abcde* (containing no The third optional argument for `send_message` method is a Hash object. * **sender** : You can override sender by passing a `sender` option. `Msgwow.send_message('message', '9538xxxxxx', sender: 'MYAPPS')` - +* **route** : **1** for promotional route and **4** for transactional route. + `Msgwow.send_message('message', '9538xxxxxx', sender: 'MYAPPS', route: 1)` +* **country**: 0 for international,1 for USA, 91 for India (integer only). + `Msgwow.send_message('message', '9538xxxxxx', country: 1)` +* **flash** : **1** or **true** to send a flash message. + `Msgwow.send_message('message', '9538xxxxxx', flash: true)` + or you can send a flash message directly with `send_flash_message` and it supports all other options. + `Msgwow.send_flash_message('message', '9538xxxxxx', sender: 'ALERT')` +* **unicode** : **1** or **true** to send a unicode message. + `Msgwow.send_message('message', '9538xxxxxx', unicode: true)` + or you can send a unicode message directly with `send_unicode_message` with all other options. + `Msgwow.send_unicode_message('message', '9538xxxxxx', sender: 'ALERT')` +* **ignore_ndnc** : **1** or **true** to make system, ignore all NDNC Numbers. + `Msgwow.send_message('message', '9538xxxxxx', ignore_ndnc: true)` +* **campaign** : Name of the campaign, you want to start. + `Msgwow.send_message('message', '9538xxxxxx', campaign: 'Christmas Offer')` +* **schedule_time** : Date and Time of when you want to schedule the SMS to be sent. +Time format will be Y-m-d H:M:S . + `Msgwow.send_message('message', '9538xxxxxx', schedule_time: '2017-02-28 18:24:00')` ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. @@ -79,8 +97,8 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/sajan4 ## TODO -* Support for more options like schedule time -* Specs for features +* Support for phonebook features. +* Specs. ## License diff --git a/lib/msgwow.rb b/lib/msgwow.rb index aa7577e..1530c37 100644 --- a/lib/msgwow.rb +++ b/lib/msgwow.rb @@ -22,5 +22,16 @@ def send_message(message, numbers, options={}) msg.send! msg end + + def send_flash_message(message, numbers, options={}) + options.merge!(flash: 1) + self.send_message(message, numbers, options) + end + + def send_unicode_message(message, numbers, options={}) + options.merge!(unicode: 1) + self.send_message(message, numbers, options) + end + end end diff --git a/lib/msgwow/message.rb b/lib/msgwow/message.rb index 68a1121..32d2ea8 100644 --- a/lib/msgwow/message.rb +++ b/lib/msgwow/message.rb @@ -6,11 +6,9 @@ module Msgwow class Message - attr_accessor :message - attr_accessor :mobiles - attr_accessor :sender - attr_accessor :route - attr_accessor :response + attr_accessor :message, :mobiles, :sender, :route, + :response, :flash, :schedule_time, + :unicode, :campaign, :ignore_ndnc, :country SMS_ENDPOINT = URI.parse("http://my.msgwow.com/api/sendhttp.php?response=json") @@ -73,13 +71,43 @@ def route end def route=(new_route) - @route = new_route if new_route + @route = new_route if new_route && [1,4].include?(new_route) + end + + def flash=(flash_value) + if flash_value == true || flash_value.to_i == 1 + @flash = '1' + else + @flash = false + end + end + + def unicode=(unicode_value) + if unicode_value == true || unicode_value.to_i == 1 + @unicode = '1' + else + @unicode = false + end + end + + def country=(country_code) + @country = country_code if country_code.match(/\A\d+\z/) + end + + def schedule_time=(date_time) + # No strict validation here, just the format + @schedule_time = date_time if date_time.match(/\A\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\z/) + end + + def ignore_ndnc=(value) + if value == true || value.to_i == 1 + @ignore_ndnc = '1' + end end def options=(options) - self.sender = options[:sender] if options.has_key?(:sender) - if options.has_key?(:route) and [1,4].include? options[:route] - self.route = options[:route] + [:sender, :route, :flash, :schedule_time, :unicode, :country, :campaign].each do |attr| + self.public_send("#{attr}=", options[attr]) if options.has_key?(attr) end end @@ -111,6 +139,14 @@ def send! 'route' => route, 'sender' => sender } + # Optional arguments + [:flash, :unicode, :country, :campaign].each do |attr| + attr_value = self.public_send(attr) + params[attr.to_s] = attr_value if attr_value + end + params['schtime'] = self.schedule_time unless self.schedule_time.nil? + params['ignoreNdnc'] = self.ignore_ndnc unless self.ignore_ndnc.nil? + req.set_form_data(params) result = http.start { |http| http.request(req) } self.response = result diff --git a/lib/msgwow/version.rb b/lib/msgwow/version.rb index ce18f14..ade7fa4 100644 --- a/lib/msgwow/version.rb +++ b/lib/msgwow/version.rb @@ -1,3 +1,3 @@ module Msgwow - VERSION = "0.1.0" + VERSION = "1.1.0" end