textmagic 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,175 +2,223 @@ require 'test_helper'
2
2
 
3
3
  class ResponseTest < Test::Unit::TestCase
4
4
 
5
- context 'Account response' do
5
+ context 'Response to account command' do
6
6
 
7
7
  setup do
8
8
  @balance = 0.1 * rand(1e4)
9
- @response = { 'balance' => @balance.to_s }
10
- @response.extend TextMagic::API::Response::Account
9
+ @hash = { 'balance' => @balance.to_s }
10
+ @response = TextMagic::API::Response.account(@hash)
11
11
  end
12
12
 
13
- should 'allow access to balance' do
13
+ should 'be an OpenStruct instance' do
14
+ @response.class.should == OpenStruct
15
+ end
16
+
17
+ should 'have balance' do
14
18
  @response.balance.should be_close(@balance, 1e-10)
15
19
  end
16
20
  end
17
21
 
18
- context 'Send response' do
22
+ context 'Response to send command with single phone number' do
19
23
 
20
24
  setup do
21
- @message_id = {
22
- '141421' => '999314159265',
23
- '173205' => '999271828182'
24
- }
25
+ @message_id, @phone = random_string, random_phone
25
26
  @text = random_string
26
- @parts_count = rand(10)
27
- @response = {
28
- 'message_id' => @message_id,
29
- 'sent_text' => @text,
30
- 'parts_count' => @parts_count
31
- }
32
- @response.extend TextMagic::API::Response::Send
27
+ @parts_count = 1 + rand(3)
28
+ @hash = { 'message_id' => { @message_id => @phone }, 'sent_text' => @text, 'parts_count' => @parts_count }
29
+ @response = TextMagic::API::Response.send(@hash, true)
30
+ end
31
+
32
+ should 'equal to the message_id' do
33
+ @response.should == @message_id
34
+ end
35
+
36
+ should 'have sent_text' do
37
+ @response.sent_text.should == @text
38
+ end
39
+
40
+ should 'have parts_count' do
41
+ @response.parts_count.should == @parts_count
42
+ end
43
+ end
44
+
45
+ context 'Response to send command with multiple phone numbers' do
46
+
47
+ setup do
48
+ @message_id1, @phone1 = random_string, random_phone
49
+ @message_id2, @phone2 = random_string, random_phone
50
+ @text = random_string
51
+ @parts_count = 1 + rand(3)
52
+ @hash = { 'message_id' => { @message_id1 => @phone1, @message_id2 => @phone2 }, 'sent_text' => @text, 'parts_count' => @parts_count }
53
+ @response = TextMagic::API::Response.send(@hash, false)
54
+ end
55
+
56
+ should 'be a hash' do
57
+ @response.class.should == Hash
33
58
  end
34
59
 
35
- should 'allow access to message_ids array' do
36
- @response.message_ids.should == ['141421', '173205']
60
+ should 'have phone numbers as keys' do
61
+ @response.keys.sort.should == [@phone1, @phone2].sort
37
62
  end
38
63
 
39
- should 'allow access to message_id for a given phone number' do
40
- @response['999314159265'].should == '141421'
41
- @response['999271828182'].should == '173205'
64
+ should 'have message ids as values' do
65
+ @response[@phone1].should == @message_id1
66
+ @response[@phone2].should == @message_id2
42
67
  end
43
68
 
44
- should 'allow access to sent_text' do
69
+ should 'have sent_text' do
45
70
  @response.sent_text.should == @text
46
71
  end
47
72
 
48
- should 'allow access to parts_count' do
73
+ should 'have parts_count' do
49
74
  @response.parts_count.should == @parts_count
50
75
  end
51
76
  end
52
77
 
53
- context 'MessageStatus response' do
78
+ context 'Response to message_status command with single id' do
54
79
 
55
80
  setup do
56
81
  @text = random_string
82
+ @status = random_string
57
83
  @reply_number = random_phone
58
84
  @created_time = (Time.now - 30).to_i
59
85
  @completed_time = (Time.now - 20).to_i
60
86
  @credits_cost = 0.01 * rand(300)
61
- @response = {
87
+ @hash = {
62
88
  '141421' => {
63
89
  'text' => @text,
64
- 'status' => 'd',
65
- 'created_time' => @created_time,
90
+ 'status' => @status,
91
+ 'created_time' => @created_time.to_s,
66
92
  'reply_number' => @reply_number,
67
- 'completed_time' => @completed_time,
93
+ 'completed_time' => @completed_time.to_s,
68
94
  'credits_cost' => @credits_cost
69
- },
70
- '173205' => {
71
- 'text' => 'test',
72
- 'status' => 'r',
73
- 'created_time' => '1242979839',
74
- 'reply_number' => '447624800500',
75
- 'completed_time' => nil,
76
- 'credits_cost' => 0.5
77
95
  }
78
96
  }
79
- @response.extend TextMagic::API::Response::MessageStatus
97
+ @response = TextMagic::API::Response.message_status(@hash, true)
80
98
  end
81
99
 
82
- should 'allow access to text for all statuses' do
83
- @response['141421'].text.should == @text
84
- @response['173205'].text.should == 'test'
100
+ should 'equal to the message status' do
101
+ @response.should == @status
85
102
  end
86
103
 
87
- should 'allow access to status for a given message_id' do
88
- @response['141421'].status.should == 'd'
89
- @response['173205'].status.should == 'r'
104
+ should 'have text' do
105
+ @response.text.should == @text
90
106
  end
91
107
 
92
- should 'allow access to reply_number for a given message_id' do
93
- @response['141421'].reply_number.should == @reply_number
94
- @response['173205'].reply_number.should == '447624800500'
108
+ should 'have created_time' do
109
+ @response.created_time.should == Time.at(@created_time)
95
110
  end
96
111
 
97
- should 'allow access to created_time for a given message_id' do
98
- @response['141421'].created_time.should == Time.at(@created_time)
99
- @response['173205'].created_time.should == Time.at(1242979839)
112
+ should 'have completed_time' do
113
+ @response.completed_time.should == Time.at(@completed_time)
100
114
  end
101
115
 
102
- should 'allow access to completed_time for a given message_id' do
103
- @response['141421'].completed_time.should == Time.at(@completed_time)
104
- @response['173205'].completed_time.should == nil
116
+ should 'have reply_number' do
117
+ @response.reply_number.should == @reply_number
105
118
  end
106
119
 
107
- should 'allow access to credits_cost for a given message_id' do
108
- @response['141421'].credits_cost.should be_close(@credits_cost, 1e-10)
109
- @response['173205'].credits_cost.should be_close(0.5, 1e-10)
120
+ should 'have credits_cost' do
121
+ @response.credits_cost.should be_close(@credits_cost, 1e-10)
110
122
  end
111
123
  end
112
-
113
- context 'Receive response' do
124
+
125
+ context 'Response to message_status command with multiple ids' do
114
126
 
115
127
  setup do
116
- @timestamp = (Time.now - 30).to_i
117
- @message1 = {
118
- 'timestamp' => @timestamp,
119
- 'from' => '999314159265',
120
- 'text' => 'Hi Fred',
121
- 'message_id' => '141421'
122
- }
123
- @message2 = {
124
- 'timestamp' => 1243244148,
125
- 'from' => '999271828182',
126
- 'text' => 'Hello buddy',
127
- 'message_id' => '173205'
128
+ @text = random_string
129
+ @status = random_string
130
+ @reply_number = random_phone
131
+ @created_time = (Time.now - 30).to_i
132
+ @completed_time = (Time.now - 20).to_i
133
+ @credits_cost = 0.01 * rand(300)
134
+ @hash = {
135
+ '141421' => {
136
+ 'text' => @text,
137
+ 'status' => @status,
138
+ 'created_time' => @created_time,
139
+ 'reply_number' => @reply_number,
140
+ 'completed_time' => @completed_time,
141
+ 'credits_cost' => @credits_cost
142
+ }
128
143
  }
129
- @messages = [@message1, @message2]
130
- @unread = rand(1e4)
131
- @response = { 'unread' => @unread, 'messages' => @messages }
132
- @response.extend TextMagic::API::Response::Receive
144
+ @response = TextMagic::API::Response.message_status(@hash, false)
133
145
  end
134
146
 
135
- should 'allow access to unread' do
136
- @response.unread.should == @unread
147
+ should 'be a hash' do
148
+ @response.class.should == Hash
149
+ end
150
+
151
+ should 'have message_ids as keys' do
152
+ @response.keys.should == ['141421']
137
153
  end
138
154
 
139
- should 'allow access to messages array' do
140
- @response.messages.should == @messages
155
+ should 'contain statuses' do
156
+ @response.values.first.should == @status
141
157
  end
142
158
 
143
- should 'allow access to message_ids array' do
144
- @response.message_ids.should == ['141421', '173205']
159
+ should 'have text for all statuses' do
160
+ @response.values.first.text.should == @text
145
161
  end
146
162
 
147
- should 'allow access to message_id for all messages' do
148
- @response.messages.first.message_id.should == '141421'
163
+ should 'have created_time for all statuses' do
164
+ @response.values.first.created_time.should == Time.at(@created_time)
149
165
  end
150
166
 
151
- should 'allow access to timestamp for all messages' do
152
- @response.messages.first.timestamp.should == Time.at(@timestamp)
167
+ should 'have completed_time for all statuses' do
168
+ @response.values.first.completed_time.should == Time.at(@completed_time)
153
169
  end
154
170
 
155
- should 'allow access to from for all messages' do
156
- @response.messages.first.from.should == '999314159265'
171
+ should 'have reply_number for all statuses' do
172
+ @response.values.first.reply_number.should == @reply_number
157
173
  end
158
174
 
159
- should 'allow access to text for all messages' do
160
- @response.messages.first.text.should == 'Hi Fred'
175
+ should 'have credits_cost for all statuses' do
176
+ @response.values.first.credits_cost.should be_close(@credits_cost, 1e-10)
161
177
  end
162
178
  end
163
179
 
164
- context 'DeleteReply response' do
180
+ context 'Response to receive command' do
165
181
 
166
182
  setup do
167
- @ids = ['141421', '1780826']
168
- @response = { 'deleted' => @ids }
169
- @response.extend TextMagic::API::Response::DeleteReply
183
+ @timestamp = (Time.now - 30).to_i
184
+ @text, @phone, @message_id = random_string, random_phone, random_string
185
+ @message = {
186
+ 'timestamp' => @timestamp,
187
+ 'from' => @phone,
188
+ 'text' => @text,
189
+ 'message_id' => @message_id
190
+ }
191
+ @unread = rand(1e4)
192
+ @hash = { 'unread' => @unread, 'messages' => [@message] }
193
+ @response = TextMagic::API::Response.receive(@hash)
194
+ end
195
+
196
+ should 'have unread' do
197
+ @response.unread.should == @unread
198
+ end
199
+
200
+ should 'be an array' do
201
+ @response.class.should == Array
202
+ end
203
+
204
+ should 'contain strings with phones numbers and texts' do
205
+ @response.first.should == "#{@phone}: #{@text}"
206
+ end
207
+
208
+ should 'have timestamp for all messages' do
209
+ @response.first.timestamp.should == Time.at(@timestamp)
210
+ end
211
+
212
+ should 'have from for allmessages' do
213
+ @response.first.from.should == @phone
214
+ end
215
+
216
+ should 'have text for all messages' do
217
+ @response.first.text.should == @text
170
218
  end
171
219
 
172
- should 'allow access to deleted' do
173
- @response.deleted.should == @ids
220
+ should 'have message_id for all messages' do
221
+ @response.first.message_id.should == @message_id
174
222
  end
175
223
  end
176
224
  end
data/textmagic.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{textmagic}
5
- s.version = "0.2.2"
5
+ s.version = "0.3.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Vladim\303\255r Bobe\305\241 Tu\305\276insk\303\275"]
9
- s.date = %q{2009-05-25}
8
+ s.authors = ["Vladimir Bobes Tuzinsky"]
9
+ s.date = %q{2009-05-28}
10
10
  s.email = %q{vladimir.tuzinsky@gmail.com}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
@@ -35,13 +35,12 @@ Gem::Specification.new do |s|
35
35
  "test/test_validation.rb",
36
36
  "textmagic.gemspec"
37
37
  ]
38
- s.has_rdoc = true
39
38
  s.homepage = %q{http://github.com/bobes/textmagic}
40
39
  s.rdoc_options = ["--charset=UTF-8"]
41
40
  s.require_paths = ["lib"]
42
41
  s.rubyforge_project = %q{textmagic}
43
- s.rubygems_version = %q{1.3.1}
44
- s.summary = %q{Ruby interface to the TextMagic's SMS gateway}
42
+ s.rubygems_version = %q{1.3.3}
43
+ s.summary = %q{Ruby interface to the TextMagic's Bulk SMS Gateway}
45
44
  s.test_files = [
46
45
  "test/test_api.rb",
47
46
  "test/test_charset.rb",
@@ -54,11 +53,23 @@ Gem::Specification.new do |s|
54
53
 
55
54
  if s.respond_to? :specification_version then
56
55
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
57
- s.specification_version = 2
56
+ s.specification_version = 3
58
57
 
59
58
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
59
+ s.add_runtime_dependency(%q<httparty>, [">= 0.4.3"])
60
+ s.add_development_dependency(%q<mocha>, [">= 0.9.5"])
61
+ s.add_development_dependency(%q<fakeweb>, [">= 1.2.2"])
62
+ s.add_development_dependency(%q<jeremymcanally-matchy>, [">= 0.1.0"])
60
63
  else
64
+ s.add_dependency(%q<httparty>, [">= 0.4.3"])
65
+ s.add_dependency(%q<mocha>, [">= 0.9.5"])
66
+ s.add_dependency(%q<fakeweb>, [">= 1.2.2"])
67
+ s.add_dependency(%q<jeremymcanally-matchy>, [">= 0.1.0"])
61
68
  end
62
69
  else
70
+ s.add_dependency(%q<httparty>, [">= 0.4.3"])
71
+ s.add_dependency(%q<mocha>, [">= 0.9.5"])
72
+ s.add_dependency(%q<fakeweb>, [">= 1.2.2"])
73
+ s.add_dependency(%q<jeremymcanally-matchy>, [">= 0.1.0"])
63
74
  end
64
75
  end
metadata CHANGED
@@ -1,18 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: textmagic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - "Vladim\xC3\xADr Bobe\xC5\xA1 Tu\xC5\xBEinsk\xC3\xBD"
7
+ - Vladimir Bobes Tuzinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-25 00:00:00 +02:00
12
+ date: 2009-05-28 00:00:00 +02:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.4.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: mocha
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.5
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: fakeweb
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.2.2
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: jeremymcanally-matchy
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 0.1.0
54
+ version:
16
55
  description:
17
56
  email: vladimir.tuzinsky@gmail.com
18
57
  executables: []
@@ -46,6 +85,8 @@ files:
46
85
  - textmagic.gemspec
47
86
  has_rdoc: true
48
87
  homepage: http://github.com/bobes/textmagic
88
+ licenses: []
89
+
49
90
  post_install_message:
50
91
  rdoc_options:
51
92
  - --charset=UTF-8
@@ -66,10 +107,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
107
  requirements: []
67
108
 
68
109
  rubyforge_project: textmagic
69
- rubygems_version: 1.3.1
110
+ rubygems_version: 1.3.3
70
111
  signing_key:
71
- specification_version: 2
72
- summary: Ruby interface to the TextMagic's SMS gateway
112
+ specification_version: 3
113
+ summary: Ruby interface to the TextMagic's Bulk SMS Gateway
73
114
  test_files:
74
115
  - test/test_api.rb
75
116
  - test/test_charset.rb