wire2air 0.1.0 → 0.2.2

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.
data/Gemfile CHANGED
@@ -14,5 +14,6 @@ group :development do
14
14
  end
15
15
 
16
16
  group :test do
17
+
17
18
  gem "trollop"
18
19
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.2
data/lib/wire2air.rb CHANGED
@@ -37,12 +37,10 @@ class Wire2Air
37
37
  # @option opts [String] :username The user name to connect as
38
38
  # @option opts [String] :password The password (in plain text) for connecting
39
39
  # @option opts [Integer] :profile_id The id of the profile
40
- # @options opts [Integer] :short_code The short code for the account
41
40
  # @options opts [Integer] :vasid The vasid of the account
42
41
  def initialize(opts)
43
- valid_keys =[:username, :password, :profile_id, :short_code, :vasid]
42
+ valid_keys =[:username, :password, :profile_id, :vasid]
44
43
  if opts.keys.sort != valid_keys.sort
45
- puts opts.keys
46
44
  raise ArgumentError.new "The options must only have the keys #{valid_keys}"
47
45
  end
48
46
 
@@ -52,7 +50,7 @@ class Wire2Air
52
50
 
53
51
  end
54
52
 
55
- attr_reader :username, :password, :vasid, :profile_id, :short_code
53
+ attr_reader :username, :password, :vasid, :profile_id
56
54
 
57
55
  alias :userid :username
58
56
 
@@ -61,26 +59,30 @@ class Wire2Air
61
59
  # @param [String, Array<String>] to_number DESTINATION MOBILE NUMBER. [(country
62
60
  # code) + mobile number] e.g 17321234567 (for
63
61
  # US), 919810601000 (for India)
62
+ # @param [String] short_code The short code number
64
63
  # @param [String] text The message text
65
- # @param [String] batch_reference If sending to multiple numbers, is used to identify
66
- # the send request used in reports
64
+ # @param [Hash] opts Extra optional settings
65
+ # @option opts [String] :batch_reference A reference string used when sending many sms
66
+ # @option opts [String] :network_id Th id of the destination network. This is the same as
67
+ # what is passed from incoming sms message for the HTTP API.
67
68
  # @return [JobId, Integer] If a single sms is being sent, a JobId is returned. Otherwise
68
69
  # an Integer for the BatchID is returned.
69
70
  # @raise NotEnoughError Not enough credits to send the sms
70
71
  # @raise FailedAuthenticationError some authentication details are wrong
71
- def send_sms(to_number, text, batch_reference = "batched send")
72
+ def submit_sm(short_code, to_number, text, opts = {})
72
73
  params = common_options
73
74
  params['VERSION'] = '2.0'
74
75
  params['FROM'] = short_code
75
76
  params['TEXT'] = text
76
-
77
+ params['NETWORKID'] = opts[:network_id] if opts.has_key? :network_id
77
78
  batch_send = !(to_number.is_a? String)
78
79
 
79
80
  if !batch_send
80
81
  params['TO'] = to_number
81
82
  else
82
83
  params['TO'] = to_number.join(',')
83
- params['BATCHNAME'] = batch_reference
84
+ params['BATCHNAME'] = opts[:batch_reference]
85
+
84
86
  end
85
87
 
86
88
  p params
@@ -104,7 +106,7 @@ class Wire2Air
104
106
  # Adds some credits to the account
105
107
  # @param [Integer] keyword_credits The number of credits to add
106
108
  # @return [void]
107
- def subscribe_credits(keyword_credits = 1)
109
+ def subscribe_keywords(keyword_credits = 1)
108
110
  url = URI.parse('http://mzone.wire2air.com/mserver/api/subscribekeywords.aspx')
109
111
  res = Net::HTTP.post_form(url, {
110
112
  'USERID' => userid,
@@ -129,7 +131,7 @@ class Wire2Air
129
131
 
130
132
  # returns the number of credits available
131
133
  # @return Integer the number of credits available
132
- def credit_count
134
+ def check_sms_credits
133
135
  url = URI.parse('http://smsapi.wire2air.com/smsadmin/checksmscredits.aspx')
134
136
  res = Net::HTTP.post_form(url, {
135
137
  'USERID' => userid,
@@ -141,8 +143,10 @@ class Wire2Air
141
143
  end
142
144
 
143
145
  # Checks whether the keyword can be registered.
146
+ # @param [String] short_code The short code id
147
+ # @param [String] keyword The keyword to search for
144
148
  # @return Boolean true if the keyword is available
145
- def is_keyword_available?(keyword)
149
+ def check_keyword(short_code, keyword)
146
150
  url = URI.parse('http://mzone.wire2air.com/shortcodemanager/api/checkkeywordapi.aspx')
147
151
  response = Net::HTTP.post_form(url, {
148
152
  'USERID' => userid,
@@ -152,6 +156,8 @@ class Wire2Air
152
156
  'KEYWORD' => keyword
153
157
  })
154
158
 
159
+ puts response.body
160
+
155
161
  response.body.include? "Err:0:"
156
162
 
157
163
 
@@ -161,6 +167,7 @@ class Wire2Air
161
167
  # registers a keyword
162
168
  # @param opts Options for creating the keyword
163
169
  # @option opts [String] :service_name Service name for the keyword
170
+ # @option opts [String] :short_code_id
164
171
  # @option opts [String] :keyword
165
172
  # @option opts [String] :processor_url The url of the webserice
166
173
  # @option opts [String] :help_msg Response for help message
@@ -170,8 +177,11 @@ class Wire2Air
170
177
  # @raise KeywordIsTakenError
171
178
  def register_keyword(opts)
172
179
  url = URI.parse('http://mzone.wire2air.com/shortcodemanager/api/RegisterKeywordAPI.aspx')
173
- params = common_options
174
- params['SHORTCODEID'] = short_code
180
+ params = {}
181
+ params['USERID'] = username
182
+ params['PASSWORD'] = password
183
+ params['VASID'] = vasid
184
+ params['SHORTCODE'] = opts[:short_code_id]
175
185
  params['SERVICENAME'] = opts[:service_name]
176
186
  params['KEYWORD'] = opts[:keyword]
177
187
  params['PROCESSORURL'] = opts[:processor_url]
@@ -180,6 +190,7 @@ class Wire2Air
180
190
  params['ACTION'] = 'ADD'
181
191
 
182
192
  res = Net::HTTP.post_form(url, params).body
193
+ puts res
183
194
 
184
195
  case res
185
196
  when /Err:70[012346789]/, /Err:71[0134]/
@@ -197,11 +208,13 @@ class Wire2Air
197
208
  # deletes a service created with register_keyword.
198
209
  # @param [Integer] service_id The id of the service to delete
199
210
  # @param [String] keyword the keyword for the service
200
- def delete_service(service_id, keyword)
211
+ def delete_service(short_code_id, service_id, keyword)
201
212
  url = URI.parse('http://mzone.wire2air.com/shortcodemanager/api/RegisterKeywordAPI.aspx')
202
- params = common_options
203
- params.delete 'PROFILEID'
204
- params['SHORTCODEID'] = short_code
213
+ params = {}
214
+ params['USERID'] = username
215
+ params['PASSWORD'] = password
216
+ params['VASID'] = vasid
217
+ params['SHORTCODE'] = short_code_id
205
218
  params['SERVICEID'] = service_id.to_s
206
219
  params['KEYWORD'] = keyword
207
220
  params['ACTION'] = 'DELETE'
data/manual_tests.rb CHANGED
@@ -1,10 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
+ # Usage: Run this script passing in parameters for --username, --password,
4
+ # --profile-id, --short-code, --vasid, --test-number
5
+ # It will then prompt for information and test using that
6
+ # eg ruby manual_tests.rb --username some_username --password some_password --profile-id 42 --short-code 3 --vasid 34 --test-number 12345677
3
7
 
4
- require 'bundler/setup'
8
+ require 'rubygems'
5
9
  require 'trollop'
6
- require './lib/wire2air'
10
+ require 'wire2air'
7
11
  require 'rspec'
12
+ require 'rspec/autorun'
8
13
 
9
14
 
10
15
  def prompt(string)
@@ -40,7 +45,7 @@ opts = Trollop::options do
40
45
  opt :username, "The username to log in as", :type => :string, :required => true
41
46
  opt :password, "The password to log in as", :type => :string, :required => true
42
47
  opt :profile_id, "The profile_id to log in as", :type => :string, :required => true
43
- opt :short_code, "The short_code to log in as", :type => :string, :required => true
48
+ opt :short_code, "The short_code to use in tests", :type => :string, :required => true
44
49
  opt :vasid, "The vasid to log in as", :type => :string, :required => true
45
50
  opt :test_number, "The mobile number to test with", :type => :string, :required => true
46
51
 
@@ -52,8 +57,7 @@ end
52
57
  connection_opts = opts.dup
53
58
 
54
59
  connection_opts = { :username => opts[:username], :password => opts[:password],
55
- :profile_id => opts[:profile_id], :short_code => opts[:short_code],
56
- :vasid => opts[:vasid]
60
+ :profile_id => opts[:profile_id], :vasid => opts[:vasid]
57
61
  }
58
62
  connection = Wire2Air.new connection_opts
59
63
 
@@ -61,7 +65,7 @@ describe "sms api" do
61
65
  unless opts[:dont_test_sending_sms]
62
66
  it "should send a single sms message" do
63
67
  msg = "test message #{Time.now}"
64
- puts connection.send_sms(opts[:test_number], msg)
68
+ puts connection.submit_sm(opts[:short_code], opts[:test_number], msg)
65
69
 
66
70
  true_false_prompt("Did a message with the text '#{msg}' get sent?").should be_true
67
71
  end
@@ -71,19 +75,20 @@ describe "sms api" do
71
75
  it 'can add more credits to the account' do
72
76
  current_credits = prompt "Enter the number of available credits currently: "
73
77
 
74
- puts connection.subscribe_credits(4)
78
+ puts connection.subscribe_keywords(4)
75
79
  true_false_prompt("Are there now #{current_credits.to_i + 4} credits available?").should be_true
76
80
  end
77
81
 
78
82
  it 'can find if a keyword is available' do
79
- connection.is_keyword_available?("testing_keyword_34551").should be_true
83
+ connection.check_keyword(opts[:short_code], "testing_keyword_34551").should be_true
80
84
  end
81
85
 
82
86
  it "can register a keyword and unregister a keyword" do
83
- service_name = "A service name"
84
- service_keyword = 'testing_keyword'
87
+ service_name = "New service"
88
+ service_keyword = 'new_keyword'
85
89
  service_id = connection.register_keyword(
86
90
  :service_name => service_name,
91
+ :short_code_id => opts[:short_code],
87
92
  :keyword => service_keyword,
88
93
  :processor_url => 'http://example.com/processor',
89
94
  :help_msg => "help message",
@@ -91,7 +96,7 @@ describe "sms api" do
91
96
  )
92
97
 
93
98
  true_false_prompt("Did a new service get registered with name '#{service_name}'").should be_true
94
- connection.delete_service(service_id, service_keyword)
99
+ connection.delete_service(opts[:short_code], service_id, service_keyword)
95
100
  true_false_prompt("Did the service '#{service_name}' get deleted?").should be_true
96
101
 
97
102
 
@@ -104,4 +109,3 @@ end
104
109
 
105
110
 
106
111
 
107
-
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.1.0"
8
+ s.version = "0.2.2"
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-08-20}
12
+ s.date = %q{2011-09-06}
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 = [
@@ -20,7 +20,6 @@ Gem::Specification.new do |s|
20
20
  ".document",
21
21
  ".rspec",
22
22
  "Gemfile",
23
- "Gemfile.lock",
24
23
  "LICENSE.txt",
25
24
  "README.rdoc",
26
25
  "Rakefile",
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.1.0
4
+ version: 0.2.2
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-08-20 00:00:00.000000000Z
12
+ date: 2011-09-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2165590560 !ruby/object:Gem::Requirement
16
+ requirement: &2153296680 !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: *2165590560
24
+ version_requirements: *2153296680
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yard
27
- requirement: &2165590080 !ruby/object:Gem::Requirement
27
+ requirement: &2153296200 !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: *2165590080
35
+ version_requirements: *2153296200
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &2165589600 !ruby/object:Gem::Requirement
38
+ requirement: &2153295720 !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: *2165589600
46
+ version_requirements: *2153295720
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &2165589120 !ruby/object:Gem::Requirement
49
+ requirement: &2153295240 !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: *2165589120
57
+ version_requirements: *2153295240
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &2165588640 !ruby/object:Gem::Requirement
60
+ requirement: &2153294760 !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: *2165588640
68
+ version_requirements: *2153294760
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
@@ -78,7 +78,6 @@ files:
78
78
  - .document
79
79
  - .rspec
80
80
  - Gemfile
81
- - Gemfile.lock
82
81
  - LICENSE.txt
83
82
  - README.rdoc
84
83
  - Rakefile
data/Gemfile.lock DELETED
@@ -1,32 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- diff-lcs (1.1.2)
5
- git (1.2.5)
6
- jeweler (1.6.4)
7
- bundler (~> 1.0)
8
- git (>= 1.2.5)
9
- rake
10
- rake (0.9.2)
11
- rcov (0.9.10)
12
- rspec (2.3.0)
13
- rspec-core (~> 2.3.0)
14
- rspec-expectations (~> 2.3.0)
15
- rspec-mocks (~> 2.3.0)
16
- rspec-core (2.3.1)
17
- rspec-expectations (2.3.0)
18
- diff-lcs (~> 1.1.2)
19
- rspec-mocks (2.3.0)
20
- trollop (1.16.2)
21
- yard (0.6.8)
22
-
23
- PLATFORMS
24
- ruby
25
-
26
- DEPENDENCIES
27
- bundler (~> 1.0.0)
28
- jeweler (~> 1.6.4)
29
- rcov
30
- rspec (~> 2.3.0)
31
- trollop
32
- yard (~> 0.6.0)