Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
masmovil-smsclient
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gems
masmovil-smsclient
Commits
afeb2eb8
Commit
afeb2eb8
authored
Oct 03, 2020
by
Oleksandr
🎱
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: make sms library send the messages and accept correct message format
parent
7fa9715b
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
66 additions
and
83 deletions
+66
-83
.gitignore
.gitignore
+2
-0
.rspec_status
.rspec_status
+0
-13
.ruby-version
.ruby-version
+1
-1
Dockerfile
Dockerfile
+2
-9
Gemfile.lock
Gemfile.lock
+1
-1
client.rb
lib/masmovil-smsclient/client.rb
+36
-30
configuration.rb
lib/masmovil-smsclient/configuration.rb
+7
-7
spec_helper.rb
spec/spec_helper.rb
+1
-1
zoholib_spec.rb
spec/zoholib_spec.rb
+16
-21
No files found.
.gitignore
0 → 100644
View file @
afeb2eb8
.devcontainer/
.rspec_status
.rspec_status
deleted
100644 → 0
View file @
7fa9715b
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 |
.ruby-version
View file @
afeb2eb8
2.
6.3
2.
7.1
\ No newline at end of file
Dockerfile
View file @
afeb2eb8
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
Gemfile.lock
View file @
afeb2eb8
...
@@ -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
lib/masmovil-smsclient/client.rb
View file @
afeb2eb8
...
@@ -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
lib/masmovil-smsclient/configuration.rb
View file @
afeb2eb8
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
...
...
spec/spec_helper.rb
View file @
afeb2eb8
...
@@ -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:
"http://masmovil:0ckpsirlY2i9W5tzAk6j@prx.wedoops.io:443"
}
end
end
end
end
...
...
spec/zoholib_spec.rb
View file @
afeb2eb8
...
@@ -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
config
=
Wedoops
::
MasmovilSmsclient
::
Configuration
.
new
(
proxy:
"http://user:password@fake.proxy.com:1234/"
)
expect
(
config
.
valid_proxy?
)
end
end
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
xit
'The address is a valid URL'
do
end
end
end
describe
'SOAP Client'
do
describe
'SOAP Client'
do
...
@@ -41,11 +26,21 @@ RSpec.describe Wedoops::MasmovilSmsclient do
...
@@ -41,11 +26,21 @@ 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
)
expect
{
client
.
sendSMS
}.
to
raise_error
(
Wedoops
::
MasmovilSmsclient
::
MsgError
)
end
it
'Can send a correct message'
do
client
=
Wedoops
::
MasmovilSmsclient
::
Client
.
new
(
Wedoops
::
MasmovilSmsclient
.
configuration
)
client
=
Wedoops
::
MasmovilSmsclient
::
Client
.
new
(
Wedoops
::
MasmovilSmsclient
.
configuration
)
response
=
client
.
sendSMS
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
)
pp
response
pp
response
expect
(
response
).
to
be_an
(
String
)
expect
(
response
).
to
be_an
(
Savon
::
Response
)
end
end
end
end
end
end
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment