Skip to content

Commit

Permalink
Added support for rest of the missing message options
Browse files Browse the repository at this point in the history
Below are the new options which are added:
* country
* flash
* unicode
* ignoreNdnc (ignore_ndnc)
* schtime (schedule_time)
* campaign
  • Loading branch information
sajan45 committed Feb 28, 2017
1 parent 29fbb8f commit 472a290
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 13 deletions.
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
11 changes: 11 additions & 0 deletions lib/msgwow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
54 changes: 45 additions & 9 deletions lib/msgwow/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/msgwow/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Msgwow
VERSION = "0.1.0"
VERSION = "1.1.0"
end

0 comments on commit 472a290

Please sign in to comment.