Skip to content

Commit

Permalink
looking better and working
Browse files Browse the repository at this point in the history
  • Loading branch information
nofxx committed Aug 17, 2008
1 parent 8160374 commit 2cc7ca1
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 57 deletions.
11 changes: 5 additions & 6 deletions lib/activesms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,9 @@
end
end

# Require global config
require 'activesms/config'
# These ppl need global config:
# Email need config first
require 'activesms/email'

# Require base classes.
require 'activesms/version'
require 'activesms/base'
require 'activesms/connections'
require 'activesms/exceptions'
Expand All @@ -73,8 +69,11 @@
require 'activesms/connection_adapters/clickatell_adapter'
require 'activesms/connection_adapters/human_adapter'

# # #
# # Establish a connection if we have yml parameters
ActiveSms::Base.establish_connection(ActiveSms::GATEWAY) if ActiveSms::GATEWAY

# Simplewire requires jruby
if RUBY_PLATFORM =~ /java/
require 'activesms/connection_adapters/simplewire_adapter'
end
end
8 changes: 2 additions & 6 deletions lib/activesms/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module ActiveSms #:nodoc#
# #
# Check out if we are on rails
# if not, use default yml with only email (for now)
# if not, use default yml with only email
RAILS_CONFIG_ROOT = defined?(RAILS_ROOT) ? "#{RAILS_ROOT}/config" : "#{File.dirname(__FILE__)}/../../generators/sms/templates" unless defined?(RAILS_CONFIG_ROOT)
# and load what we have!
conf_yml ||= YAML::load(File.open("#{RAILS_CONFIG_ROOT}/sms.yml"))
Expand All @@ -18,10 +18,6 @@ module ActiveSms #:nodoc#

# #
# Get all carriers
CARRIERS = conf_yml['carriers']

# #
# Establish a connection if we have yml parameters
ActiveSms::Base.establish_connection(GATEWAY) if GATEWAY
CARRIERS = conf_yml['carriers']

end
3 changes: 1 addition & 2 deletions lib/activesms/connections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def establish_connection(config)
# a particular SMS gateway.
def connection
self.class.connection
end

end
end
end
12 changes: 6 additions & 6 deletions lib/activesms/email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module Email
@@carriers ||= CARRIERS
@@from_address ||= CONFIG['from_address']

# def self.carriers
# @@carriers.dup
# end
def carriers
@@carriers.dup
end

def email_deliver(sms)#number,carrier,message,options={})

Expand All @@ -15,11 +15,11 @@ def email_deliver(sms)#number,carrier,message,options={})
# number = format_number(number)

#options[:limit] ||= message.length
options[:from] ||= @@from_address
#options[:from] ||= @@from_address
#message = message[0..options[:limit]-1]
sms_email = determine_sms_email(number, carrier)#format_number(number),carrier)

Sms2Email.deliver_sms_message(sms_email, sms.body, options[:from])
Sms2Email.deliver_sms_message(sms_email, sms.body, @@from_address)
rescue CarrierException => e
raise e
end
Expand All @@ -43,7 +43,7 @@ def is_valid?(number)
end

def determine_sms_email(phone_number, carrier)
carrier = carrier.downcase
carrier = carrier.to_s.downcase

if carriers.has_key?(carrier)
"#{phone_number}#{carriers[carrier]}"
Expand Down
2 changes: 1 addition & 1 deletion lib/activesms/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module ActiveSms #:nodoc:
module VERSION #:nodoc:
MAJOR = 0
MINOR = 8
TINY = 9
TINY = 10

STRING = [MAJOR, MINOR, TINY].join('.')
end
Expand Down
66 changes: 31 additions & 35 deletions spec/activesms/email_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,47 @@


class Noter < ActiveSms::Base
#CARRIERS = []
#include Email
def emaio
@delivery = :email
@carrier = 'tim' #
@recipients = '553591412167'#'553187835666'
@from = ''
@body = "Nodsdsdsdster#emaio"
#@id = ''
#@schedule = "dd/mm/aaaa hh:mm:ss"
@options = {}
end




def emaio
@delivery = :email
@carrier = 'tim' #
@recipients = '5555555555'
@from = 'me@somewhere.net'
@body = "Hi Friend"
#@id = ''
#@schedule = "dd/mm/aaaa hh:mm:ss"
@options = {}
end
end

describe Email do

it "should deliver an sms" do
sms = mock(Sms, :delivery => :email, :recipients => '5555555555', :body => 'hi', :options => {},
:id => 1, :carrier => :tim, :from => 'other@domain.com', :schedule => "08/08/2008 01:18:56")
Sms2Email.should_receive(:deliver_sms_message).with("5555555555@tim.com.br", "hi", "noreply@domain.com").and_return(true)
Noter.deliver(sms)
end

before(:each) do
# @base = ck(Noter)
@email = Noter.create_emaio
#Sms.new#.create_emaio#ActiveSms::Base#.stub!(:new_notifier)

it "should determine a correct email address" do
Noter.get_sms_address('5543214321', 'tim').should eql('5543214321@tim.com.br')
#@email.get_sms_address('5543214321', 'oi').should eql('5543214321@sms.oi.com.br')
end

it "should be valid" do


describe "Instantiated" do
before(:each) do
@email = Noter.create_emaio
end

it "should be valid" do
violated unless @email
end
end


it "should deliver an sms" do
sms = mock(Sms, :recipients => 'x@xx.com', :body => 'hi', :id => 1, :carrier => :tim,
:from => 'no@mail.com', :schedule => "08/08/2008 01:18:56")
Sms2Email.should_receive(:deliver_sms_message).with("some@mail.com", "hi", "Mr X").and_return(true)
@email.stub!('ActiveSms::CARRIERS').and_return(true)
@email.email_deliver(sms)
end


#
# # it "should determine a correct email address" do
# # ActiveSms::Base.should_receive(:get_sms_address)
# #@email.get_sms_address('5543214321', 'tim').should eql('5543214321@tim.com.br')
# # @email.get_sms_address('5543214321', 'oi').should eql('5543214321@sms.oi.com.br')
# end
#
# it "should clean the number" do
# @email.get_sms_address('5-543-2=14321', 'tim').should eql('5543214321@tim.com.br')
Expand Down
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
$:.unshift(File.dirname(__FILE__) + '/../lib')
$:.unshift(File.dirname(__FILE__) + '/../lib/activesms')
$:.unshift(File.dirname(__FILE__) + '/../lib/activesms/connection_adapters')
# require 'activesms/sms'
require 'activesms'
require 'activesms/connection_adapters/abstract_adapter'
#
# require 'activesms/connection_adapters/abstract_adapter'
include ActiveSms

# #
Expand Down

0 comments on commit 2cc7ca1

Please sign in to comment.