bulksms 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *.swp
6
+ *.swo
@@ -0,0 +1,22 @@
1
+ * 0.5.0
2
+ Completely re-written.
3
+ Simple API via Bulksms module.
4
+ Support for configuration object.
5
+ Railtie links for Rails > 3.X configurations.
6
+
7
+ * 0.4
8
+ Adding method send_multiple to bulksms.rb file
9
+
10
+ * 0.3
11
+ Fixing a bug related to getting the host of bulksms service
12
+ Added gem spec file to the library
13
+ Packaging the library as a gem
14
+
15
+ * 0.2
16
+ Added CHANGELOG and a README file
17
+ Added support for BulkSMS international sites
18
+
19
+ * 0.1
20
+ Added support for sending messages
21
+ Added support checking account balance
22
+ Included a small example command-line client
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bulksms.gemspec
4
+ gemspec
@@ -0,0 +1,88 @@
1
+ = Introduction
2
+
3
+ BulkSMS is a Ruby library that allows you to easily integrate SMS services into your Ruby or Ruby on Rails applications.
4
+
5
+ It has support for all BulkSMS international sites, including the UK, USA, South Africa, Spain and Europe.
6
+
7
+ To use the library, you will need an account from www.bulksms.com and some credits.
8
+
9
+ = Configuration
10
+
11
+ Simply set using the configuration object provided by the Bulksms module:
12
+
13
+ Bulksms.config do |config|
14
+ config.username = 'testuser'
15
+ config.password = 'zepass'
16
+ config.country = :uk
17
+ end
18
+
19
+ If Rails is available, the library can be configured using the standard environment configs:
20
+
21
+ SomeRails::Application.configure do
22
+
23
+ # set config in one go
24
+ config.bulksms do |c|
25
+ c.username = 'testuser'
26
+ c.password = 'zepass'
27
+ end
28
+
29
+ # single config options
30
+ config.bulksms.country = :es
31
+
32
+ end
33
+
34
+ = Examples
35
+
36
+ Sending a quick message is very simple:
37
+
38
+ Bulksms.deliver(:message => 'Hello, I hope you like my message!', :recipient => '44799123456')
39
+
40
+ == Multiple messages
41
+
42
+ Provide an array of hashes and multiple messages will be sent via the same HTTP connection:
43
+
44
+ Bulksms.deliver([{:message => 'Test Message', :recipient => "44342134131"}, {:message => "Another Msg", :recipient => "4441234354254"}])
45
+
46
+ == Additional message options
47
+
48
+ If you prefer more control, the <tt>Service</tt> and <tt>Message</tt> objects are also available for direct usage:
49
+
50
+ s = Bulksms::Service.new
51
+ m = Bulksms::Message.new(:message => "Test Message", :recipient => "34901123123")
52
+ m.routing_group = 1
53
+ m.want_report = 1
54
+ s.deliver(m)
55
+
56
+
57
+ == Checking your account balance
58
+
59
+ Use the main module to request the current user's balance:
60
+
61
+ Bulksms.credits
62
+
63
+ A <tt>Bulksms::AccountError</tt> will be raised if there is a problem.
64
+
65
+ = Limitations
66
+
67
+ This library currently only implements a small portion of the API, allowing you to send messages and check your account balance. Further parts of the BulkSMS API may be implemented in the future such as the ability to receive messages and status reports and manage the address book provided by BulkSMS.
68
+
69
+ = Testing
70
+
71
+ Rspec from the console:
72
+
73
+ rspec spec
74
+
75
+ Tests still need a bit more work to cover all cases.
76
+
77
+ = Authors
78
+
79
+ The Original work on "ruby-bulksms" was made by Luke Redpath (email:contact@lukeredpath.co.uk). Modifications were added by Basayel Said (email:eng.basayel.said@gmail.com).
80
+
81
+ The latest version, "bulksms", with a simpler interface, rspec testing, and an easier configuration was written by Sam Lown (me@samlown.com).
82
+
83
+ Modifications include:
84
+
85
+ * simple helper module for direct access to classes
86
+ * DRYer support libraries
87
+ * Railtie support for configuration
88
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "bulksms/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "bulksms"
7
+ s.version = Bulksms::VERSION
8
+ s.authors = ["Sam Lown", "Basayel Said", "Shuntyard Technologies"]
9
+ s.email = ["me@samlown.com"]
10
+ s.homepage = "https://github.com/samlown/bulksms"
11
+ s.summary = %q{Simple BulkSMS API}
12
+ s.description = %q{Send SMS text messages via the BulkSMS API.}
13
+
14
+ s.rubyforge_project = "bulksms"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec"
23
+ s.add_development_dependency "fakeweb"
24
+ # s.add_runtime_dependency "rest-client"
25
+ end
@@ -0,0 +1,56 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
2
+
3
+ require 'bulksms'
4
+
5
+ puts "\nWelcome to the BulkSMS Sender!"
6
+ puts "--------------------------------\n\n"
7
+
8
+ print 'Please enter your account username: '
9
+ username = gets.strip
10
+
11
+ print 'Please enter your account password: '
12
+ password = gets.strip
13
+
14
+ print 'Please enter your account country: (international)'
15
+ country = gets.strip
16
+ country = country.to_s.empty? ? :international : country.to_sym
17
+
18
+ puts "\nChecking...\n\n"
19
+
20
+ # set the configuration details
21
+ Bulksms.config do |c|
22
+ c.username = username
23
+ c.password = password
24
+ c.country = country
25
+ end
26
+
27
+ begin
28
+ credits = Bulksms.credits
29
+ puts "Welcome back #{username}. You have #{credits} credits remaining.\n\n"
30
+ rescue Bulksms::AccountError => d
31
+ puts "Sorry, there was an error validating your account details."
32
+ puts "\n\t#{d}\n\n"
33
+ puts "Goodbye."
34
+ exit
35
+ end
36
+
37
+ print "Enter the mobile number of the person you want to send an SMS to: "
38
+ recipient = gets.strip
39
+
40
+ print "Now enter your message: "
41
+ message = gets.strip
42
+
43
+ puts "\nThank you. Processing...\n\n"
44
+
45
+ response = Bulksms.send(:message => message, :recipient => recipient, :test_always_success => 1)
46
+
47
+ if response.success?
48
+ puts "Your SMS was sent successfully.\n\n"
49
+ puts "You now have #{Bulksms.credits} credits remaining."
50
+ puts "Goodbye!"
51
+ else
52
+ puts "Sorry, but your SMS was not sent this time. The service returned the error:"
53
+ puts "\n\t#{response.code}: #{response.description}\n\n"
54
+ puts "Please try again later. Goodbye."
55
+ end
56
+
@@ -0,0 +1,50 @@
1
+
2
+ require "net/http"
3
+ require "uri"
4
+ require "bulksms/version"
5
+ require "bulksms/configuration"
6
+ require "bulksms/message"
7
+ require "bulksms/account"
8
+ require "bulksms/service"
9
+ require "bulksms/response"
10
+
11
+ if defined?(Rails)
12
+ require "bulksms/railtie"
13
+ end
14
+
15
+ module Bulksms
16
+ extend self
17
+
18
+ def config
19
+ @config ||= Configuration.new
20
+ yield @config if block_given?
21
+ @config
22
+ end
23
+
24
+ # Simple wrapper for sending SMS messages via BulkSMS API.
25
+ # The most simple message should be provided as a hash as follows:
26
+ #
27
+ # {
28
+ # :message => "Body of message to send",
29
+ # :recipient => "+34644477123"
30
+ # }
31
+ #
32
+ # An array of messages may also be provided to send multiple SMS
33
+ # in the same HTTP connection.
34
+ #
35
+ def deliver(*args)
36
+ msg = args.shift
37
+ opts = args.shift || {}
38
+ service = Service.new(opts)
39
+ service.deliver(msg)
40
+ end
41
+
42
+ # Request the number of credits available in your account.
43
+ # Returns a single float if successful, or raises an AccountError exception.
44
+ def credits(*args)
45
+ opts = args.last || { }
46
+ account = Account.new(opts)
47
+ account.credits
48
+ end
49
+
50
+ end
@@ -0,0 +1,59 @@
1
+ module Bulksms
2
+
3
+ class AccountError < Exception; end
4
+
5
+ class Account
6
+
7
+ attr_reader :username, :password, :host, :port
8
+
9
+ def initialize(opts = {})
10
+ opts ||= { }
11
+ @username = opts[:username] || Bulksms.config.username
12
+ @password = opts[:password] || Bulksms.config.password
13
+ @host = opts[:host] || Bulksms.config.host
14
+ @port = opts[:port] || Bulksms.config.port
15
+ end
16
+
17
+ def to_params
18
+ { 'username' => @username, 'password' => @password }
19
+ end
20
+
21
+ def credits
22
+ res = request Bulksms.config.credits_path
23
+ raise(AccountError, res.result, caller) if res.code != 0
24
+ res.result.to_f
25
+ end
26
+
27
+ def request(path, params = {})
28
+ response = nil
29
+ connection do |http|
30
+ if params.is_a?(Array)
31
+ response = params.map{|p| post(http, path, p)}
32
+ else
33
+ response = post(http, path, params)
34
+ end
35
+ end
36
+ response
37
+ end
38
+
39
+ protected
40
+
41
+ def post(http, path, params = {})
42
+ payload = params_to_query_string(to_params.merge(params))
43
+ response = http.post path, payload
44
+ Response.parse(response.body)
45
+ end
46
+
47
+ def connection
48
+ Net::HTTP.start(host, port) do |http|
49
+ yield http
50
+ end
51
+ end
52
+
53
+ def params_to_query_string(params)
54
+ URI.encode(params.collect{|x,y| "#{x}=#{y}"}.join('&'))
55
+ end
56
+
57
+ end
58
+
59
+ end
@@ -0,0 +1,43 @@
1
+ module Bulksms
2
+
3
+ class Configuration
4
+
5
+ attr_accessor :username
6
+ attr_accessor :password
7
+ attr_accessor :country
8
+ attr_accessor :host
9
+ attr_accessor :port
10
+ attr_accessor :message_path
11
+ attr_accessor :credits_path
12
+ attr_accessor :message_class
13
+
14
+ def initialize
15
+ # Prepare default options
16
+ self.country = :international
17
+ self.port = 5567
18
+ self.message_path = "/eapi/submission/send_sms/2/2.0"
19
+ self.credits_path = "/eapi/user/get_credits/1/1.1"
20
+ self.message_class = 2
21
+ end
22
+
23
+ # Overide the default host config so that a short name will be converted
24
+ # into a full hostname.
25
+ def host
26
+ return @host unless @host.to_s.empty?
27
+ case @country
28
+ when :uk
29
+ 'www.bulksms.co.uk'
30
+ when :usa
31
+ 'usa.bulksms.com'
32
+ when :safrica
33
+ 'bulksms.2way.co.za'
34
+ when :spain
35
+ 'bulksms.com.es'
36
+ else # :international
37
+ 'bulksms.vsms.net'
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,48 @@
1
+ module Bulksms
2
+
3
+ # Encapsulates a message to be sent by the gateway
4
+ class Message
5
+
6
+ # The various attributes for a message as defined
7
+ # by the BulkSMS HTTP API. For full details on the
8
+ # different attributes see:
9
+ # http://www.bulksms.co.uk/docs/eapi/submission/send_sms/
10
+ attr_accessor :message, :recipient, :msg_class,
11
+ :want_report, :routing_group, :source_id,
12
+ :test_always_succeed, :test_always_fail,
13
+ :concat_text_sms, :concat_max_parts
14
+
15
+ def initialize(opts = {})
16
+ @message = opts[:message]
17
+ @recipient = opts[:recipient]
18
+ @msg_class = Bulksms.config.message_class
19
+ @want_report = 0
20
+ @routing_group = 2
21
+ @source_id = ''
22
+ @test_always_succeed = opts[:test_always_succeed] || 0
23
+ @test_always_fail = opts[:test_always_fail] || 0
24
+ @concat_text_sms = 0
25
+ @concat_max_parts = 2
26
+ end
27
+
28
+ # Returns a message as a http query string for use
29
+ # by other gateway services
30
+ def to_params
31
+ raise "Missing message!" if @message.to_s.empty?
32
+ raise "Missing recipient!" if @recipient.to_s.empty?
33
+ {
34
+ 'message' => @message,
35
+ 'msisdn' => @recipient,
36
+ 'msg_class' => @msg_class,
37
+ 'want_report' => @want_report,
38
+ 'routing_group' => @routing_group,
39
+ 'source_id' => @source_id,
40
+ 'test_always_succeed' => @test_always_succeed,
41
+ 'test_always_fail' => @test_always_fail,
42
+ 'allow_concat_text_sms' => @concat_text_sms,
43
+ 'concat_text_sms_max_parts' => @concat_max_parts
44
+ }
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,11 @@
1
+ module Bulksms
2
+
3
+ class Railtie < ::Rails::Railtie
4
+
5
+ config.before_configuration do
6
+ config.bulksms = Bulksms.config
7
+ end
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,22 @@
1
+ module Bulksms
2
+ class Response
3
+
4
+ attr_reader :code, :result, :batch_id
5
+
6
+ def initialize(code, result, batch_id)
7
+ @code = code
8
+ @result = result
9
+ @batch_id = batch_id
10
+ end
11
+
12
+ def success?
13
+ @code == 0
14
+ end
15
+
16
+ def self.parse(response_text)
17
+ tokens = response_text.split('|')
18
+ new tokens[0].to_i, tokens[1], tokens[2].to_i
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,33 @@
1
+ module Bulksms
2
+
3
+ class Service
4
+
5
+ attr_accessor :account
6
+
7
+ def initialize(opts = {})
8
+ @account = Account.new(opts)
9
+ end
10
+
11
+ # Send a single message or multiple messages.
12
+ def deliver(*args)
13
+ msg = args.shift
14
+ opts = args.shift || {}
15
+ case msg
16
+ when Hash
17
+ msg = Message.new(msg)
18
+ when Array
19
+ msg = msg.map{|m| m.is_a?(Message) ? m : Message.new(m)}
20
+ end
21
+ send_request(msg)
22
+ end
23
+
24
+ protected
25
+
26
+ def send_request(msg)
27
+ params = msg.is_a?(Array) ? msg.map{|m| m.to_params} : msg.to_params
28
+ @account.request Bulksms.config.message_path, params
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,3 @@
1
+ module Bulksms
2
+ VERSION = "0.5.0"
3
+ end
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,86 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe Bulksms::Account do
5
+
6
+ before :all do
7
+ Bulksms.config.username = "fooobar"
8
+ Bulksms.config.password = "passs"
9
+ end
10
+
11
+ describe "initialisation" do
12
+
13
+ it "should set initial values" do
14
+ @account = Bulksms::Account.new
15
+ @account.username.should eql("fooobar")
16
+ @account.password.should eql("passs")
17
+ end
18
+
19
+ it "should allow override of attirbutes" do
20
+ @account = Bulksms::Account.new(:username => 'bardom', :password => "fooooed")
21
+ @account.username.should eql('bardom')
22
+ @account.password.should eql('fooooed')
23
+ end
24
+
25
+ end
26
+
27
+ describe "methods" do
28
+
29
+ before :each do
30
+ @account = Bulksms::Account.new
31
+ end
32
+
33
+ describe "#to_params" do
34
+ it "should return hash of username and password" do
35
+ @account.to_params.should eql('username' => 'fooobar', 'password' => 'passs')
36
+ end
37
+ end
38
+
39
+ describe "#credits" do
40
+
41
+ before :all do
42
+ @conf = Bulksms.config
43
+ end
44
+
45
+ it "returns credits on success" do
46
+ FakeWeb.register_uri(:post, "http://#{@conf.host}:#{@conf.port}#{@conf.credits_path}", :body => "0|302.3")
47
+ @account.credits.should eql(302.3)
48
+ end
49
+
50
+ it "raises an error when request fails" do
51
+ FakeWeb.register_uri(:post, "http://#{@conf.host}:#{@conf.port}#{@conf.credits_path}", :body => "23|Authentication failed")
52
+ expect { @account.credits }.to raise_error Bulksms::AccountError, /Authentication/
53
+ end
54
+
55
+ end
56
+
57
+ describe "#request" do
58
+ # TODO: fix: These tests are slightly flawed as they do not test the parameters.
59
+
60
+ before :all do
61
+ @conf = Bulksms.config
62
+ end
63
+
64
+ it "will send single request to server" do
65
+ FakeWeb.register_uri(:post, "http://#{@conf.host}:#{@conf.port}/test", {:body => "0|OK|1234"})
66
+ @account.request("/test", {:foo => :bar}).success?.should be_true
67
+ end
68
+
69
+ it "will send bad single request to server" do
70
+ FakeWeb.register_uri(:post, "http://#{@conf.host}:#{@conf.port}/test", {:body => "22|Internal fatal error|1234"})
71
+ @account.request("/test", {:foo => :bar}).success?.should be_false
72
+ end
73
+
74
+ it "will send multiple requests to server" do
75
+ FakeWeb.register_uri(:post, "http://#{@conf.host}:#{@conf.port}/test", [{:body => "0|OK|1234"}, {:body => "0|OK|1234"}])
76
+ res = @account.request("/test", [{:foo => :bar}, {:foo => :bar}])
77
+ res.should be_a(Array)
78
+ res[0].success?.should be_true
79
+ res[1].success?.should be_true
80
+ end
81
+
82
+ end
83
+
84
+ end
85
+
86
+ end
@@ -0,0 +1,74 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe Bulksms do
5
+
6
+ it "should exist" do
7
+ Bulksms.should be_a(Module)
8
+ end
9
+
10
+ describe "#config" do
11
+
12
+ it "should be provided" do
13
+ Bulksms.config.should be_a(Bulksms::Configuration)
14
+ end
15
+
16
+ it "should accept a block to set config options" do
17
+ Bulksms.config.username = ""
18
+ Bulksms.config do |c|
19
+ c.username = "foobar"
20
+ end
21
+ Bulksms.config.username.should eql('foobar')
22
+ end
23
+
24
+ end
25
+
26
+ describe "#deliver" do
27
+
28
+ it "should exist" do
29
+ Bulksms.should respond_to(:deliver)
30
+ end
31
+
32
+ it "should send a message" do
33
+ service = mock(:Service)
34
+ service.should_receive(:deliver)
35
+ Bulksms::Service.should_receive(:new).with({}).and_return(service)
36
+ Bulksms.deliver(:message => "Test", :recipient => "123456")
37
+ end
38
+
39
+ it "should send a message with opts" do
40
+ opts = {:opts => 'bar'}
41
+ service = mock(:Service)
42
+ service.should_receive(:deliver)
43
+ Bulksms::Service.should_receive(:new).with(opts).and_return(service)
44
+ Bulksms.deliver({:message => "Test", :recipient => "123456"}, opts)
45
+ end
46
+
47
+
48
+ end
49
+
50
+ describe "#credits" do
51
+
52
+ it "should exist" do
53
+ Bulksms.should respond_to(:credits)
54
+ end
55
+
56
+ it "should request credits" do
57
+ account = mock(:Account)
58
+ account.should_receive(:credits)
59
+ Bulksms::Account.should_receive(:new).with({}).and_return(account)
60
+ Bulksms.credits
61
+ end
62
+
63
+ it "should pass options to account" do
64
+ opts = {:opts => 'bar'}
65
+ account = mock(:Account)
66
+ account.should_receive(:credits)
67
+ Bulksms::Account.should_receive(:new).with(opts).and_return(account)
68
+ Bulksms.credits(opts)
69
+ end
70
+
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bulksms::Configuration do
4
+
5
+ before :each do
6
+ @config = Bulksms::Configuration.new
7
+ end
8
+
9
+ describe "accessors" do
10
+ it "should be provided" do
11
+ [:username, :password, :country, :host, :port, :message_path,
12
+ :credits_path, :message_class].each do |accessor|
13
+ @config.should respond_to accessor
14
+ end
15
+ end
16
+ end
17
+
18
+ describe "initialize" do
19
+
20
+ it "should set defaults" do
21
+ @config.country.should eql(:international)
22
+ @config.port.should eql(5567)
23
+ @config.message_path.should_not be_empty
24
+ @config.credits_path.should_not be_empty
25
+ @config.message_class.should eql(2)
26
+ end
27
+
28
+ end
29
+
30
+ describe "#host" do
31
+
32
+ it "should provide international host by default" do
33
+ @config.host.should eql('bulksms.vsms.net')
34
+ end
35
+
36
+ it "should provide hostname from country if blank" do
37
+ @config.country = :uk
38
+ @config.host.should eql('www.bulksms.co.uk')
39
+ end
40
+
41
+ it "should provide host name if set" do
42
+ @config.host = "some.host"
43
+ @config.host.should eql("some.host")
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
@@ -0,0 +1,41 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe Bulksms::Message do
5
+
6
+ describe "initialize" do
7
+
8
+ it "should instantiate" do
9
+ Bulksms::Message.new.should be_a(Bulksms::Message)
10
+ end
11
+
12
+ it "should accept message payload details" do
13
+ @msg = Bulksms::Message.new :message => "foo", :recipient => "1234"
14
+ @msg.message.should eql("foo")
15
+ @msg.recipient.should eql("1234")
16
+ end
17
+
18
+ end
19
+
20
+
21
+ describe "#to_params" do
22
+
23
+ it "should return a hash of parameters" do
24
+ @msg = Bulksms::Message.new :message => "foo", :recipient => "1234"
25
+ @msg.to_params['message'].should eql('foo')
26
+ @msg.to_params['msisdn'].should eql('1234')
27
+ end
28
+
29
+ it "should raise an error if recipient is missing" do
30
+ @msg = Bulksms::Message.new :message => "foo"
31
+ expect { @msg.to_params }.to raise_error /recipient/
32
+ end
33
+
34
+ it "should raise an error if message is missing" do
35
+ @msg = Bulksms::Message.new :recipient => "1234"
36
+ expect { @msg.to_params }.to raise_error /message/
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bulksms::Service do
4
+
5
+ describe "initialization" do
6
+
7
+ it "instantiates account with options" do
8
+ opts = {:random => 'stuff'}
9
+ Bulksms::Account.should_receive(:new).once.with(opts)
10
+ Bulksms::Service.new(opts)
11
+ end
12
+
13
+ end
14
+
15
+ describe "#deliver" do
16
+
17
+ before :each do
18
+ @service = Bulksms::Service.new
19
+ @service.stub!(:send_request)
20
+ end
21
+
22
+ it "should convert hash into message" do
23
+ msg = {:message => "Foooo", :recipient => "1232131"}
24
+ Bulksms::Message.should_receive(:new).once.with(msg)
25
+ @service.deliver(msg)
26
+ end
27
+
28
+ it "should convert hash array into message array" do
29
+ msgs = [{:message => "Foooo", :recipient => "1232131"}, {:message => "Foooo", :recipient => "1232131"}]
30
+ Bulksms::Message.should_receive(:new).once.with(msgs[0])
31
+ Bulksms::Message.should_receive(:new).once.with(msgs[1])
32
+ @service.deliver(msgs)
33
+ end
34
+
35
+ it "should not do anything to a real Message" do
36
+ msg = Bulksms::Message.new(:message => "foobar", :recipient => "123344544")
37
+ @service.should_receive(:send_request).with(msg)
38
+ @service.deliver(msg)
39
+ end
40
+
41
+ end
42
+
43
+ describe "#send_request" do
44
+
45
+ before :each do
46
+ @service = Bulksms::Service.new
47
+ end
48
+
49
+ it "should convert messages to params" do
50
+ msg = Bulksms::Message.new(:message => 'test', :recipient => '1234')
51
+ @service.account = mock(:Account)
52
+ @service.account.should_receive(:request).with(Bulksms.config.message_path, msg.to_params)
53
+ @service.send(:send_request, msg)
54
+ end
55
+
56
+ end
57
+
58
+
59
+ end
60
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'fakeweb'
5
+ require 'bulksms'
6
+
7
+ RSpec.configure do |config|
8
+ # some (optional) config here
9
+ # end
10
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bulksms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sam Lown
9
+ - Basayel Said
10
+ - Shuntyard Technologies
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2011-11-28 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ requirement: &21179040 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: *21179040
27
+ - !ruby/object:Gem::Dependency
28
+ name: fakeweb
29
+ requirement: &21178380 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *21178380
38
+ description: Send SMS text messages via the BulkSMS API.
39
+ email:
40
+ - me@samlown.com
41
+ executables: []
42
+ extensions: []
43
+ extra_rdoc_files: []
44
+ files:
45
+ - .gitignore
46
+ - CHANGELOG
47
+ - Gemfile
48
+ - README.rdoc
49
+ - Rakefile
50
+ - bulksms.gemspec
51
+ - examples/client.rb
52
+ - lib/bulksms.rb
53
+ - lib/bulksms/account.rb
54
+ - lib/bulksms/configuration.rb
55
+ - lib/bulksms/message.rb
56
+ - lib/bulksms/railtie.rb
57
+ - lib/bulksms/response.rb
58
+ - lib/bulksms/service.rb
59
+ - lib/bulksms/version.rb
60
+ - spec/.rspec
61
+ - spec/account_spec.rb
62
+ - spec/bulksms_spec.rb
63
+ - spec/configuration_spec.rb
64
+ - spec/message_spec.rb
65
+ - spec/service_spec.rb
66
+ - spec/spec_helper.rb
67
+ homepage: https://github.com/samlown/bulksms
68
+ licenses: []
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project: bulksms
87
+ rubygems_version: 1.8.10
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Simple BulkSMS API
91
+ test_files: []