Commit 942b6e0f authored by Jose Ernesto Suarez's avatar Jose Ernesto Suarez

Merge branch 'fix/make-smslib-work' into 'master'

fix: make sms library send the messages and accept correct message format

See merge request !3
parents 7fa9715b 14305b96
.devcontainer/
.rspec_status
example_id | status | run_time |
----------------------------- | ------- | --------------- |
./spec/zoholib_spec.rb[1:1] | passed | 0.00168 seconds |
./spec/zoholib_spec.rb[1:2] | passed | 0.04786 seconds |
./spec/zoholib_spec.rb[1:3:1] | passed | 0.00112 seconds |
./spec/zoholib_spec.rb[1:3:2] | passed | 0.0001 seconds |
./spec/zoholib_spec.rb[1:3:3] | pending | 0.00001 seconds |
./spec/zoholib_spec.rb[1:3:4] | pending | 0 seconds |
./spec/zoholib_spec.rb[1:3:5] | pending | 0.00001 seconds |
./spec/zoholib_spec.rb[1:3:6] | pending | 0 seconds |
./spec/zoholib_spec.rb[1:3:7] | pending | 0 seconds |
./spec/zoholib_spec.rb[1:4:1] | passed | 0.00023 seconds |
./spec/zoholib_spec.rb[1:4:2] | failed | 0.82752 seconds |
2.6.3 2.7.1
\ No newline at end of file
FROM ruby:2.7 FROM ruby:2.7
WORKDIR /app WORKDIR /app
ADD Gemfile /app/Gemfile
#ADD Gemfile.lock /app/Gemfile.lock
ADD . /app ADD . /app
RUN bundle install --system
RUN bundle install --system
RUN rake spec RUN rake spec
RUN gem build masmovil-smsclient.gemspec RUN gem build masmovil-smsclient.gemspec
#TO-DO: Get automatically the version number #TO-DO: Get automatically the version number
RUN gem install masmovil-smsclient-$(cat /app/lib/masmovil-smsclient/version.rb|grep VERSION|cut -d '=' -f 2|sed "s/'//g" | sed "s/ //g").gem RUN gem install masmovil-smsclient-$(cat /app/lib/masmovil-smsclient/version.rb|grep VERSION|cut -d '=' -f 2|sed "s/'//g" | sed "s/ //g").gem
\ No newline at end of file
...@@ -63,4 +63,4 @@ DEPENDENCIES ...@@ -63,4 +63,4 @@ DEPENDENCIES
savon (~> 2.12.0) savon (~> 2.12.0)
BUNDLED WITH BUNDLED WITH
1.17.3 2.1.4
# Zoho Library # Zoho Library
\ No newline at end of file
### Development and testing
To run the test you can use `rake spec` command in root folder of this project.
If you have a proxy and need to set it for testing you need to provide `SMS_PROXY` environment variables.
The variable must in following format `http://<user>:<passowrd>@<host>:<port>` - any of the parts can be omitted if they are not necessary
\ No newline at end of file
...@@ -4,6 +4,12 @@ require 'savon' ...@@ -4,6 +4,12 @@ require 'savon'
module Wedoops module Wedoops
module MasmovilSmsclient module MasmovilSmsclient
class MsgError < StandardError
def initialize(msg="Provided message does not correspond correct format")
super(msg)
end
end
class Client class Client
def initialize(options=Wedoops::MasmovilSmsclient::Configuration.new) def initialize(options=Wedoops::MasmovilSmsclient::Configuration.new)
...@@ -14,22 +20,13 @@ module Wedoops ...@@ -14,22 +20,13 @@ module Wedoops
initialize_client initialize_client
end end
def sendSMS def sendSMS(msg = {})
@logger.info("Calling thing...") raise Wedoops::MasmovilSmsclient::MsgError.new("provided messages #{msg} is not valid") unless message_valid?(msg)
message = { @logger.info("Sending the message: #{msg}")
:user => "APPSimplant19", # prepare the message to send
:pass => "h6pG0S60", message = msg.merge({:user => "APPSimplant19", :pass => "h6pG0S60"})
:src => "+34619766776",
:dst => "+34619766776",
:msg => "Yeep",
:date => DateTime.now,
:name => "pepe"
}
begin begin
# pp @client response = @client.call(:send_sms, message: message)
response = @client.call(:send_sms) do
message(message)
end
rescue Exception => e rescue Exception => e
@logger.error("Error sending SMS: #{e.message}") @logger.error("Error sending SMS: #{e.message}")
return nil return nil
...@@ -39,45 +36,54 @@ module Wedoops ...@@ -39,45 +36,54 @@ module Wedoops
private private
# Message must be a has and has following keys
# :src - max 11 characters (letters and numbers only)
# :dst - phone number
# :msg - text of the SMS message
# :date - in format YYYY-mm-dd HH:MM:SS
# :name - just string name? TODO: find out what this is for
def message_valid?(msg = {})
return false unless msg.key?(:src) and msg[:src].length < 11
return false unless msg.key?(:dst) and !msg[:dst].empty?
return false unless msg.key?(:msg) and !msg[:msg].empty?
return false unless date_valid?(msg[:date])
return false unless msg.key?(:name) and !msg[:name].empty?
return true
end
def date_valid?(d)
format_ok = d.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/)
parseable = Date.strptime(d, '%F %T') rescue false
return format_ok && parseable
end
def initialize_client def initialize_client
@logger.debug("Initlizing savon") @logger.debug("Initlizing savon")
unless @proxy.nil? unless @proxy.nil?
# TO-DO: Fix the authentication as needed
#secret = Base64.strict_encode64("#{@proxy[:user]}:#{@proxy[:password]}")
#@logger.debug(@proxy)
#header={ "Proxy-Authorization" => "Basic #{secret}","Authorization" => "Basic"}
#@logger.debug(header)
@client = Savon.client( @client = Savon.client(
wsdl: 'https://websms.xtratelecom.es/api_php/server.wsdl', wsdl: 'https://websms.xtratelecom.es/api_php/server.wsdl',
pretty_print_xml: true, pretty_print_xml: true,
#convert_request_keys_to :camelcase
log: true, log: true,
log_level: :info, log_level: :info,
logger: @logger, logger: @logger,
# basic_auth: [@proxy[:user],@proxy[:password]] , filters: [:proxy, :proxy, :user, :pass, :password],
filters: [:password], proxy: @proxy,
proxy: "#{@proxy[:address]}",
#headers: header
) )
else else
@client = Savon.client( @client = Savon.client(
wsdl: 'https://websms.xtratelecom.es/api_php/server.wsdl', wsdl: 'https://websms.xtratelecom.es/api_php/server.wsdl',
pretty_print_xml: true, pretty_print_xml: true,
#convert_request_keys_to :camelcase
log: true, log: true,
log_level: :debug, log_level: :debug,
) )
end end
# end
end end
def setup_proxy def setup_proxy
@proxy = @config.option[:proxy] @proxy = @config.option[:proxy]
end end
end end
end end
end end
\ No newline at end of file
require 'uri'
# frozen_string_literal: true # frozen_string_literal: true
module Wedoops module Wedoops
module MasmovilSmsclient module MasmovilSmsclient
...@@ -8,8 +10,8 @@ module Wedoops ...@@ -8,8 +10,8 @@ module Wedoops
class Configuration class Configuration
attr_accessor :option attr_accessor :option
def initialize def initialize(opts = {})
@option = Hash.new @option = opts
end end
def uses_proxy? def uses_proxy?
...@@ -23,11 +25,9 @@ module Wedoops ...@@ -23,11 +25,9 @@ module Wedoops
private private
def validate_proxy_options(options) # check if the proxy is a valid URI
return false unless options[:user].kind_of?String def validate_proxy_options(proxy)
return false unless options[:password].kind_of?String return false unless proxy =~ URI::regexp
# TO-DO : control if the address is an address object. Maybe need initialization?
return false unless options[:address].kind_of?String
end end
end end
......
...@@ -7,7 +7,7 @@ RSpec.configure do |conf| ...@@ -7,7 +7,7 @@ RSpec.configure do |conf|
conf.before(:all) do conf.before(:all) do
Wedoops::MasmovilSmsclient.configure do |config| Wedoops::MasmovilSmsclient.configure do |config|
puts "Trying to config" puts "Trying to config"
config.option = {proxy: {user: "masmovil",password: "0ckpsirlY2i9W5tzAk6j", address: "http://masmovil:0ckpsirlY2i9W5tzAk6j@prx.wedoops.io:443"}} config.option = {proxy: ENV["SMS_PROXY"]}
end end
end end
......
...@@ -6,10 +6,6 @@ RSpec.describe Wedoops::MasmovilSmsclient do ...@@ -6,10 +6,6 @@ RSpec.describe Wedoops::MasmovilSmsclient do
expect(Wedoops::MasmovilSmsclient::VERSION).not_to be nil expect(Wedoops::MasmovilSmsclient::VERSION).not_to be nil
end end
it 'does something useful' do
expect(true).to eq(true)
end
describe 'Configuration' do describe 'Configuration' do
it 'The configuration shuld be a MasmovilSmsclient::Configuration' do it 'The configuration shuld be a MasmovilSmsclient::Configuration' do
expect(Wedoops::MasmovilSmsclient.configuration).to be_a_kind_of(Wedoops::MasmovilSmsclient::Configuration) expect(Wedoops::MasmovilSmsclient.configuration).to be_a_kind_of(Wedoops::MasmovilSmsclient::Configuration)
...@@ -19,21 +15,10 @@ RSpec.describe Wedoops::MasmovilSmsclient do ...@@ -19,21 +15,10 @@ RSpec.describe Wedoops::MasmovilSmsclient do
expect(Wedoops::MasmovilSmsclient.configuration.option).to be_an(Hash) expect(Wedoops::MasmovilSmsclient.configuration.option).to be_an(Hash)
end end
xit 'The option proxy works' do it 'The proxy can be set' do
end config = Wedoops::MasmovilSmsclient::Configuration.new(proxy: "http://user:password@fake.proxy.com:1234/")
expect(config.valid_proxy?)
xit 'I an Query if I have a proxy' do
end
xit 'I can validate user' do
end
xit 'I can validate a password' do
end end
xit 'The address is a valid URL' do
end
end end
describe 'SOAP Client' do describe 'SOAP Client' do
...@@ -41,11 +26,18 @@ RSpec.describe Wedoops::MasmovilSmsclient do ...@@ -41,11 +26,18 @@ RSpec.describe Wedoops::MasmovilSmsclient do
expect(Wedoops::MasmovilSmsclient::Client.new).to be_an(Wedoops::MasmovilSmsclient::Client) expect(Wedoops::MasmovilSmsclient::Client.new).to be_an(Wedoops::MasmovilSmsclient::Client)
end end
it 'Can Send a SMS' do it 'Cannot send an empty message' do
client=Wedoops::MasmovilSmsclient::Client.new(Wedoops::MasmovilSmsclient.configuration) client=Wedoops::MasmovilSmsclient::Client.new(Wedoops::MasmovilSmsclient.configuration)
response= client.sendSMS expect { client.sendSMS }.to raise_error(Wedoops::MasmovilSmsclient::MsgError)
pp response end
expect(response).to be_an(String)
it 'Can send a correct message' do
client=Wedoops::MasmovilSmsclient::Client.new(Wedoops::MasmovilSmsclient.configuration)
future_date = DateTime.now + (5/1440.0)
msg = {:src => "TESTER", :dst => "+34619766776", :msg => "This is the tester text #{DateTime.now.to_s}", :name => "Testing", :date => future_date.strftime("%F %TZ")}
response = client.sendSMS(msg)
expect(response).to be_an(Savon::Response)
end end
end end
end end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment