textmagic 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,110 +1,110 @@
1
1
  require "test_helper"
2
2
 
3
- class ValidationTest < Test::Unit::TestCase
3
+ describe "Validation" do
4
4
 
5
- context "validate_text_length method for non-unicode texts" do
5
+ describe "validate_text_length method for non-unicode texts" do
6
6
 
7
- should "use real_length method to determine the real length of the message" do
7
+ it "should use real_length method to determine the real length of the message" do
8
8
  text = random_string
9
9
  TextMagic::API.expects(:real_length).with(text, false).returns(0)
10
10
  TextMagic::API.validate_text_length(text, false, 1)
11
11
  end
12
12
 
13
- should "return true if parts limit is set to 1 and text length is less than or equal to 160" do
14
- TextMagic::API.validate_text_length(random_string(160), false, 1).should == true
13
+ it "should return true if parts limit is set to 1 and text length is less than or equal to 160" do
14
+ assert_equal true, TextMagic::API.validate_text_length(random_string(160), false, 1)
15
15
  end
16
16
 
17
- should "return false if parts limit is set to 1 and text length is greater than 160" do
18
- TextMagic::API.validate_text_length(random_string(161), false, 1).should == false
17
+ it "should return false if parts limit is set to 1 and text length is greater than 160" do
18
+ assert_equal false, TextMagic::API.validate_text_length(random_string(161), false, 1)
19
19
  end
20
20
 
21
- should "return true if parts limit is set to 2 and text length is less than or equal to 306" do
22
- TextMagic::API.validate_text_length(random_string(306), false, 2).should == true
21
+ it "should return true if parts limit is set to 2 and text length is less than or equal to 306" do
22
+ assert_equal true, TextMagic::API.validate_text_length(random_string(306), false, 2)
23
23
  end
24
24
 
25
- should "return false if parts limit is set to 2 and text length is greater than 306" do
26
- TextMagic::API.validate_text_length(random_string(307), false, 2).should == false
25
+ it "should return false if parts limit is set to 2 and text length is greater than 306" do
26
+ assert_equal false, TextMagic::API.validate_text_length(random_string(307), false, 2)
27
27
  end
28
28
 
29
- should "return true if parts limit is set to 3 or is not specified and text length is less than or equal to 459" do
30
- TextMagic::API.validate_text_length(random_string(459), false).should == true
31
- TextMagic::API.validate_text_length(random_string(459), false, 3).should == true
29
+ it "should return true if parts limit is set to 3 or is not specified and text length is less than or equal to 459" do
30
+ assert_equal true, TextMagic::API.validate_text_length(random_string(459), false)
31
+ assert_equal true, TextMagic::API.validate_text_length(random_string(459), false, 3)
32
32
  end
33
33
 
34
- should "return false if parts limit is set to 3 or is not specified and text length is greater than 459" do
35
- TextMagic::API.validate_text_length(random_string(460), false).should == false
36
- TextMagic::API.validate_text_length(random_string(460), false, 3).should == false
34
+ it "should return false if parts limit is set to 3 or is not specified and text length is greater than 459" do
35
+ assert_equal false, TextMagic::API.validate_text_length(random_string(460), false)
36
+ assert_equal false, TextMagic::API.validate_text_length(random_string(460), false, 3)
37
37
  end
38
38
  end
39
39
 
40
- context "validate_text_length method for unicode texts" do
40
+ describe "validate_text_length method for unicode texts" do
41
41
 
42
- should "use real_length method to determine the real length of the message" do
42
+ it "should use real_length method to determine the real length of the message" do
43
43
  text = random_string
44
44
  TextMagic::API.expects(:real_length).with(text, true).returns(0)
45
45
  TextMagic::API.validate_text_length(text, true, 1)
46
46
  end
47
47
 
48
- should "return true if parts limit is set to 1 and text length is less than or equal to 70" do
49
- TextMagic::API.validate_text_length(random_string(70), true, 1).should == true
48
+ it "should return true if parts limit is set to 1 and text length is less than or equal to 70" do
49
+ assert_equal true, TextMagic::API.validate_text_length(random_string(70), true, 1)
50
50
  end
51
51
 
52
- should "return false if parts limit is set to 1 and text length is greater than 70" do
53
- TextMagic::API.validate_text_length(random_string(71), true, 1).should == false
52
+ it "should return false if parts limit is set to 1 and text length is greater than 70" do
53
+ assert_equal true, TextMagic::API.validate_text_length(random_string(71), false, 1)
54
54
  end
55
55
 
56
- should "return true if parts limit is set to 2 and text length is less than or equal to 134" do
57
- TextMagic::API.validate_text_length(random_string(134), true, 2).should == true
56
+ it "should return true if parts limit is set to 2 and text length is less than or equal to 134" do
57
+ assert_equal true, TextMagic::API.validate_text_length(random_string(134), true, 2)
58
58
  end
59
59
 
60
- should "return false if parts limit is set to 2 and text length is greater than 134" do
61
- TextMagic::API.validate_text_length(random_string(135), true, 2).should == false
60
+ it "should return false if parts limit is set to 2 and text length is greater than 134" do
61
+ assert_equal true, TextMagic::API.validate_text_length(random_string(135), false, 2)
62
62
  end
63
63
 
64
- should "return true if parts limit is set to 3 or is not specified and text length is less than or equal to 201" do
65
- TextMagic::API.validate_text_length(random_string(201), true).should == true
66
- TextMagic::API.validate_text_length(random_string(201), true, 3).should == true
64
+ it "should return true if parts limit is set to 3 or is not specified and text length is less than or equal to 201" do
65
+ assert_equal true, TextMagic::API.validate_text_length(random_string(201), true)
66
+ assert_equal true, TextMagic::API.validate_text_length(random_string(201), true, 3)
67
67
  end
68
68
 
69
- should "return false if parts limit is set to 3 or is not specified and text length is greater than 201" do
70
- TextMagic::API.validate_text_length(random_string(202), true).should == false
71
- TextMagic::API.validate_text_length(random_string(202), true, 3).should == false
69
+ it "should return false if parts limit is set to 3 or is not specified and text length is greater than 201" do
70
+ assert_equal true, TextMagic::API.validate_text_length(random_string(202), false)
71
+ assert_equal true, TextMagic::API.validate_text_length(random_string(202), false, 3)
72
72
  end
73
73
  end
74
74
 
75
- context "validate_phones method" do
75
+ describe "validate_phones method" do
76
76
 
77
- should "return true if phone number consists of up to 15 digits" do
78
- TextMagic::API.validate_phones(rand(10 ** 15).to_s).should == true
77
+ it "should return true if phone number consists of up to 15 digits" do
78
+ assert_equal true, TextMagic::API.validate_phones(rand(10 ** 15).to_s)
79
79
  end
80
80
 
81
- should "return false if phone number is longer than 15 digits" do
82
- TextMagic::API.validate_phones((10 ** 16 + rand(10 ** 15)).to_s).should == false
81
+ it "should return false if phone number is longer than 15 digits" do
82
+ assert_equal false, TextMagic::API.validate_phones((10 ** 16 + rand(10 ** 15)).to_s)
83
83
  end
84
84
 
85
- should "return false if phone number contains non-digits" do
86
- TextMagic::API.validate_phones(random_string).should == false
85
+ it "should return false if phone number contains non-digits" do
86
+ assert_equal false, TextMagic::API.validate_phones(random_string)
87
87
  end
88
88
 
89
- should "return false if phone number is empty" do
90
- TextMagic::API.validate_phones("").should == false
89
+ it "should return false if phone number is empty" do
90
+ assert_equal false, TextMagic::API.validate_phones("")
91
91
  end
92
92
 
93
- should "return true if all phone numbers in a list are valid" do
93
+ it "should return true if all phone numbers in a list are valid" do
94
94
  phone1, phone2 = rand(10 ** 15).to_s, rand(10 ** 15).to_s
95
- TextMagic::API.validate_phones(phone1, phone2).should == true
96
- TextMagic::API.validate_phones([phone1, phone2]).should == true
95
+ assert_equal true, TextMagic::API.validate_phones(phone1, phone2)
96
+ assert_equal true, TextMagic::API.validate_phones([phone1, phone2])
97
97
  end
98
98
 
99
- should "return false if phone numbers list is empty" do
100
- TextMagic::API.validate_phones().should == false
99
+ it "should return false if phone numbers list is empty" do
100
+ assert_equal false, TextMagic::API.validate_phones
101
101
  end
102
102
 
103
- should "return false if format of any of phone numbers in a list is invalid" do
103
+ it "should return false if format of any of phone numbers in a list is invalid" do
104
104
  phone1 = rand(10 ** 15).to_s, rand(10 ** 15).to_s
105
105
  phone2 = random_string
106
- TextMagic::API.validate_phones(phone1, phone2).should == false
107
- TextMagic::API.validate_phones([phone1, phone2]).should == false
106
+ assert_equal false, TextMagic::API.validate_phones(phone1, phone2)
107
+ assert_equal false, TextMagic::API.validate_phones([phone1, phone2])
108
108
  end
109
109
  end
110
110
  end
@@ -20,9 +20,5 @@ Gem::Specification.new do |gem|
20
20
  gem.require_paths = ["lib"]
21
21
  gem.version = Textmagic::VERSION
22
22
 
23
- gem.add_runtime_dependency "httparty", ">= 0.5.2"
24
- gem.add_development_dependency "mocha", ">= 0.9.8"
25
- gem.add_development_dependency "shoulda", ">= 2.10.3"
26
- gem.add_development_dependency "fakeweb", ">= 1.2.8"
27
- gem.add_development_dependency "mcmire-matchy", ">= 0.5.2"
23
+ gem.add_runtime_dependency "httparty", "~> 0.5"
28
24
  end
metadata CHANGED
@@ -1,72 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: textmagic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
5
- prerelease:
4
+ version: 0.6.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Vladimir Bobes Tuzinsky
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2011-10-27 00:00:00.000000000Z
11
+ date: 2014-09-08 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: httparty
16
- requirement: &70140940266900 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: 0.5.2
19
+ version: '0.5'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70140940266900
25
- - !ruby/object:Gem::Dependency
26
- name: mocha
27
- requirement: &70140940265840 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: 0.9.8
33
- type: :development
34
- prerelease: false
35
- version_requirements: *70140940265840
36
- - !ruby/object:Gem::Dependency
37
- name: shoulda
38
- requirement: &70140940263280 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: 2.10.3
44
- type: :development
45
- prerelease: false
46
- version_requirements: *70140940263280
47
- - !ruby/object:Gem::Dependency
48
- name: fakeweb
49
- requirement: &70140940261980 !ruby/object:Gem::Requirement
50
- none: false
22
+ version_requirements: !ruby/object:Gem::Requirement
51
23
  requirements:
52
- - - ! '>='
24
+ - - "~>"
53
25
  - !ruby/object:Gem::Version
54
- version: 1.2.8
55
- type: :development
56
- prerelease: false
57
- version_requirements: *70140940261980
58
- - !ruby/object:Gem::Dependency
59
- name: mcmire-matchy
60
- requirement: &70140940261020 !ruby/object:Gem::Requirement
61
- none: false
62
- requirements:
63
- - - ! '>='
64
- - !ruby/object:Gem::Version
65
- version: 0.5.2
66
- type: :development
67
- prerelease: false
68
- version_requirements: *70140940261020
69
- description: ! "\n textmagic is a Ruby interface to the TextMagic's Bulk SMS Gateway.\n
26
+ version: '0.5'
27
+ description: "\n textmagic is a Ruby interface to the TextMagic's Bulk SMS Gateway.\n
70
28
  \ It can be used to easily integrate SMS features into your application.\n It
71
29
  supports sending messages, receiving replies and more.\n You need to have a valid
72
30
  TextMagic account to use this gem. You can get one at http://www.textmagic.com.\n
@@ -78,12 +36,12 @@ executables:
78
36
  extensions: []
79
37
  extra_rdoc_files: []
80
38
  files:
81
- - .document
82
- - .gitignore
39
+ - ".document"
40
+ - ".gitignore"
83
41
  - Gemfile
84
42
  - History.txt
85
43
  - LICENSE
86
- - README.rdoc
44
+ - README.md
87
45
  - Rakefile
88
46
  - bin/tm
89
47
  - lib/textmagic.rb
@@ -105,27 +63,26 @@ files:
105
63
  - textmagic.gemspec
106
64
  homepage: ''
107
65
  licenses: []
66
+ metadata: {}
108
67
  post_install_message:
109
68
  rdoc_options: []
110
69
  require_paths:
111
70
  - lib
112
71
  required_ruby_version: !ruby/object:Gem::Requirement
113
- none: false
114
72
  requirements:
115
- - - ! '>='
73
+ - - ">="
116
74
  - !ruby/object:Gem::Version
117
75
  version: '0'
118
76
  required_rubygems_version: !ruby/object:Gem::Requirement
119
- none: false
120
77
  requirements:
121
- - - ! '>='
78
+ - - ">="
122
79
  - !ruby/object:Gem::Version
123
80
  version: '0'
124
81
  requirements: []
125
82
  rubyforge_project:
126
- rubygems_version: 1.8.10
83
+ rubygems_version: 2.2.2
127
84
  signing_key:
128
- specification_version: 3
85
+ specification_version: 4
129
86
  summary: Ruby interface to the TextMagic's Bulk SMS Gateway
130
87
  test_files:
131
88
  - test/test_api.rb
@@ -1,153 +0,0 @@
1
- = TextMagic
2
-
3
- +textmagic+ gem is a Ruby interface to the TextMagic's Bulk SMS Gateway.
4
- It can be used to easily integrate SMS features into your application.
5
- It supports sending messages, receiving replies and more. You need to have
6
- a valid TextMagic[http://www.textmagic.com] account to use this gem. You can
7
- get one at http://www.textmagic.com.
8
-
9
- To learn more about the TextMagic's Bulk
10
- SMS Gateway, visit the official {API documentation}[http://api.textmagic.com]
11
- or {Google group}[http://groups.google.com/group/textmagic-api].
12
-
13
- Links:
14
- Doc[http://tuzinsky.com/textmagic/rdoc]
15
- |
16
- Code[http://github.com/bobes/textmagic/tree/master]
17
- |
18
- Blame[http://tuzinsky.com]
19
-
20
-
21
- == Installation
22
-
23
- Run
24
-
25
- gem install textmagic
26
-
27
- Use +sudo+ if required by your system.
28
-
29
-
30
- == Basic usage
31
-
32
- Start with requiring +textmagic+ library:
33
-
34
- require 'rubygems'
35
- require 'textmagic'
36
-
37
- Then create an API instance with your credentials:
38
-
39
- api = TextMagic::API.new(username, password)
40
-
41
- These credentials will be used in all requests to the SMS gateway.
42
-
43
- === Account balance
44
-
45
- Check your account's balance:
46
-
47
- api.account.balance
48
- # => 314.15
49
-
50
- See TextMagic::API.account for more information on +account+ method.
51
-
52
- === Sending messages
53
-
54
- To send a message to a single phone number, run:
55
-
56
- api.send 'Hi Wilma!', '999314159265'
57
-
58
- You can even specify multiple phone numbers:
59
-
60
- api.send 'Hello everybody', '999314159265', '999271828182'
61
-
62
- Unicode messages are supported as well:
63
-
64
- api.send 'Вильма Привет!', '999314159265'
65
-
66
- Long messages will be split to up to 3 parts. To limit maximum number
67
- of parts, specify an optional +max_length+ parameter:
68
-
69
- api.send 'Very very long message...', '999314159265', :max_length => 2
70
-
71
- If you want to postpone message delivery, specify a +send_time+ parameter:
72
-
73
- api.send 'Two hours later', '999314159265', :send_time => Time.now.to_i + 7200
74
-
75
- See TextMagic::API.send for more information on +send+ method.
76
-
77
- === Checking sent message status
78
-
79
- If you want to check sent message status, you have to use +message_id+
80
- returned in response to +send+ command.
81
-
82
- api.send('Hi Wilma!', '999314159265')
83
- # => '141421'
84
- status = api.message_status('141421')
85
- # => 'd'
86
- status.completed_time
87
- # => Fri May 22 10:10:18 +0200 2009
88
-
89
- You can also check statuses of several messages at once, in which case
90
- you'll get a hash with message ids as keys:
91
-
92
- api.send('Hi Wilma!', '999314159265', '999271828182').message_id
93
- # => { '999314159265' => '141421', '999271828182' => '173205' }
94
- statuses = api.message_status('141421', '173205')
95
- # => { '141421' => 'r', '173205' => 'd' }
96
- statuses['173205'].created_time
97
- # => Thu May 28 16:41:45 +0200 2009
98
-
99
- See TextMagic::API.message_status for more information on +message_status+ method.
100
-
101
- <b>It is strongly recommended to setup callbacks to receive updates on message status
102
- instead of using this method. Learn more about callbacks at
103
- {TextMagic API}[http://api.textmagic.com/https-api] site</b>
104
-
105
- === Receiving replies
106
-
107
- To receive all available replies, run:
108
-
109
- replies = api.receive
110
- # => ['999271828182: Hello Fred!', '999314159265: Good day!']
111
- replies.first.text
112
- # => 'Hello Fred!'
113
- replies.last.from
114
- # => '999314159265'
115
- replies.last.message_id
116
- # => '178082'
117
-
118
- To prevent receiving old replies again, supply +last_retrieved_id+ argument:
119
-
120
- api.receive('178082')
121
- # => []
122
-
123
- See TextMagic::API.receive for more information on +message_status+ method.
124
-
125
- <b>It is strongly recommended to setup callbacks to receive replies instead of
126
- using this method. Learn more about callbacks at
127
- {TextMagic API}[http://api.textmagic.com/https-api] site</b>
128
-
129
- === Deleting retrieved replies
130
-
131
- After you retrieve replies, you can delete them from server by running:
132
-
133
- api.delete_reply '141421', '178082'
134
- # => true
135
-
136
- See TextMagic::API.delete_reply for more information on +message_status+ method.
137
-
138
-
139
- == Command-line utility
140
-
141
- The +textmagic+ gem also features a handy command-line utility. It gives you access
142
- to all of the gem's features. Run
143
-
144
- tm
145
-
146
- from your console to see help on its usage.
147
-
148
- <i>Note: This has only been tested on a Mac with Ruby 1.8.7 and 1.9.1. If you have any troubles
149
- using this gem, contact the author (or submit a patch).</i>
150
-
151
- == Copyright
152
-
153
- Copyright (c) 2009 Vladimír Bobeš Tužinský. See LICENSE for details.