rumeme 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ Version 0.1.2 - 2010-03-11
2
+ ===============================================================================
3
+
4
+ antlypls (14):
5
+ change SmsMessage class constructor parameters to hash
6
+ modify sms interface to reflect sms message changes
7
+ minor changes
8
+ update readme
9
+
10
+
1
11
  Version 0.1.1 - 2010-03-09
2
12
  ===============================================================================
3
13
 
@@ -10,3 +20,4 @@ antlypls (5):
10
20
 
11
21
 
12
22
 
23
+
data/README.rdoc CHANGED
@@ -25,16 +25,23 @@ Then you can use SmsInterface class to add and send messages.
25
25
 
26
26
  si = SmsInterface.new
27
27
 
28
- si.add_message('xxxxxxxxxxx', 'Message text 1')
29
- si.add_message('xxxxxxxxxxx', 'Message text 2')
30
- si.add_message('xxxxxxxxxxx', 'Message text 3')
31
- si.add_message('xxxxxxxxxxx', 'Message text 4')
32
- si.add_message('xxxxxxxxxxx', 'Message text 5')
28
+ si.add_message :phone_number => 'xxxxxxxxxxx', :message => 'Message text 1'
29
+ si.add_message :phone_number => 'xxxxxxxxxxx', :message => 'Message text 2'
30
+ si.add_message :phone_number => 'xxxxxxxxxxx', :message => 'Message text 3'
31
+ si.add_message :phone_number => 'xxxxxxxxxxx', :message => 'Message text 4'
32
+ si.add_message :phone_number => 'xxxxxxxxxxx', :message => 'Message text 5'
33
33
 
34
34
  si.send_messages
35
35
 
36
36
  Where xxxxxxxxxxx is phone number.
37
37
 
38
38
  = To Do
39
- * Refactoring to make api more rubyish.
40
- * Add unit tests
39
+ * Refactoring to make api more rubyish,
40
+ * Add unit tests,
41
+ * Remove dependency to nokogiri
42
+
43
+ = Credits
44
+ RuMeMe is maintained by antlypls, and is funded by Programmable, LLC.
45
+
46
+ = License
47
+ Still looking for license. But the software is provided "as is", without warranty of any kind.
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rake'
2
+ require 'rake/testtask'
2
3
  require 'rake/gempackagetask'
3
4
 
4
5
  GEM_ROOT = File.dirname(__FILE__).freeze
@@ -6,6 +7,14 @@ VERSION_FILE = File.join(GEM_ROOT, 'lib', 'rumeme', 'version')
6
7
 
7
8
  require VERSION_FILE
8
9
 
10
+ desc 'Test the rumeme gem'
11
+ Rake::TestTask.new(:test) do |t|
12
+ t.libs << 'lib'
13
+ t.pattern = 'test/**/*_test.rb'
14
+ t.verbose = true
15
+ end
16
+
17
+
9
18
  gemspec = Gem::Specification.new do |s|
10
19
  s.name = 'rumeme'
11
20
  s.version = Rumeme::VERSION
@@ -18,6 +27,7 @@ gemspec = Gem::Specification.new do |s|
18
27
  s.rdoc_options = ['--line-numbers', "--main", "README.rdoc"]
19
28
 
20
29
  s.add_runtime_dependency('nokogiri', '1.4.1')
30
+ s.add_development_dependency("shoulda")
21
31
 
22
32
  s.authors = ['antlypls']
23
33
  s.email = 'antlypls@gmail.com'
@@ -118,10 +128,8 @@ end
118
128
 
119
129
  desc "Push gem to Gemcutter"
120
130
  task :push_gem do
121
- system "echo '\n\n\033[31mRun: gem push #{gemspec.name}-#{gemspec.version}.gem\033[0m\n\n'"
122
-
123
- #abort("not implemented yet")
124
- #system("git push origin $(git tag | tail -1)")
131
+ system "echo '\n\n\033[31mPushing gem to gemcutter\033[0m\n\n'"
132
+ system "gem push pkg/#{gemspec.name}-#{gemspec.version}.gem"
125
133
  end
126
134
 
127
135
  desc 'release gem'
@@ -4,7 +4,6 @@ module Rumeme
4
4
  attr_accessor :password
5
5
  attr_accessor :use_message_id
6
6
  attr_accessor :secure
7
- #attr_accessor :proxy_settings
8
7
  attr_accessor :allow_splitting
9
8
  attr_accessor :allow_long_messages
10
9
  end
@@ -70,28 +70,33 @@ module Rumeme
70
70
  attr_reader :response_message
71
71
 
72
72
  # Add a message to be sent.
73
- def add_message phone, message_text, message_id = 0, delay = 0, validity_period = 169, delivery_report = false
73
+ def add_message args
74
74
  p 'in add_message '
75
- phone = strip_invalid(phone);
76
- return if phone.empty?
75
+ args[:phone_number] = strip_invalid(args[:phone_number]) #not good idea, modifying original args, from outer scope (antlypls)
77
76
 
78
- if message_text.length <= 160
79
- @message_list << SmsMessage.new(phone, message_text, message_id, delay, validity_period, delivery_report)
77
+ raise ArgumentError.new("phone_number is empty") if args[:phone_number].nil? || args[:phone_number].empty?
78
+ raise ArgumentError.new("message is empty") if args[:message].nil? || args[:message].empty?
79
+
80
+ if args[:message].length <= 160
81
+ @message_list << SmsMessage.new(args)
80
82
  return
81
83
  end
82
84
 
83
85
  if (@allow_long_messages) # Use concatenation.
84
- @message_list << SmsMessage.new(phone, message_text[0..1071], message_id, delay, validity_period, delivery_report) # 1071??? WTF ??? see php code
86
+ args[:message] = args[:message][0..1071] # 1071??? WTF ??? see php code (antlypls)
87
+ @message_list << SmsMessage.new(args)
85
88
  return
86
89
  end
87
90
 
88
91
  if !@allow_splitting
89
- @message_list << SmsMessage.new(phone, message_text[0..160], message_id, delay, validity_period, delivery_report)
92
+ args[:message] = args[:message][0..160] # maybe 159 ? (antlypls)
93
+ @message_list << SmsMessage.new(args)
90
94
  return
91
95
  end
92
96
 
93
97
  ml = []
94
- maxlen = 152;
98
+ maxlen = 152
99
+ message_text = args[:message]
95
100
  while message_text.length > maxlen
96
101
  if (pos = message_text[0..maxlen].rindex(" ")) == 0
97
102
  pos = maxlen - 1
@@ -115,7 +120,7 @@ module Rumeme
115
120
  m << "...(#{ni}/#{ml.size})"
116
121
  end
117
122
 
118
- @message_list << SmsMessage.new(phone, m, message_id, delay + 30*i, validity_period, delivery_report)
123
+ @message_list << SmsMessage.new(args.merge({:message => m, :delay => args[:delay] + 30*i}))
119
124
  }
120
125
  end
121
126
 
@@ -246,6 +251,7 @@ module Rumeme
246
251
 
247
252
  # Strip invalid characters from the phone number.
248
253
  def strip_invalid phone
254
+ return if phone.nil?
249
255
  "+#{phone.gsub(/[^0-9]/, '')}"
250
256
  end
251
257
 
@@ -254,7 +260,9 @@ module Rumeme
254
260
  p 'in connect'
255
261
  return unless @http_connection.nil?
256
262
 
257
- @server_list.all? {|server| !open_server_connection(server, @secure)} #unusefull code open_server_connection, do not connetct to server, just creates http object, so we can't check availability of the server
263
+ @server_list.all? {|server| !open_server_connection(server, @secure)} # unusefull code open_server_connection,
264
+ # does not connect to server, just creates http object,
265
+ # so we can't check availability of the server at this moment (antlypls)
258
266
 
259
267
  return if @http_connection.nil?
260
268
 
@@ -265,11 +273,9 @@ module Rumeme
265
273
  @text_buffer << "\r\nPASSWORD=#{@password}\r\nVER=PHP1.0\r\n";
266
274
  end
267
275
 
268
- # only 4 php compatibility, just free object reference
276
+ # only for php compatibility, just free object reference
269
277
  def close
270
- return if @http_connection.nil?
271
- #@http_connection.finish
272
- @http_connection = nil
278
+ @http_connection = nil unless @http_connection.nil?
273
279
  end
274
280
 
275
281
  # Flush the text buffer to the HTTP connection.
@@ -4,9 +4,16 @@ module Rumeme
4
4
  attr_reader :phone_number, :message, :message_id, :delay, :validity_period, :delivery_report
5
5
 
6
6
  # Constructor.
7
- def initialize phone_number, message, message_id, delay, validity_period, delivery_report
8
- @phone_number, @message, @message_id, @delay, @validity_period, @delivery_report = phone_number, message, message_id, delay, validity_period, delivery_report
9
- @message = message.gsub("\n",'\n').gsub("\r",'\r').gsub("\\",'\\\\')
7
+ def initialize args
8
+ # this defaults must be moved to global configuration
9
+ defaults = {:phone_number => nil, :message => nil, :message_id => 0, :delay => 0, :validity_period => ValidityPeriod::THREE_DAYS, :delivery_report => false}
10
+ params = defaults.merge args
11
+ defaults.keys.each {|k| instance_variable_set("@#{k.to_s}".to_sym, params[k])}
12
+
13
+ raise ArgumentError.new("phone_number is empty") if @phone_number.nil? || @phone_number.empty?
14
+ raise ArgumentError.new("message is empty") if @message.nil? || @message.empty?
15
+
16
+ @message = @message.gsub("\n",'\n').gsub("\r",'\r').gsub("\\",'\\\\')
10
17
  end
11
18
  end
12
19
  end
@@ -21,7 +21,7 @@ module Rumeme
21
21
  # php suxx. reimplement using regex
22
22
  def self.parse line, use_message_id
23
23
  p "parsing line: #{line}. #{use_message_id}."
24
- message_id = 0;
24
+ message_id = nil;
25
25
  status = MessageStatus::NONE
26
26
 
27
27
  prev_idx = 0;
@@ -1,3 +1,3 @@
1
1
  module Rumeme
2
- VERSION = "0.1.1".freeze
2
+ VERSION = "0.1.2".freeze
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - antlypls
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-09 00:00:00 +04:00
17
+ date: 2010-03-11 00:00:00 +04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -31,6 +31,18 @@ dependencies:
31
31
  version: 1.4.1
32
32
  type: :runtime
33
33
  version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: shoulda
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
34
46
  description:
35
47
  email: antlypls@gmail.com
36
48
  executables: []