vianettsms 0.0.2 → 0.0.3

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.
@@ -16,15 +16,8 @@ module Vianettsms
16
16
  end
17
17
 
18
18
  def deliver
19
- params = {
20
- :username => Vianettsms.config[:username],
21
- :password => Vianettsms.config[:password],
22
- :tel => @to || "",
23
- :msg => @message || "",
24
- :msgid => @msgid || ""
25
- }
26
- if valid?(params)
27
- handle_response(params)
19
+ if valid?
20
+ handle_response(Net::HTTP.post_form(URI.parse(Vianettsms.url), params_hash))
28
21
  end
29
22
  delivered?
30
23
  end
@@ -33,17 +26,29 @@ module Vianettsms
33
26
  @delivered
34
27
  end
35
28
 
29
+ def valid?
30
+ raise(ArgumentError, ":to is required") if @to.nil? or @to.empty?
31
+ raise(ArgumentError, ":message is required") if @message.nil? or @message.empty?
32
+ raise(ArgumentError, ":msgid is required") if @msgid.nil? or @msgid.empty?
33
+ not (@to.nil? or @to.empty? or @message.nil? or @message.empty? or @msgid.nil? or @msgid.empty?)
34
+ end
35
+
36
36
  private
37
37
 
38
38
  attr_accessor :response
39
39
 
40
- def valid?(params)
41
- not (params[:tel].empty? or params[:msg].empty? or params[:msgid].empty?)
40
+ def params_hash
41
+ {
42
+ :username => Vianettsms.config[:username],
43
+ :password => Vianettsms.config[:password],
44
+ :tel => @to || "",
45
+ :msg => @message || "",
46
+ :msgid => @msgid || ""
47
+ }
42
48
  end
43
49
 
44
- def handle_response(params)
45
- uri = URI.parse(Vianettsms.url)
46
- @response = Net::HTTP.post_form(uri, params)
50
+ def handle_response(response)
51
+ @response = response
47
52
  unless @response.nil?
48
53
  @response_hash = XmlSimple.xml_in(@response.body)
49
54
  @status = @response_hash['errorcode']
@@ -1,3 +1,3 @@
1
1
  module Vianettsms
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -2,8 +2,6 @@ require 'spec_helper.rb'
2
2
 
3
3
  describe Vianettsms::Sms, "#deliver", :vianettsms => true do
4
4
 
5
- puts "============ VIANETTSMS IS ENABLED ================"
6
-
7
5
  let(:valid_config) { { :username => 'diego@maradona.com.ar',
8
6
  :password => 'eldie10' } }
9
7
 
@@ -33,59 +31,6 @@ describe Vianettsms::Sms, "#deliver", :vianettsms => true do
33
31
  end
34
32
  end
35
33
 
36
- context "without params" do
37
-
38
- let(:sms) {
39
- sms = Vianettsms::Sms.new({})
40
- sms.deliver
41
- sms
42
- }
43
-
44
- it "should return errorcode 1000 (Message ID required)" do
45
- sms.status.should == "1000"
46
- end
47
- end
48
-
49
- context "when msgid not sent" do
50
-
51
- let(:params) do {
52
- :msgid => '',
53
- :to => '4711111111',
54
- :message => 'Hello World' }
55
- end
56
-
57
- let(:sms) {
58
- sms = Vianettsms::Sms.new(params)
59
- sms.deliver
60
- sms
61
- }
62
-
63
- it "should return errorcode 1000 (Message ID required)" do
64
- sms.status.should == "1000"
65
- end
66
-
67
- end
68
-
69
- context "when phone number is empty" do
70
-
71
- let(:params) do {
72
- :msgid => '1234',
73
- :to => '',
74
- :message => 'Hello World' }
75
- end
76
-
77
- let(:sms) {
78
- sms = Vianettsms::Sms.new(params)
79
- sms.deliver
80
- sms
81
- }
82
-
83
-
84
- it "should return errorcode 105 (No recipients specified or invalid recipient value)" do
85
- sms.status.should == "105"
86
- end
87
-
88
- end
89
34
  end
90
35
 
91
36
  context "with invalid configuration" do
@@ -4,7 +4,12 @@ require 'webmock/rspec'
4
4
  WebMock.allow_net_connect!
5
5
 
6
6
  ::VIANETTSMS_ENABLED = ENV["VIANETSMS_ENABLED"] == "true" #DISABLED BY DEFAULT
7
- puts "============ VIANETTSMS IS DISABLED ================" unless ::VIANETTSMS_ENABLED
7
+
8
+ if ::VIANETTSMS_ENABLED
9
+ puts "============ VIANETTSMS HTTP API IS ENABLED ================"
10
+ else
11
+ puts "============ VIANETTSMS HTTP API IS DISABLED ================"
12
+ end
8
13
 
9
14
  RSpec.configure do |c|
10
15
  c.filter_run_excluding :vianettsms => true unless ::VIANETTSMS_ENABLED
@@ -58,5 +58,71 @@ describe Vianettsms::Sms, "#deliver" do
58
58
 
59
59
  end
60
60
 
61
+ context "Without msgid" do
62
+
63
+ before { Vianettsms.config = valid_config }
64
+
65
+ let(:params) do {
66
+ :msgid => '',
67
+ :to => '4711111111',
68
+ :message => 'Hello World' }
69
+ end
70
+
71
+ let(:sms) {
72
+ sms = Vianettsms::Sms.new(params)
73
+ sms.deliver
74
+ sms
75
+ }
76
+
77
+ it "should raise ArgumentError exception" do
78
+ expect{ sms.valid? }.to raise_error(ArgumentError)
79
+ end
80
+
81
+ end
82
+
83
+ context "Without message" do
84
+
85
+ before { Vianettsms.config = valid_config }
86
+
87
+ let(:params) do {
88
+ :msgid => '1234',
89
+ :to => '4711111111',
90
+ :message => '' }
91
+ end
92
+
93
+ let(:sms) {
94
+ sms = Vianettsms::Sms.new(params)
95
+ sms.deliver
96
+ sms
97
+ }
98
+
99
+ it "should raise ArgumentError exception" do
100
+ expect{ sms.valid? }.to raise_error(ArgumentError)
101
+ end
102
+
103
+ end
104
+
105
+ context "Without to" do
106
+
107
+ before { Vianettsms.config = valid_config }
108
+
109
+ let(:params) do {
110
+ :msgid => '1234',
111
+ :to => nil,
112
+ :message => 'Hello World' }
113
+ end
114
+
115
+ let(:sms) {
116
+ sms = Vianettsms::Sms.new(params)
117
+ sms.deliver
118
+ sms
119
+ }
120
+
121
+ it "should raise ArgumentError exception" do
122
+ expect{ sms.valid? }.to raise_error(ArgumentError)
123
+ end
124
+
125
+ end
126
+
61
127
  end
62
128
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vianettsms
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Juan Pablo Taulamet
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-12-26 00:00:00 Z
18
+ date: 2012-12-27 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec