rumeme 0.2.0 → 0.3.0
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/.gitignore +3 -0
- data/CHANGELOG +9 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +7 -0
- data/README.rdoc +0 -1
- data/Rakefile +9 -60
- data/lib/rumeme.rb +2 -1
- data/lib/rumeme/generator.rb +110 -0
- data/lib/rumeme/sms_interface.rb +12 -17
- data/lib/rumeme/sms_reply.rb +0 -1
- data/lib/rumeme/version.rb +1 -1
- data/rumeme.gemspec +29 -0
- data/test/sms_message_test.rb +57 -0
- data/test/sms_reply_test.rb +114 -0
- metadata +48 -76
    
        data/.gitignore
    ADDED
    
    
    
        data/CHANGELOG
    CHANGED
    
    | @@ -1,3 +1,10 @@ | |
| 1 | 
            +
            Version 0.3.0 - 2012-02-17
         | 
| 2 | 
            +
            ===============================================================================
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            Anatoliy Plastinin (1):
         | 
| 5 | 
            +
                  some fixes for ruby 1.9.3 support
         | 
| 6 | 
            +
             | 
| 7 | 
            +
             | 
| 1 8 | 
             
            Version 0.2.0 - 2010-08-18
         | 
| 2 9 | 
             
            ===============================================================================
         | 
| 3 10 |  | 
| @@ -77,3 +84,5 @@ antlypls (5): | |
| 77 84 |  | 
| 78 85 |  | 
| 79 86 |  | 
| 87 | 
            +
             | 
| 88 | 
            +
             | 
    
        data/Gemfile
    ADDED
    
    
    
        data/Gemfile.lock
    ADDED
    
    
    
        data/README.rdoc
    CHANGED
    
    
    
        data/Rakefile
    CHANGED
    
    | @@ -1,11 +1,6 @@ | |
| 1 1 | 
             
            require 'rake'
         | 
| 2 2 | 
             
            require 'rake/testtask'
         | 
| 3 | 
            -
            require ' | 
| 4 | 
            -
             | 
| 5 | 
            -
            GEM_ROOT     = File.dirname(__FILE__).freeze
         | 
| 6 | 
            -
            VERSION_FILE = File.join(GEM_ROOT, 'lib', 'rumeme', 'version')
         | 
| 7 | 
            -
             | 
| 8 | 
            -
            require VERSION_FILE
         | 
| 3 | 
            +
            require 'bundler/gem_tasks'
         | 
| 9 4 |  | 
| 10 5 | 
             
            desc 'Test the rumeme gem'
         | 
| 11 6 | 
             
            Rake::TestTask.new(:test) do |t|
         | 
| @@ -14,43 +9,6 @@ Rake::TestTask.new(:test) do |t| | |
| 14 9 | 
             
              t.verbose = true
         | 
| 15 10 | 
             
            end
         | 
| 16 11 |  | 
| 17 | 
            -
             | 
| 18 | 
            -
            gemspec = Gem::Specification.new do |s|
         | 
| 19 | 
            -
              s.name        = 'rumeme'
         | 
| 20 | 
            -
              s.version     = Rumeme::VERSION
         | 
| 21 | 
            -
              s.summary     = 'Ruby SDK for Message Media SMS Gateway API'
         | 
| 22 | 
            -
             | 
| 23 | 
            -
              s.files        = FileList['[A-Z]*', 'lib/**/*.rb']
         | 
| 24 | 
            -
              s.require_path = 'lib'
         | 
| 25 | 
            -
             | 
| 26 | 
            -
              s.extra_rdoc_files = ['README.rdoc']
         | 
| 27 | 
            -
              s.rdoc_options = ['--line-numbers', "--main", "README.rdoc"]
         | 
| 28 | 
            -
             | 
| 29 | 
            -
              s.add_runtime_dependency('nokogiri', '1.4.1')
         | 
| 30 | 
            -
              s.add_development_dependency("shoulda")
         | 
| 31 | 
            -
             | 
| 32 | 
            -
              s.authors = ['antlypls']
         | 
| 33 | 
            -
              s.email   = 'antlypls@gmail.com'
         | 
| 34 | 
            -
              s.homepage = 'http://github.com/programmable/rumeme'
         | 
| 35 | 
            -
             | 
| 36 | 
            -
              s.platform = Gem::Platform::RUBY
         | 
| 37 | 
            -
            end
         | 
| 38 | 
            -
             | 
| 39 | 
            -
            Rake::GemPackageTask.new gemspec do |pkg|
         | 
| 40 | 
            -
              pkg.need_tar = true
         | 
| 41 | 
            -
              pkg.need_zip = true
         | 
| 42 | 
            -
            end
         | 
| 43 | 
            -
             | 
| 44 | 
            -
            desc "Clean files generated by rake tasks"
         | 
| 45 | 
            -
            task :clobber => [:clobber_package]
         | 
| 46 | 
            -
             | 
| 47 | 
            -
            desc "Generate a gemspec file"
         | 
| 48 | 
            -
            task :gemspec do
         | 
| 49 | 
            -
              File.open("#{gemspec.name}.gemspec", 'w') do |f|
         | 
| 50 | 
            -
                f.write gemspec.to_ruby
         | 
| 51 | 
            -
              end
         | 
| 52 | 
            -
            end
         | 
| 53 | 
            -
             | 
| 54 12 | 
             
            desc "Bumps the version by a minor or patch version, depending on what was passed in."
         | 
| 55 13 | 
             
            task :bump, :part do |t, args|
         | 
| 56 14 | 
             
              if Rumeme::VERSION  =~ /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/
         | 
| @@ -77,7 +35,7 @@ task :bump, :part do |t, args| | |
| 77 35 | 
             
              File.open(File.join("lib", "rumeme", "version.rb"), "w") do |f|
         | 
| 78 36 | 
             
                f.write <<EOF
         | 
| 79 37 | 
             
            module Rumeme
         | 
| 80 | 
            -
              VERSION = "#{version}" | 
| 38 | 
            +
              VERSION = "#{version}"
         | 
| 81 39 | 
             
            end
         | 
| 82 40 | 
             
            EOF
         | 
| 83 41 | 
             
              end
         | 
| @@ -101,7 +59,7 @@ Version #{version} - #{Date.today} | |
| 101 59 | 
             
            EOF
         | 
| 102 60 | 
             
              end
         | 
| 103 61 |  | 
| 104 | 
            -
              editor = ENV["EDITOR"] || ' | 
| 62 | 
            +
              editor = ENV["EDITOR"] || 'mvim'
         | 
| 105 63 |  | 
| 106 64 | 
             
              system ["#{editor} #{file}",
         | 
| 107 65 | 
             
                    "git commit -aqm '#{message}'",
         | 
| @@ -127,18 +85,9 @@ task :push do | |
| 127 85 | 
             
              system("git push origin $(git tag | tail -1)")
         | 
| 128 86 | 
             
            end
         | 
| 129 87 |  | 
| 130 | 
            -
            desc  | 
| 131 | 
            -
            task : | 
| 132 | 
            -
               | 
| 133 | 
            -
               | 
| 134 | 
            -
             | 
| 135 | 
            -
             | 
| 136 | 
            -
            desc 'Preparing release'
         | 
| 137 | 
            -
            task :prepare_release, :part do |t, args|
         | 
| 138 | 
            -
              Rake::Task['bump'].invoke(args[:part])
         | 
| 139 | 
            -
              Rake::Task['change'].invoke
         | 
| 140 | 
            -
              Rake::Task['push'].invoke
         | 
| 141 | 
            -
            end
         | 
| 142 | 
            -
             | 
| 143 | 
            -
            desc 'Building and publishing gem'
         | 
| 144 | 
            -
            task :publish_release => [:gem, :push_gem]
         | 
| 88 | 
            +
            #desc 'Preparing release'
         | 
| 89 | 
            +
            #task :prepare_release, :part do |t, args|
         | 
| 90 | 
            +
            #  Rake::Task['bump'].invoke(args[:part])
         | 
| 91 | 
            +
            #  Rake::Task['change'].invoke
         | 
| 92 | 
            +
            #  Rake::Task['push'].invoke
         | 
| 93 | 
            +
            #end
         | 
    
        data/lib/rumeme.rb
    CHANGED
    
    | @@ -4,6 +4,7 @@ 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"
         | 
| 7 8 |  | 
| 8 9 | 
             
            module Rumeme
         | 
| 9 10 | 
             
              class << self
         | 
| @@ -11,7 +12,7 @@ module Rumeme | |
| 11 12 |  | 
| 12 13 | 
             
                def configure
         | 
| 13 14 | 
             
                  @configuration ||= Configuration.new
         | 
| 14 | 
            -
                  yield | 
| 15 | 
            +
                  yield @configuration
         | 
| 15 16 |  | 
| 16 17 | 
             
                  raise 'unknown long_messages_strategy' unless [:split, :send, :cut].include?(@configuration.long_messages_strategy)
         | 
| 17 18 | 
             
                end
         | 
| @@ -0,0 +1,110 @@ | |
| 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
         | 
    
        data/lib/rumeme/sms_interface.rb
    CHANGED
    
    | @@ -1,8 +1,5 @@ | |
| 1 1 | 
             
            require "net/http"
         | 
| 2 2 | 
             
            require "net/https"
         | 
| 3 | 
            -
            require 'rubygems'
         | 
| 4 | 
            -
            require 'nokogiri'
         | 
| 5 | 
            -
            require 'generator'
         | 
| 6 3 |  | 
| 7 4 | 
             
            module Rumeme
         | 
| 8 5 |  | 
| @@ -43,7 +40,7 @@ module Rumeme | |
| 43 40 | 
             
                  }
         | 
| 44 41 |  | 
| 45 42 | 
             
                  @message_list = []
         | 
| 46 | 
            -
                  @server_list =  | 
| 43 | 
            +
                  @server_list = %W(smsmaster.m4u.com.au smsmaster1.m4u.com.au smsmaster2.m4u.com.au)
         | 
| 47 44 |  | 
| 48 45 | 
             
                end
         | 
| 49 46 |  | 
| @@ -87,7 +84,7 @@ module Rumeme | |
| 87 84 | 
             
                  messages = response_message.split("\r\n")[1..-2].map{|message_line| SmsReply.parse(message_line)} # check @use_message_id
         | 
| 88 85 | 
             
                  confirm_replies_received if @replies_auto_confirm && messages.size > 0
         | 
| 89 86 |  | 
| 90 | 
            -
                   | 
| 87 | 
            +
                  messages
         | 
| 91 88 | 
             
                end
         | 
| 92 89 |  | 
| 93 90 | 
             
                # sends confirmation to server
         | 
| @@ -103,7 +100,7 @@ module Rumeme | |
| 103 100 | 
             
                    if response_code != 100
         | 
| 104 101 | 
             
                      raise BadServerResponse.new 'M4U code is not 100'
         | 
| 105 102 | 
             
                    end
         | 
| 106 | 
            -
                     | 
| 103 | 
            +
                    $2.to_i
         | 
| 107 104 | 
             
                  else
         | 
| 108 105 | 
             
                    raise BadServerResponse.new "cant parse response: #{response_message}"
         | 
| 109 106 | 
             
                  end
         | 
| @@ -132,7 +129,7 @@ module Rumeme | |
| 132 129 | 
             
                  list =[]
         | 
| 133 130 | 
             
                  sizes = Generator.new { |generator|  generator.yield 152; generator.yield 155 while true }
         | 
| 134 131 |  | 
| 135 | 
            -
                   | 
| 132 | 
            +
                  until message.nil? do
         | 
| 136 133 | 
             
                    head, message = head_tail_split(message, sizes.next)
         | 
| 137 134 | 
             
                    list << head
         | 
| 138 135 | 
             
                  end
         | 
| @@ -164,31 +161,29 @@ module Rumeme | |
| 164 161 | 
             
                end
         | 
| 165 162 |  | 
| 166 163 | 
             
                def post_data_to_server data
         | 
| 167 | 
            -
                   | 
| 164 | 
            +
                  puts 'post_data_to_server'
         | 
| 168 165 |  | 
| 169 166 | 
             
                  http_connection = open_server_connection(@server_list[0])
         | 
| 170 167 | 
             
                  text_buffer = create_login_string + data
         | 
| 171 168 |  | 
| 172 | 
            -
                   | 
| 169 | 
            +
                  puts "buffer: #{text_buffer}"
         | 
| 173 170 | 
             
                  headers = {'Content-Length' => text_buffer.length.to_s}
         | 
| 174 171 |  | 
| 175 172 | 
             
                  path = '/'
         | 
| 176 173 |  | 
| 177 | 
            -
                  resp | 
| 178 | 
            -
                   | 
| 179 | 
            -
                  p  | 
| 174 | 
            +
                  resp = http_connection.post(path, text_buffer, headers)
         | 
| 175 | 
            +
                  data = resp.body
         | 
| 176 | 
            +
                  p resp
         | 
| 177 | 
            +
                  p data
         | 
| 180 178 |  | 
| 181 179 | 
             
                  raise BadServerResponse.new('http response code != 200') if resp.code.to_i != 200
         | 
| 182 180 |  | 
| 183 | 
            -
                  #parsed_title, parsed_body = nil, nil
         | 
| 184 | 
            -
             | 
| 185 181 | 
             
                  if data =~ /^.+<TITLE>(.+)<\/TITLE>.+<BODY>(.+)<\/BODY>.+/m
         | 
| 186 182 | 
             
                    parsed_title, parsed_body = $1, $2
         | 
| 187 183 | 
             
                  else
         | 
| 188 184 | 
             
                    raise BadServerResponse.new('not html')
         | 
| 189 185 | 
             
                  end
         | 
| 190 186 |  | 
| 191 | 
            -
                  #doc = Nokogiri::HTML(data)
         | 
| 192 187 | 
             
                  raise BadServerResponse.new('bad title') if parsed_title != "M4U SMSMASTER"
         | 
| 193 188 |  | 
| 194 189 | 
             
                  response_message = parsed_body.strip
         | 
| @@ -196,8 +191,8 @@ module Rumeme | |
| 196 191 | 
             
                  response_message.match /^(\d+)\s+/
         | 
| 197 192 | 
             
                  response_code = $1.to_i
         | 
| 198 193 |  | 
| 199 | 
            -
                   | 
| 200 | 
            -
                   | 
| 194 | 
            +
                  puts "latest response code: #{response_code}"
         | 
| 195 | 
            +
                  puts "response: #{response_message }"
         | 
| 201 196 |  | 
| 202 197 | 
             
                  [response_message, response_code]
         | 
| 203 198 | 
             
                end
         | 
    
        data/lib/rumeme/sms_reply.rb
    CHANGED
    
    
    
        data/lib/rumeme/version.rb
    CHANGED
    
    
    
        data/rumeme.gemspec
    ADDED
    
    | @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            GEM_ROOT     = File.dirname(__FILE__).freeze
         | 
| 4 | 
            +
            VERSION_FILE = File.join(GEM_ROOT, 'lib', 'rumeme', 'version')
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            require VERSION_FILE
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            Gem::Specification.new do |s|
         | 
| 9 | 
            +
              s.name = "rumeme"
         | 
| 10 | 
            +
              s.version = Rumeme::VERSION
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              s.authors     = ["Anatoliy Plastinin, Cloud Castle LLC"]
         | 
| 13 | 
            +
              s.email       = ["antlypls@gmail.com"]
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              s.homepage = "http://github.com/programmable/rumeme"
         | 
| 16 | 
            +
              s.summary = "Ruby SDK for Message Media SMS Gateway API"
         | 
| 17 | 
            +
              s.description = "Ruby SDK for Message Media SMS Gateway API"
         | 
| 18 | 
            +
             | 
| 19 | 
            +
             | 
| 20 | 
            +
              s.add_development_dependency 'shoulda'
         | 
| 21 | 
            +
             | 
| 22 | 
            +
             | 
| 23 | 
            +
              s.files         = `git ls-files`.split("\n")
         | 
| 24 | 
            +
              s.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
         | 
| 25 | 
            +
              s.require_paths = %W(lib)
         | 
| 26 | 
            +
              s.extra_rdoc_files = ["README.rdoc"]
         | 
| 27 | 
            +
              s.rdoc_options = ["--line-numbers", "--main", "README.rdoc"]
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            end
         | 
| @@ -0,0 +1,57 @@ | |
| 1 | 
            +
            $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
         | 
| 2 | 
            +
            require 'test/unit'
         | 
| 3 | 
            +
            require "rubygems"
         | 
| 4 | 
            +
            require 'shoulda'
         | 
| 5 | 
            +
            require "rumeme"
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            class SmsMessageTest < Test::Unit::TestCase
         | 
| 8 | 
            +
              context "SmsMessage constructor" do
         | 
| 9 | 
            +
                should "correctly assign all parameters" do
         | 
| 10 | 
            +
                  sms = SmsMessage.new :phone_number => "12345678901",
         | 
| 11 | 
            +
                                       :message => "qwertasdfzxcv",
         | 
| 12 | 
            +
                                       :message_id => 100,
         | 
| 13 | 
            +
                                       :delay => 10,
         | 
| 14 | 
            +
                                       :validity_period => ValidityPeriod::MINIMUM,
         | 
| 15 | 
            +
                                       :delivery_report => true
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  assert_equal "12345678901", sms.phone_number
         | 
| 18 | 
            +
                  assert_equal "qwertasdfzxcv", sms.message
         | 
| 19 | 
            +
                  assert_equal 100, sms.message_id
         | 
| 20 | 
            +
                  assert_equal 10, sms.delay
         | 
| 21 | 
            +
                  assert_equal ValidityPeriod::MINIMUM, sms.validity_period
         | 
| 22 | 
            +
                  assert_equal true, sms.delivery_report
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                should "correctly assign default values" do
         | 
| 26 | 
            +
                  sms = SmsMessage.new :phone_number => "12345678901",
         | 
| 27 | 
            +
                                       :message => "qwertasdfzxcv"
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  assert_equal "12345678901", sms.phone_number
         | 
| 30 | 
            +
                  assert_equal "qwertasdfzxcv", sms.message
         | 
| 31 | 
            +
                  assert_equal 0, sms.message_id
         | 
| 32 | 
            +
                  assert_equal 0, sms.delay
         | 
| 33 | 
            +
                  assert_equal ValidityPeriod::THREE_DAYS, sms.validity_period
         | 
| 34 | 
            +
                  assert_equal false, sms.delivery_report
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                should "raise ArgumentError if phone number is not provided" do
         | 
| 38 | 
            +
                  e = assert_raise(ArgumentError) { SmsMessage.new :message => "qwertasdfzxcv" }
         | 
| 39 | 
            +
                  assert_match(/phone_number is empty/, e.message)
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                should "raise ArgumentError if phone number is empty" do
         | 
| 43 | 
            +
                  e = assert_raise(ArgumentError) { SmsMessage.new :phone_number => "", :message => "qwertasdfzxcv" }
         | 
| 44 | 
            +
                  assert_match(/phone_number is empty/, e.message)
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                should "raise ArgumentError if message is not provided" do
         | 
| 48 | 
            +
                  e = assert_raise(ArgumentError) { SmsMessage.new :phone_number => "12345678901" }
         | 
| 49 | 
            +
                  assert_match(/message is empty/, e.message)
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
                
         | 
| 52 | 
            +
                should "raise ArgumentError if message is empty" do
         | 
| 53 | 
            +
                  e = assert_raise(ArgumentError) { SmsMessage.new :phone_number => "12345678901", :message => "" }
         | 
| 54 | 
            +
                  assert_match(/message is empty/, e.message)
         | 
| 55 | 
            +
                end
         | 
| 56 | 
            +
              end
         | 
| 57 | 
            +
            end
         | 
| @@ -0,0 +1,114 @@ | |
| 1 | 
            +
            #units test for rumeme
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
         | 
| 4 | 
            +
            require 'test/unit'
         | 
| 5 | 
            +
            require "rubygems"
         | 
| 6 | 
            +
            require 'shoulda'
         | 
| 7 | 
            +
            require "rumeme"
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            include Rumeme
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            class SmsReplyTest < Test::Unit::TestCase
         | 
| 12 | 
            +
              context "SmsReply.parse method (for reply with id)" do
         | 
| 13 | 
            +
                setup do
         | 
| 14 | 
            +
                  @sms_reply = SmsReply.parse("12 79270123456 100 asdfgh")
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                should "correctly parse message id" do
         | 
| 18 | 
            +
                  assert_equal 12, @sms_reply.message_id
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                should "correctly parse phone number" do
         | 
| 22 | 
            +
                  assert_equal '79270123456', @sms_reply.phone_number
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                should "correctly parse when" do
         | 
| 26 | 
            +
                  assert_equal 100, @sms_reply.when
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                should "correctly parse message text" do
         | 
| 30 | 
            +
                  assert_equal 'asdfgh', @sms_reply.message
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                should "assign NONE status " do
         | 
| 34 | 
            +
                  assert_equal MessageStatus::NONE, @sms_reply.status
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
              context "SmsReply.parse method (for reply with id, phone with +)" do
         | 
| 39 | 
            +
                setup do
         | 
| 40 | 
            +
                  @sms_reply = SmsReply.parse("39 +79270123456 35 105")
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                should "correctly parse message id" do
         | 
| 44 | 
            +
                  assert_equal 39, @sms_reply.message_id
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                should "correctly parse phone number" do
         | 
| 48 | 
            +
                  assert_equal '79270123456', @sms_reply.phone_number
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                should "correctly parse when" do
         | 
| 52 | 
            +
                  assert_equal 35, @sms_reply.when
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                should "correctly parse message text" do
         | 
| 56 | 
            +
                  assert_equal '105', @sms_reply.message
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                should "assign NONE status " do
         | 
| 60 | 
            +
                  assert_equal MessageStatus::NONE, @sms_reply.status
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
              context "SmsReply.parse method (for reply without id)" do
         | 
| 65 | 
            +
                setup do
         | 
| 66 | 
            +
                  @sms_reply = SmsReply.parse("79270123456 100 asdfgh")
         | 
| 67 | 
            +
                end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                should "assign nil for message id" do
         | 
| 70 | 
            +
                  assert_nil @sms_reply.message_id
         | 
| 71 | 
            +
                end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                should "correctly parse phone number" do
         | 
| 74 | 
            +
                  assert_equal '79270123456', @sms_reply.phone_number
         | 
| 75 | 
            +
                end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                should "correctly parse when" do
         | 
| 78 | 
            +
                  assert_equal 100, @sms_reply.when
         | 
| 79 | 
            +
                end 
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                should "correctly parse message text" do
         | 
| 82 | 
            +
                  assert_equal 'asdfgh', @sms_reply.message
         | 
| 83 | 
            +
                end
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                should "assign NONE status" do
         | 
| 86 | 
            +
                  assert_equal MessageStatus::NONE, @sms_reply.status
         | 
| 87 | 
            +
                end
         | 
| 88 | 
            +
              end
         | 
| 89 | 
            +
             | 
| 90 | 
            +
              context "SmsReply.parse method (for delivery report: pending)" do
         | 
| 91 | 
            +
                setup do
         | 
| 92 | 
            +
                  @sms_reply = SmsReply.parse("12 1 100")
         | 
| 93 | 
            +
                end
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                should "correctly parse message id" do
         | 
| 96 | 
            +
                  assert_equal 12, @sms_reply.message_id
         | 
| 97 | 
            +
                end
         | 
| 98 | 
            +
             | 
| 99 | 
            +
                should "correctly parse when" do
         | 
| 100 | 
            +
                  assert_equal 100, @sms_reply.when
         | 
| 101 | 
            +
                end
         | 
| 102 | 
            +
             | 
| 103 | 
            +
                should "assign PENDING status" do
         | 
| 104 | 
            +
                  assert_equal MessageStatus::PENDING, @sms_reply.status
         | 
| 105 | 
            +
                end
         | 
| 106 | 
            +
              end
         | 
| 107 | 
            +
             | 
| 108 | 
            +
              context "SmsReply.parse method (for delivery report: pending)" do
         | 
| 109 | 
            +
                should "raise ArgumentError if incorrect string passed into" do
         | 
| 110 | 
            +
                  e = assert_raise(ArgumentError) { SmsReply.parse("jzxhcjkvhiusdfyhg") }
         | 
| 111 | 
            +
                  assert_match(/can't parse line: jzxhcjkvhiusdfyhg/, e.message)
         | 
| 112 | 
            +
                end
         | 
| 113 | 
            +
              end
         | 
| 114 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,108 +1,80 @@ | |
| 1 | 
            -
            --- !ruby/object:Gem::Specification | 
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rumeme
         | 
| 3 | 
            -
            version: !ruby/object:Gem::Version | 
| 4 | 
            -
               | 
| 5 | 
            -
              prerelease:  | 
| 6 | 
            -
              segments: 
         | 
| 7 | 
            -
              - 0
         | 
| 8 | 
            -
              - 2
         | 
| 9 | 
            -
              - 0
         | 
| 10 | 
            -
              version: 0.2.0
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.3.0
         | 
| 5 | 
            +
              prerelease: 
         | 
| 11 6 | 
             
            platform: ruby
         | 
| 12 | 
            -
            authors: | 
| 13 | 
            -
            -  | 
| 7 | 
            +
            authors:
         | 
| 8 | 
            +
            - Anatoliy Plastinin, Cloud Castle LLC
         | 
| 14 9 | 
             
            autorequire: 
         | 
| 15 10 | 
             
            bindir: bin
         | 
| 16 11 | 
             
            cert_chain: []
         | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
            dependencies: 
         | 
| 21 | 
            -
            - !ruby/object:Gem::Dependency 
         | 
| 22 | 
            -
              name: nokogiri
         | 
| 23 | 
            -
              prerelease: false
         | 
| 24 | 
            -
              requirement: &id001 !ruby/object:Gem::Requirement 
         | 
| 25 | 
            -
                none: false
         | 
| 26 | 
            -
                requirements: 
         | 
| 27 | 
            -
                - - "="
         | 
| 28 | 
            -
                  - !ruby/object:Gem::Version 
         | 
| 29 | 
            -
                    hash: 5
         | 
| 30 | 
            -
                    segments: 
         | 
| 31 | 
            -
                    - 1
         | 
| 32 | 
            -
                    - 4
         | 
| 33 | 
            -
                    - 1
         | 
| 34 | 
            -
                    version: 1.4.1
         | 
| 35 | 
            -
              type: :runtime
         | 
| 36 | 
            -
              version_requirements: *id001
         | 
| 37 | 
            -
            - !ruby/object:Gem::Dependency 
         | 
| 12 | 
            +
            date: 2012-02-17 00:00:00.000000000 Z
         | 
| 13 | 
            +
            dependencies:
         | 
| 14 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 38 15 | 
             
              name: shoulda
         | 
| 39 | 
            -
               | 
| 40 | 
            -
              requirement: &id002 !ruby/object:Gem::Requirement 
         | 
| 16 | 
            +
              requirement: &70265569651140 !ruby/object:Gem::Requirement
         | 
| 41 17 | 
             
                none: false
         | 
| 42 | 
            -
                requirements: | 
| 43 | 
            -
                - -  | 
| 44 | 
            -
                  - !ruby/object:Gem::Version | 
| 45 | 
            -
                     | 
| 46 | 
            -
                    segments: 
         | 
| 47 | 
            -
                    - 0
         | 
| 48 | 
            -
                    version: "0"
         | 
| 18 | 
            +
                requirements:
         | 
| 19 | 
            +
                - - ! '>='
         | 
| 20 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 21 | 
            +
                    version: '0'
         | 
| 49 22 | 
             
              type: :development
         | 
| 50 | 
            -
               | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 23 | 
            +
              prerelease: false
         | 
| 24 | 
            +
              version_requirements: *70265569651140
         | 
| 25 | 
            +
            description: Ruby SDK for Message Media SMS Gateway API
         | 
| 26 | 
            +
            email:
         | 
| 27 | 
            +
            - antlypls@gmail.com
         | 
| 53 28 | 
             
            executables: []
         | 
| 54 | 
            -
             | 
| 55 29 | 
             
            extensions: []
         | 
| 56 | 
            -
             | 
| 57 | 
            -
            extra_rdoc_files: 
         | 
| 30 | 
            +
            extra_rdoc_files:
         | 
| 58 31 | 
             
            - README.rdoc
         | 
| 59 | 
            -
            files: | 
| 32 | 
            +
            files:
         | 
| 33 | 
            +
            - .gitignore
         | 
| 34 | 
            +
            - CHANGELOG
         | 
| 35 | 
            +
            - Gemfile
         | 
| 36 | 
            +
            - Gemfile.lock
         | 
| 60 37 | 
             
            - README.rdoc
         | 
| 61 38 | 
             
            - Rakefile
         | 
| 62 | 
            -
            - CHANGELOG
         | 
| 63 39 | 
             
            - lib/rumeme.rb
         | 
| 64 | 
            -
            - lib/rumeme/sms_interface.rb
         | 
| 65 | 
            -
            - lib/rumeme/version.rb
         | 
| 66 40 | 
             
            - lib/rumeme/configuration.rb
         | 
| 67 | 
            -
            - lib/rumeme/ | 
| 41 | 
            +
            - lib/rumeme/generator.rb
         | 
| 68 42 | 
             
            - lib/rumeme/message_status.rb
         | 
| 43 | 
            +
            - lib/rumeme/sms_interface.rb
         | 
| 44 | 
            +
            - lib/rumeme/sms_message.rb
         | 
| 69 45 | 
             
            - lib/rumeme/sms_reply.rb
         | 
| 70 46 | 
             
            - lib/rumeme/validity_period.rb
         | 
| 71 | 
            -
             | 
| 47 | 
            +
            - lib/rumeme/version.rb
         | 
| 48 | 
            +
            - rumeme.gemspec
         | 
| 49 | 
            +
            - test/sms_message_test.rb
         | 
| 50 | 
            +
            - test/sms_reply_test.rb
         | 
| 72 51 | 
             
            homepage: http://github.com/programmable/rumeme
         | 
| 73 52 | 
             
            licenses: []
         | 
| 74 | 
            -
             | 
| 75 53 | 
             
            post_install_message: 
         | 
| 76 | 
            -
            rdoc_options: | 
| 54 | 
            +
            rdoc_options:
         | 
| 77 55 | 
             
            - --line-numbers
         | 
| 78 56 | 
             
            - --main
         | 
| 79 57 | 
             
            - README.rdoc
         | 
| 80 | 
            -
            require_paths: | 
| 58 | 
            +
            require_paths:
         | 
| 81 59 | 
             
            - lib
         | 
| 82 | 
            -
            required_ruby_version: !ruby/object:Gem::Requirement | 
| 60 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 83 61 | 
             
              none: false
         | 
| 84 | 
            -
              requirements: | 
| 85 | 
            -
              - -  | 
| 86 | 
            -
                - !ruby/object:Gem::Version | 
| 87 | 
            -
                   | 
| 88 | 
            -
             | 
| 89 | 
            -
                  - 0
         | 
| 90 | 
            -
                  version: "0"
         | 
| 91 | 
            -
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 62 | 
            +
              requirements:
         | 
| 63 | 
            +
              - - ! '>='
         | 
| 64 | 
            +
                - !ruby/object:Gem::Version
         | 
| 65 | 
            +
                  version: '0'
         | 
| 66 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 92 67 | 
             
              none: false
         | 
| 93 | 
            -
              requirements: | 
| 94 | 
            -
              - -  | 
| 95 | 
            -
                - !ruby/object:Gem::Version | 
| 96 | 
            -
                   | 
| 97 | 
            -
                  segments: 
         | 
| 98 | 
            -
                  - 0
         | 
| 99 | 
            -
                  version: "0"
         | 
| 68 | 
            +
              requirements:
         | 
| 69 | 
            +
              - - ! '>='
         | 
| 70 | 
            +
                - !ruby/object:Gem::Version
         | 
| 71 | 
            +
                  version: '0'
         | 
| 100 72 | 
             
            requirements: []
         | 
| 101 | 
            -
             | 
| 102 73 | 
             
            rubyforge_project: 
         | 
| 103 | 
            -
            rubygems_version: 1. | 
| 74 | 
            +
            rubygems_version: 1.8.15
         | 
| 104 75 | 
             
            signing_key: 
         | 
| 105 76 | 
             
            specification_version: 3
         | 
| 106 77 | 
             
            summary: Ruby SDK for Message Media SMS Gateway API
         | 
| 107 | 
            -
            test_files: | 
| 108 | 
            -
             | 
| 78 | 
            +
            test_files:
         | 
| 79 | 
            +
            - test/sms_message_test.rb
         | 
| 80 | 
            +
            - test/sms_reply_test.rb
         |