OpenMarket
We use HTTParty to send SMS messages using the OpenMarket API. See USAGE below for details.
Installation
Add this line to your application's Gemfile:
gem 'openmarket'
And then execute:
$ bundle
Or install it yourself as:
$ gem install openmarket
Usage
Configuration
The openmarket gem requires you to provide an id, password, program_id and short_code. Configure them before attempting any API calls.
OpenMarket.configure do |config|
config.id = "000-000-000-00000"
config.password = "Re@llyL0ngR&om$tr1ng"
config.program_id = "ABC"
config.short_code = 99999
end
Since the openmarket gem depends on sms_validation (https://github.com/betesh/sms_validation/), it is also recommended that you configure sms_validation.
openmarket uses sms_validation's logger. In a Rails environment, you will probably want to rely on the default configuration,
but outside of Rails, you will need to configure it if you want any logging:
SmsValidation.configure do |config|
config.logger = ::Logger.new(STDOUT)
end
API calls
OpenMarket::API supports 3 API calls: carrier_lookup, send_sms, and status.
carrier_lookup
require 'openmarket'
phone = 2125551212
result = OpenMarket::API.carrier_lookup(phone)
puts result.code
puts result.description
puts result.carrier_id
puts result.inspect
send_sms
require 'openmarket'
phone = 2125551212
message = "Hello, this is a test of the OpenMarket API"
result = OpenMarket::API.send_sms(phone, message)
puts result.code
puts result.description
ticket_id = result.ticket_id
carrier_id = result.carrier_id
result = OpenMarket::API.send_sms(
phone,
message,
dr_url: "http://www.example.com/drs",
carrier_id: carrier_id,
short_code: 33333,
minutes_to_retry: 120,
note: "Information that will be passed on to the DR",
ticket_id_for_retry: ticket_id
)
status
require 'openmarket'
result = OpenMarket::API.status(ticket_id)
puts result.code
puts result.description
puts result.status_code
puts result.status_description
Processing MO's
require 'openmarket/mo'
mo = OpenMarket::MO.new(params['xml'])
puts mo.inspect
render nothing: true
return [200]
Processing DR's
require 'openmarket/dr'
dr = OpenMarket::DR.new(params['xml'])
puts dr.inspect
render nothing: true
return [200]
Contributing
- Fork it ( https://github.com/betesh/open_market/fork )
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create a new Pull Request