wire2air 0.3.0 → 0.3.1

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.
Files changed (5) hide show
  1. data/VERSION +1 -1
  2. data/lib/wire2air.rb +27 -21
  3. data/manual_tests.rb +7 -5
  4. data/wire2air.gemspec +2 -2
  5. metadata +12 -12
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
data/lib/wire2air.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  require 'net/http'
2
2
  require 'uri'
3
3
 
4
- # Class for interacting with the TxtImpact sms sending and receiving service.
4
+ # Class for interacting with the Wire2Air sms sending and receiving service.
5
5
  # Example usage:
6
- # connection = TxtImpact.new(:username => 'your_username',
6
+ # connection = Wire2Air.new(:username => 'your_username',
7
7
  # :password => 'your password',
8
8
  # :profile_id => 42,
9
- # :short_code => 1111,
9
+ # :from => 1111,
10
10
  # :vasid => 12345)
11
11
  # connection.submit_sm()
12
12
  class Wire2Air
@@ -31,7 +31,7 @@ class Wire2Air
31
31
  end
32
32
 
33
33
 
34
- # Initializes a TxtImpact object with the common profile info needed
34
+ # Initializes a Wire2Air object with the common profile info needed
35
35
  # for making connections.
36
36
  # @param [Hash] opts The profile connection options
37
37
  # @option opts [String] :username The user name to connect as
@@ -56,10 +56,10 @@ class Wire2Air
56
56
 
57
57
  public
58
58
  # sends an sms
59
- # @param [String, Array<String>] to_number DESTINATION MOBILE NUMBER. [(country
59
+ # @param [String, Array<String>] mobile_number DESTINATION MOBILE NUMBER. [(country
60
60
  # code) + mobile number] e.g 17321234567 (for
61
61
  # US), 919810601000 (for India)
62
- # @param [String] short_code The short code number
62
+ # @param [String] from The short code number
63
63
  # @param [String] text The message text
64
64
  # @param [Hash] opts Extra optional settings
65
65
  # @option opts [String] :batch_reference A reference string used when sending many sms
@@ -69,24 +69,22 @@ class Wire2Air
69
69
  # an Integer for the BatchID is returned.
70
70
  # @raise NotEnoughError Not enough credits to send the sms
71
71
  # @raise FailedAuthenticationError some authentication details are wrong
72
- def submit_sm(short_code, to_number, text, opts = {})
72
+ def submit_sm(from, mobile_number, text, opts = {})
73
73
  params = common_options
74
74
  params['VERSION'] = '2.0'
75
- params['FROM'] = short_code
75
+ params['FROM'] = from
76
76
  params['TEXT'] = text
77
77
  params['NETWORKID'] = opts[:network_id] if opts.has_key? :network_id
78
- batch_send = !(to_number.is_a? String)
78
+ batch_send = !(mobile_number.is_a? String)
79
79
 
80
80
  if !batch_send
81
- params['TO'] = to_number
81
+ params['TO'] = mobile_number
82
82
  else
83
- params['TO'] = to_number.join(',')
83
+ params['TO'] = mobile_number.join(',')
84
84
  params['BATCHNAME'] = opts[:batch_reference]
85
85
 
86
86
  end
87
87
 
88
- p params
89
-
90
88
  url = URI.parse('http://smsapi.wire2air.com/smsadmin/submitsm.aspx')
91
89
  res = Net::HTTP.post_form(url, params).body
92
90
  case res
@@ -138,7 +136,7 @@ class Wire2Air
138
136
  'PASSWORD' => password,
139
137
  'VASID' => vasid
140
138
  }).body
141
- raise FailedAuthenticationError if res =~ /ERR: 301/
139
+ raise FailedAuthenticationError if res =~ /ERR:301/
142
140
  res.to_i
143
141
  end
144
142
 
@@ -152,14 +150,20 @@ class Wire2Air
152
150
  'USERID' => userid,
153
151
  'PASSWORD' => password,
154
152
  'VASID' => vasid,
155
- 'SHORTCODEID' => short_code,
153
+ 'SHORTCODE' => short_code,
156
154
  'KEYWORD' => keyword
157
155
  })
158
156
 
159
- puts response.body
160
-
161
- response.body.include? "Err:0:"
162
-
157
+ case response.body
158
+ when /Err:0/
159
+ return true
160
+ when /Err:705/
161
+ return false
162
+ when /Err:301/
163
+ raise FailedAuthenticationError
164
+ else
165
+ raise StandardError.new response.body
166
+ end
163
167
 
164
168
  end
165
169
 
@@ -168,7 +172,7 @@ class Wire2Air
168
172
  # for a given short code.
169
173
  # @param opts Options for creating the keyword
170
174
  # @option opts [String] :service_name Service name for the keyword
171
- # @option opts [String] :short_code_id
175
+ # @option opts [String] :short_code
172
176
  # @option opts [String] :keyword
173
177
  # @option opts [String] :processor_url The url of the webservice
174
178
  # @option opts [String] :help_msg Response for help message
@@ -185,7 +189,7 @@ class Wire2Air
185
189
  params['USERID'] = username
186
190
  params['PASSWORD'] = password
187
191
  params['VASID'] = vasid
188
- params['SHORTCODE'] = opts[:short_code_id]
192
+ params['SHORTCODE'] = opts[:short_code]
189
193
  params['SERVICENAME'] = opts[:service_name]
190
194
  params['KEYWORD'] = opts[:keyword]
191
195
  params['PROCESSORURL'] = opts[:processor_url]
@@ -199,6 +203,8 @@ class Wire2Air
199
203
  case res
200
204
  when /Err:70[012346789]/, /Err:71[0134]/
201
205
  raise ArgumentError.new res
206
+ when /Err:300/
207
+ raise FailedAuthenticationError
202
208
  when /Err:705/
203
209
  raise KeywordIsTakenError
204
210
  when /Err:712/
data/manual_tests.rb CHANGED
@@ -71,12 +71,16 @@ describe "sms api" do
71
71
  end
72
72
  end
73
73
 
74
+ it 'can check the number of available credits' do
75
+ credits = connection.check_sms_credits
76
+ true_false_prompt("Are there #{credits} number of sms credits available?").should be_true
77
+ end
74
78
 
75
79
  it 'can add more credits to the account' do
76
- current_credits = prompt "Enter the number of available credits currently: "
80
+ current_credits = prompt "Enter the number of available keyword credits currently: "
77
81
 
78
82
  puts connection.subscribe_keywords(4)
79
- true_false_prompt("Are there now #{current_credits.to_i + 4} credits available?").should be_true
83
+ true_false_prompt("Are there now #{current_credits.to_i + 4} keyword credits available?").should be_true
80
84
  end
81
85
 
82
86
  it 'can find if a keyword is available' do
@@ -88,7 +92,7 @@ describe "sms api" do
88
92
  service_keyword = 'new_keyword'
89
93
  service_id = connection.register_keyword(
90
94
  :service_name => service_name,
91
- :short_code_id => opts[:short_code],
95
+ :short_code => opts[:short_code],
92
96
  :keyword => service_keyword,
93
97
  :processor_url => 'http://example.com/processor',
94
98
  :help_msg => "help message",
@@ -96,8 +100,6 @@ describe "sms api" do
96
100
  )
97
101
 
98
102
  true_false_prompt("Did a new service get registered with name '#{service_name}'").should be_true
99
- connection.delete_service(opts[:short_code], service_id, service_keyword)
100
- true_false_prompt("Did the service '#{service_name}' get deleted?").should be_true
101
103
 
102
104
 
103
105
  end
data/wire2air.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{wire2air}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{David Miani}]
12
- s.date = %q{2011-09-06}
12
+ s.date = %q{2011-09-08}
13
13
  s.description = %q{Allows sending sms and voice messages, checking and adding more credits, subscribing to keywords}
14
14
  s.email = %q{davidmiani@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wire2air
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-06 00:00:00.000000000Z
12
+ date: 2011-09-08 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2153620960 !ruby/object:Gem::Requirement
16
+ requirement: &2153338800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.3.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2153620960
24
+ version_requirements: *2153338800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yard
27
- requirement: &2153636860 !ruby/object:Gem::Requirement
27
+ requirement: &2153338320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.6.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2153636860
35
+ version_requirements: *2153338320
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &2153636380 !ruby/object:Gem::Requirement
38
+ requirement: &2153337840 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2153636380
46
+ version_requirements: *2153337840
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &2153635900 !ruby/object:Gem::Requirement
49
+ requirement: &2153337360 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2153635900
57
+ version_requirements: *2153337360
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &2153635420 !ruby/object:Gem::Requirement
60
+ requirement: &2153336880 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2153635420
68
+ version_requirements: *2153336880
69
69
  description: Allows sending sms and voice messages, checking and adding more credits,
70
70
  subscribing to keywords
71
71
  email: davidmiani@gmail.com