rumeme 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,15 @@
1
+ Version 0.4.0 - 2012-10-30
2
+ ===============================================================================
3
+
4
+ Stan Carver II (6):
5
+ changed send_messages to return true or false instead of raising an error
6
+ added send_messages! to raise an error
7
+ change inverted if not conditionals to unless
8
+ refactored message_id_sign out of create_login_string
9
+ consolidated self references with a << self block
10
+ added my name to the credits as a contributor
11
+
12
+
1
13
  Version 0.3.0 - 2012-02-17
2
14
  ===============================================================================
3
15
 
data/README.rdoc CHANGED
@@ -9,7 +9,7 @@ Just execute
9
9
  gem install rumeme
10
10
 
11
11
  == Usage
12
- Firs of all add Rumeme initialization
12
+ First, add Rumeme initialization
13
13
 
14
14
  Rumeme.configure do |config|
15
15
  config.username = 'xxx'
@@ -40,7 +40,10 @@ Where xxxxxxxxxxx is phone number.
40
40
  * Add unit tests,
41
41
 
42
42
  = Credits
43
- RuMeMe is maintained by antlypls, and is funded by Programmable, LLC.
43
+ RuMeMe is maintained by Anatoliy Plastinin, and is funded by {Cloud Castle, LLC}[http://cloudcastlegroup.com/].
44
+
45
+ = Contributors
46
+ Stan Carver II
44
47
 
45
48
  = License
46
- Still looking for license. But the software is provided "as is", without warranty of any kind.
49
+ Still looking for license. But the software is provided "as is", without warranty of any kind.
@@ -79,7 +79,7 @@ module Rumeme
79
79
  # Return the list of replies we have received.
80
80
  def check_replies
81
81
  response_message, response_code = post_data_to_server("CHECKREPLY2.0\r\n.\r\n")
82
- return if response_code != 150
82
+ return unless response_code == 150
83
83
 
84
84
  messages = response_message.split("\r\n")[1..-2].map{|message_line| SmsReply.parse(message_line)} # check @use_message_id
85
85
  confirm_replies_received if @replies_auto_confirm && messages.size > 0
@@ -106,57 +106,66 @@ module Rumeme
106
106
  end
107
107
  end
108
108
 
109
- # Sends all the messages that have been added with the
110
- # add_message command.
109
+ # Sends all the messages that have been added with the add_message command.
110
+ # returns boolean. true if successful, false if not.
111
111
  def send_messages
112
112
  post_string = @message_list.map(&:post_string).join
113
113
  text_buffer = "MESSAGES2.0\r\n#{post_string}.\r\n"
114
114
  response_message, response_code = post_data_to_server(text_buffer)
115
+ response_code == 100
116
+ end
115
117
 
116
- raise BadServerResponse.new('error during sending messages') if response_code != 100
118
+ # Sends all the messages that have been added with the add_message command.
119
+ # Raises exception if not successful
120
+ def send_messages!
121
+ raise BadServerResponse.new('error during sending messages') unless send_messages
117
122
  end
118
123
 
119
124
  private
120
125
 
121
- def self.head_tail_split message, max_len
122
- return [message, nil] if message.length < max_len
123
- pattern = /\s\.,!;:-\)/
124
- index = message[0..max_len].rindex(pattern) || max_len
125
- [message[0..index], message[index+1 .. -1]]
126
- end
126
+ class << self
127
+ def head_tail_split message, max_len
128
+ return [message, nil] if message.length < max_len
129
+ pattern = /\s\.,!;:-\)/
130
+ index = message[0..max_len].rindex(pattern) || max_len
131
+ [message[0..index], message[index+1 .. -1]]
132
+ end
127
133
 
128
- def self.split_message_internal message
129
- list =[]
130
- sizes = Generator.new { |generator| generator.yield 152; generator.yield 155 while true }
134
+ def split_message_internal message
135
+ list =[]
136
+ sizes = Enumerator.new {|yielder| yielder << 152; yielder << 155 while true}
131
137
 
132
- until message.nil? do
133
- head, message = head_tail_split(message, sizes.next)
134
- list << head
138
+ until message.nil? do
139
+ head, message = head_tail_split(message, sizes.next)
140
+ list << head
141
+ end
142
+
143
+ list
135
144
  end
136
145
 
137
- list
138
- end
146
+ def split_message message
147
+ messages = split_message_internal message
148
+ message_index = 1
149
+ total_messages = messages.size
150
+ ["#{messages[0]}...(1/#{total_messages})"].concat(messages[1..-1].map {|msg| "(#{message_index+=1}/#{total_messages})#{msg}"})
151
+ end
139
152
 
140
- def self.split_message message
141
- messages = split_message_internal message
142
- message_index = 1
143
- total_messages = messages.size
144
- ["#{messages[0]}...(1/#{total_messages})"].concat(messages[1..-1].map {|msg| "(#{message_index+=1}/#{total_messages})#{msg}"})
153
+ # Strip invalid characters from the phone number.
154
+ def strip_invalid phone
155
+ phone.nil? ? "+#{phone.gsub(/[^0-9]/, '')}" : nil
156
+ end
145
157
  end
146
-
158
+
147
159
  def process_long_message message
148
160
  return [message] if message.length <= 160
149
161
  @long_messages_processor.call(message)
150
162
  end
151
163
 
152
- # Strip invalid characters from the phone number.
153
- def self.strip_invalid phone
154
- return nil if phone.nil?
155
- "+#{phone.gsub(/[^0-9]/, '')}"
164
+ def message_id_sign
165
+ @use_message_id ? '#' : ''
156
166
  end
157
-
167
+
158
168
  def create_login_string # can be calculate once at initialization
159
- message_id_sign = @use_message_id? '#' :''
160
169
  "m4u\r\nUSER=#{@username}#{message_id_sign}\r\nPASSWORD=#{@password}\r\nVER=PHP1.0\r\n"
161
170
  end
162
171
 
@@ -175,8 +184,8 @@ module Rumeme
175
184
  data = resp.body
176
185
  p resp
177
186
  p data
178
-
179
- raise BadServerResponse.new('http response code != 200') if resp.code.to_i != 200
187
+
188
+ raise BadServerResponse.new('http response code != 200') unless response.code.to_i == 200
180
189
 
181
190
  if data =~ /^.+<TITLE>(.+)<\/TITLE>.+<BODY>(.+)<\/BODY>.+/m
182
191
  parsed_title, parsed_body = $1, $2
@@ -184,7 +193,7 @@ module Rumeme
184
193
  raise BadServerResponse.new('not html')
185
194
  end
186
195
 
187
- raise BadServerResponse.new('bad title') if parsed_title != "M4U SMSMASTER"
196
+ raise BadServerResponse.new('bad title') unless parsed_title == "M4U SMSMASTER"
188
197
 
189
198
  response_message = parsed_body.strip
190
199
 
@@ -8,34 +8,36 @@ module Rumeme
8
8
  @phone_number, @message, @message_id, @when, @status = phone_number, message, message_id, _when, status
9
9
  end
10
10
 
11
- # Unescape any escaped characters in the string.
12
- def self.unescape line
13
- line.nil? ? nil : line.gsub('\n', "\n").gsub('\r', "\r").gsub('\\\\', "\\")
14
- end
11
+ class << self
12
+ # Unescape any escaped characters in the string.
13
+ def unescape line
14
+ line.nil? ? nil : line.gsub('\n', "\n").gsub('\r', "\r").gsub('\\\\', "\\")
15
+ end
15
16
 
16
- # Parse a reply from a string.
17
- # Format is: messageID phone when message /(\d+)\s(\d+)\s(\d+)\s(.+)/
18
- # Or if no message ID: phone when message /(\d+)\s(\d+)\s(.+)/
19
- # Or if delivery receipt: messageID messageStatus when /(\d+)\s(\d)\s(\d+)/
20
- # current implementation ignores use_message_id setting (as original code)
21
- def self.parse line
22
- p "parsing line: #{line}"
17
+ # Parse a reply from a string.
18
+ # Format is: messageID phone when message /(\d+)\s(\d+)\s(\d+)\s(.+)/
19
+ # Or if no message ID: phone when message /(\d+)\s(\d+)\s(.+)/
20
+ # Or if delivery receipt: messageID messageStatus when /(\d+)\s(\d)\s(\d+)/
21
+ # current implementation ignores use_message_id setting (as original code)
22
+ def parse line
23
+ p "parsing line: #{line}"
23
24
 
24
- message_id, status, message, phone, when_ = case line
25
- when /^(\d+)\s(\d)\s(\d+)/
26
- #process delivery report
27
- [$1.to_i, $2.to_i, nil, nil, $3.to_i]
28
- when /^(\d+)\s\+?(\d+)\s(\d+)\s(.+)/
29
- #process message with id
30
- [$1.to_i, MessageStatus::NONE, unescape($4), $2, $3.to_i]
31
- when /^\+?(\d+)\s(\d+)\s(.+)/
32
- #process message without id
33
- [nil, MessageStatus::NONE, unescape($3), $1, $2.to_i]
34
- else
35
- raise ArgumentError.new("can't parse line: #{line}")
36
- end
25
+ message_id, status, message, phone, when_ = case line
26
+ when /^(\d+)\s(\d)\s(\d+)/
27
+ #process delivery report
28
+ [$1.to_i, $2.to_i, nil, nil, $3.to_i]
29
+ when /^(\d+)\s\+?(\d+)\s(\d+)\s(.+)/
30
+ #process message with id
31
+ [$1.to_i, MessageStatus::NONE, unescape($4), $2, $3.to_i]
32
+ when /^\+?(\d+)\s(\d+)\s(.+)/
33
+ #process message without id
34
+ [nil, MessageStatus::NONE, unescape($3), $1, $2.to_i]
35
+ else
36
+ raise ArgumentError.new("can't parse line: #{line}")
37
+ end
37
38
 
38
- return SmsReply.new(phone, message, message_id, when_, status)
39
+ return SmsReply.new(phone, message, message_id, when_, status)
40
+ end
39
41
  end
40
42
 
41
43
  def delivery_report?
@@ -1,3 +1,3 @@
1
1
  module Rumeme
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/rumeme.rb CHANGED
@@ -4,7 +4,6 @@ require "rumeme/validity_period"
4
4
  require "rumeme/sms_message"
5
5
  require "rumeme/sms_reply"
6
6
  require "rumeme/sms_interface"
7
- require "rumeme/generator"
8
7
 
9
8
  module Rumeme
10
9
  class << self
data/rumeme.gemspec CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.name = "rumeme"
10
10
  s.version = Rumeme::VERSION
11
11
 
12
- s.authors = ["Anatoliy Plastinin, Cloud Castle LLC"]
13
- s.email = ["antlypls@gmail.com"]
12
+ s.authors = ["Anatoliy Plastinin, Cloud Castle LLC", "Stan Carver II, A1 Web Consulting"]
13
+ s.email = ["antlypls@gmail.com", "stan@a1webconsulting.com"]
14
14
 
15
15
  s.homepage = "http://github.com/programmable/rumeme"
16
16
  s.summary = "Ruby SDK for Message Media SMS Gateway API"
metadata CHANGED
@@ -1,19 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rumeme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Anatoliy Plastinin, Cloud Castle LLC
9
+ - Stan Carver II, A1 Web Consulting
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-02-17 00:00:00.000000000 Z
13
+ date: 2012-11-01 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: shoulda
16
- requirement: &70265569651140 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
17
18
  none: false
18
19
  requirements:
19
20
  - - ! '>='
@@ -21,10 +22,16 @@ dependencies:
21
22
  version: '0'
22
23
  type: :development
23
24
  prerelease: false
24
- version_requirements: *70265569651140
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
25
31
  description: Ruby SDK for Message Media SMS Gateway API
26
32
  email:
27
33
  - antlypls@gmail.com
34
+ - stan@a1webconsulting.com
28
35
  executables: []
29
36
  extensions: []
30
37
  extra_rdoc_files:
@@ -38,7 +45,6 @@ files:
38
45
  - Rakefile
39
46
  - lib/rumeme.rb
40
47
  - lib/rumeme/configuration.rb
41
- - lib/rumeme/generator.rb
42
48
  - lib/rumeme/message_status.rb
43
49
  - lib/rumeme/sms_interface.rb
44
50
  - lib/rumeme/sms_message.rb
@@ -71,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
77
  version: '0'
72
78
  requirements: []
73
79
  rubyforge_project:
74
- rubygems_version: 1.8.15
80
+ rubygems_version: 1.8.23
75
81
  signing_key:
76
82
  specification_version: 3
77
83
  summary: Ruby SDK for Message Media SMS Gateway API
@@ -1,110 +0,0 @@
1
- # from ruby 1.8.7 source
2
-
3
- class Generator
4
- include Enumerable
5
-
6
- # Creates a new generator either from an Enumerable object or from a
7
- # block.
8
- #
9
- # In the former, block is ignored even if given.
10
- #
11
- # In the latter, the given block is called with the generator
12
- # itself, and expected to call the +yield+ method for each element.
13
- def initialize(enum = nil, &block)
14
- if enum
15
- @block = proc { |g|
16
- enum.each { |x| g.yield x }
17
- }
18
- else
19
- @block = block
20
- end
21
-
22
- @index = 0
23
- @queue = []
24
- @cont_next = @cont_yield = @cont_endp = nil
25
-
26
- if @cont_next = callcc { |c| c }
27
- @block.call(self)
28
-
29
- @cont_endp.call(nil) if @cont_endp
30
- end
31
-
32
- self
33
- end
34
-
35
- # Yields an element to the generator.
36
- def yield(value)
37
- if @cont_yield = callcc { |c| c }
38
- @queue << value
39
- @cont_next.call(nil)
40
- end
41
-
42
- self
43
- end
44
-
45
- # Returns true if the generator has reached the end.
46
- def end?()
47
- if @cont_endp = callcc { |c| c }
48
- @cont_yield.nil? && @queue.empty?
49
- else
50
- @queue.empty?
51
- end
52
- end
53
-
54
- # Returns true if the generator has not reached the end yet.
55
- def next?()
56
- !end?
57
- end
58
-
59
- # Returns the current index (position) counting from zero.
60
- def index()
61
- @index
62
- end
63
-
64
- # Returns the current index (position) counting from zero.
65
- def pos()
66
- @index
67
- end
68
-
69
- # Returns the element at the current position and moves forward.
70
- def next()
71
- if end?
72
- raise EOFError, "no more elements available"
73
- end
74
-
75
- if @cont_next = callcc { |c| c }
76
- @cont_yield.call(nil) if @cont_yield
77
- end
78
-
79
- @index += 1
80
-
81
- @queue.shift
82
- end
83
-
84
- # Returns the element at the current position.
85
- def current()
86
- if @queue.empty?
87
- raise EOFError, "no more elements available"
88
- end
89
-
90
- @queue.first
91
- end
92
-
93
- # Rewinds the generator.
94
- def rewind()
95
- initialize(nil, &@block) if @index.nonzero?
96
-
97
- self
98
- end
99
-
100
- # Rewinds the generator and enumerates the elements.
101
- def each
102
- rewind
103
-
104
- until end?
105
- yield self.next
106
- end
107
-
108
- self
109
- end
110
- end