textveloper 0.1.6 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78e5661ebae07a5d06455e310099e6423e09e384
4
- data.tar.gz: 6cafa7251f0c04ec359bb8355e9aeddf6cf39fea
3
+ metadata.gz: 73e6c36f3f3594e0b5f1821c0791fe15335c66f8
4
+ data.tar.gz: 2ef5f5233cf4860e4295b62e424baff3f8e3c7be
5
5
  SHA512:
6
- metadata.gz: 2276a163fd52175f4b3ced6c747ed42f66675a386a8f4ff2b185f5530a61dae46791ae240768d0ab17753cba2480c0045508cff45e122f1386fa09f3b5f1ea31
7
- data.tar.gz: 84ca58c55c24a260e04180a5377e540b4b33ed1b86407037f4a0f43a118ddaa4deaf43b3ac37c154aacb5a7e734810894a175f1060e0e362a8c38626f70a6144
6
+ metadata.gz: f314b95655d086b8a1b1a07d8b8fe5ea3d956aa01099fdeb38b9896d7e31c673016efa5dc98f06c10a3ce1eabb37f3ca218e62323dd355bcb129f03dd7940f45
7
+ data.tar.gz: e6475cfbbcaa3ad36456df2882f79e939c9c40a073ebdc731de2116f5b130e0940d41063829bae3ac58dcf7d40ae7ec74b9ea7767a945a1d28880a0ef36a6925
data/lib/textveloper.rb CHANGED
@@ -29,7 +29,7 @@ module Textveloper
29
29
  :telefono => format_phone(number),
30
30
  :mensaje => message
31
31
  }
32
- return Curl.post(url + api_actions[:enviar] + '/', data ).body_str
32
+ return Curl.post(url + api_actions[:enviar] + '/', data )
33
33
  end
34
34
 
35
35
  #Servicio SMS
@@ -81,23 +81,23 @@ module Textveloper
81
81
  end
82
82
 
83
83
  def account_balance
84
- hash_contructor(Curl.post(url + api_actions[:puntos_cuenta] + '/', account_data).body_str)
84
+ hash_contructor(Curl.post(url + api_actions[:puntos_cuenta] + '/', account_data))
85
85
  end
86
86
 
87
87
  def buy_history
88
- hash_contructor(Curl.post(url + api_actions[:compras] + '/', account_data).body_str)
88
+ hash_contructor(Curl.post(url + api_actions[:compras] + '/', account_data))
89
89
  end
90
90
 
91
91
  def subaccount_balance
92
- hash_contructor(Curl.post(url + api_actions[:puntos_subcuenta] + '/', transactional_data).body_str)
92
+ hash_contructor(Curl.post(url + api_actions[:puntos_subcuenta] + '/', transactional_data))
93
93
  end
94
94
 
95
95
  def account_history
96
- hash_contructor(Curl.post(url + api_actions[:envios] + '/',transactional_data).body_str)
96
+ hash_contructor(Curl.post(url + api_actions[:envios] + '/',transactional_data))
97
97
  end
98
98
 
99
99
  def transfer_history
100
- hash_contructor(Curl.post(url + api_actions[:transferencias] + '/',transactional_data).body_str)
100
+ hash_contructor(Curl.post(url + api_actions[:transferencias] + '/',transactional_data))
101
101
  end
102
102
 
103
103
  #metodos de formato de data
@@ -114,14 +114,22 @@ module Textveloper
114
114
  data
115
115
  end
116
116
 
117
- private
117
+ #private
118
118
 
119
119
  def format_phone(phone_number)
120
120
  phone_number.nil? ? "" : phone_number.gsub(/\W/,"").sub(/^58/,"").sub(/(^4)/, '0\1')
121
121
  end
122
122
 
123
+ def valid_content_types
124
+ ["application/json", "application/x-javascript", "text/javascript", "text/x-javascript", "text/x-json"]
125
+ end
126
+
123
127
  def hash_contructor(response)
124
- JSON.parse(response)
128
+ if valid_content_types.any? { |type| response.content_type.match(type) }
129
+ JSON.parse(response.body_str)
130
+ else
131
+ {"transaccion"=>"error", "mensaje_transaccion"=>"ERROR_EN_SERVICIO"}
132
+ end
125
133
  end
126
134
 
127
135
  def chunck_message(message)
@@ -1,3 +1,3 @@
1
1
  module Textveloper
2
- VERSION = "0.1.6"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -18,42 +18,72 @@ describe Textveloper do
18
18
  it "consulta de puntos" do
19
19
  stub_request(:post, "http://api.textveloper.com/saldo-subcuenta/").
20
20
  with(:body => "cuenta_token=account_token&subcuenta_token=subaccount_token").
21
- to_return(:status => 200, :body => points, :headers => {})
22
- notificator.subaccount_balance.should == hash_response_points
21
+ to_return(:status => 200, :body => points, :headers => {"Content-Type" => "application/json"})
22
+ notificator.subaccount_balance.should == hash_response_points
23
+ end
24
+
25
+ it 'Api no responde sin envía algo distinto a JSON' do
26
+ stub_request(:post, "http://api.textveloper.com/enviar/").
27
+ with(:body => "cuenta_token=account_token&subcuenta_token=subaccount_token&telefono=04121234567&mensaje=Enviado+desde+textveloper+plataform").
28
+ to_return(:status => 200, :body => "<html><head></head><body><h1>To Many Request</h1></body></html>", :headers => {"Content-Type" => "application/html"})
29
+ notificator.send_sms("04121234567", mensaje).should == {:"04121234567"=>{"transaccion"=>"error", "mensaje_transaccion"=>"ERROR_EN_SERVICIO"}}
23
30
  end
24
31
 
25
32
 
26
33
  it 'envio de mensaje simple' do
27
34
  stub_request(:post, "http://api.textveloper.com/enviar/").
28
35
  with(:body => "cuenta_token=account_token&subcuenta_token=subaccount_token&telefono=04121234567&mensaje=Enviado+desde+textveloper+plataform").
29
- to_return(:status => 200, :body => response, :headers => {})
36
+ to_return(:status => 200, :body => response, :headers => {"Content-Type" => "application/json"})
30
37
 
31
38
  notificator.send_sms("04121234567",mensaje).should == {:"04121234567"=>hash_response}
32
- end
39
+ end
33
40
 
34
41
  it 'envio masivo de mensajes' do
35
42
  tel_numbers.each do |number|
36
43
  stub_request(:post, "http://api.textveloper.com/enviar/").
37
44
  with(:body => "cuenta_token=account_token&subcuenta_token=subaccount_token&telefono=#{number}&mensaje=Enviado+desde+textveloper+plataform").
38
- to_return(:status => 200, :body => response, :headers => {})
39
- end
45
+ to_return(:status => 200, :body => response, :headers => {"Content-Type" => "application/json"})
46
+ end
40
47
  notificator.mass_messages(tel_numbers,mensaje).should == {:"04147890123"=>hash_response, :"04141234567"=>hash_response, :"04161234567"=>hash_response}
41
48
  end
42
49
 
43
50
  context "asociacion de numeros de telefono con data recibida" do
44
51
  let(:numero){["04146578904"]}
45
52
  let(:numeros){["04147890123","04141234567"]}
46
-
53
+
54
+
47
55
  it "un telefono" do
48
- notificator.hash_constructor_with_numbers(numero,[response]).should == {:"04146578904"=>hash_response}
56
+ responses = []
57
+ numero.each do |number|
58
+ stub_request(:post, "http://api.textveloper.com/enviar/").
59
+ with(:body => "cuenta_token=account_token&subcuenta_token=subaccount_token&telefono=#{number}&mensaje=Enviado+desde+textveloper+plataform").
60
+ to_return(:status => 200, :body => response, :headers => {"Content-Type" => "application/json"})
61
+ responses << notificator.core_operation(number, mensaje)
62
+ end
63
+ notificator.hash_constructor_with_numbers(numero,responses).should == {:"04146578904"=>hash_response}
49
64
  end
50
65
 
51
- it "varios numeros" do
52
- notificator.hash_constructor_with_numbers(numeros,[response,response]).should == {:"04147890123"=>hash_response,:"04141234567"=>hash_response}
66
+ it "varios numeros" do
67
+ responses = []
68
+ numeros.each do |number|
69
+ stub_request(:post, "http://api.textveloper.com/enviar/").
70
+ with(:body => "cuenta_token=account_token&subcuenta_token=subaccount_token&telefono=#{number}&mensaje=Enviado+desde+textveloper+plataform").
71
+ to_return(:status => 200, :body => response, :headers => {"Content-Type" => "application/json"})
72
+ responses << notificator.core_operation(number, mensaje)
73
+ end
74
+ notificator.hash_constructor_with_numbers(numeros,responses).should == {:"04147890123"=>hash_response,:"04141234567"=>hash_response}
53
75
  end
54
76
 
55
77
  end
56
78
 
79
+ it "Error en servicio, respuesta del firewall formato HTML" do
80
+ stub_request(:post, "http://api.textveloper.com/enviar/").
81
+ with(:body => "cuenta_token=account_token&subcuenta_token=subaccount_token&telefono=04121234567&mensaje=Enviado+desde+textveloper+plataform").
82
+ to_return(:status => 200, :body => "<html><head></head><body><h1>To Many Request</h1></body></html>", :headers => {"Content-Type" => "application/html"})
83
+ response = notificator.core_operation("04121234567", mensaje)
84
+ notificator.send(:hash_contructor, response).should == {"transaccion"=>"error", "mensaje_transaccion"=>"ERROR_EN_SERVICIO"}
85
+ end
86
+
57
87
  it "formatear el numero de telefono a la forma 04xxxxxxxx" do
58
88
  notificator.send(:format_phone,"+584121234567").should eq("04121234567")
59
89
  notificator.send(:format_phone,"+58-412.123.45.67").should eq("04121234567")
@@ -67,7 +97,11 @@ describe Textveloper do
67
97
  end
68
98
 
69
99
  it "formatear response a hash " do
70
- notificator.send(:hash_contructor,points).should eq(hash_response_points)
100
+ stub_request(:post, "http://api.textveloper.com/enviar/").
101
+ with(:body => "cuenta_token=account_token&subcuenta_token=subaccount_token&telefono=04121234567&mensaje=Enviado+desde+textveloper+plataform").
102
+ to_return(:status => 200, :body => response, :headers => {"Content-Type" => "application/json"})
103
+ rspn = notificator.core_operation("04121234567", mensaje)
104
+ notificator.send(:hash_contructor,rspn).should eq(hash_response)
71
105
  end
72
106
 
73
107
  it "Divisor de mensajes" do
@@ -79,4 +113,4 @@ describe Textveloper do
79
113
  end
80
114
 
81
115
 
82
- end
116
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,4 @@
1
1
  require 'textveloper'
2
- require 'webmock/rspec'
2
+ require 'webmock/rspec'
3
+ require 'curb'
4
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: textveloper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gustavo Gimenez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-27 00:00:00.000000000 Z
11
+ date: 2016-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curb
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  requirements: []
135
135
  rubyforge_project:
136
- rubygems_version: 2.3.0
136
+ rubygems_version: 2.4.6
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: Gema para el envío de sms en Venezuela a tráves del servicio de Textveloper