rfetion 0.4.2 → 0.4.3
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/VERSION +1 -1
- data/lib/rfetion/command.rb +17 -18
- data/lib/rfetion/fetion.rb +62 -48
- data/rfetion.gemspec +2 -2
- metadata +2 -2
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.4. | 
| 1 | 
            +
            0.4.3
         | 
    
        data/lib/rfetion/command.rb
    CHANGED
    
    | @@ -9,9 +9,11 @@ OptionParser.new do |opts| | |
| 9 9 | 
             
              opts.separator ""
         | 
| 10 10 | 
             
              opts.separator <<-EOF
         | 
| 11 11 | 
             
                Example: rfetion -m mobile -p password -c sms_content
         | 
| 12 | 
            +
                         rfetion -s sip -p password -c sms_content
         | 
| 12 13 | 
             
                         rfetion -m mobile -p password -r mobile_or_fetion_numbers -c sms_content
         | 
| 13 14 | 
             
                         rfetion -m mobile -p password -r mobile_or_fetion_numbers -c sms_content -t time
         | 
| 14 15 | 
             
                         rfetion -m mobile -p password --add-buddy-with-mobile friend_mobile
         | 
| 16 | 
            +
                         rfetion -s sip -p password --add-buddy-with-mobile friend_mobile
         | 
| 15 17 | 
             
                         rfetion -m mobile -p password --add-buddy-with-sip friend_sip
         | 
| 16 18 |  | 
| 17 19 | 
             
              EOF
         | 
| @@ -20,6 +22,10 @@ OptionParser.new do |opts| | |
| 20 22 | 
             
                options[:mobile_no] = mobile
         | 
| 21 23 | 
             
              end
         | 
| 22 24 |  | 
| 25 | 
            +
              opts.on('-s', '--sip FETION_SIP', 'Fetion sid number') do |sid|
         | 
| 26 | 
            +
                options[:sid] = sid
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 23 29 | 
             
              opts.on('-p', '--password PASSWORD', 'Fetion password') do |password|
         | 
| 24 30 | 
             
                options[:password] = password
         | 
| 25 31 | 
             
              end
         | 
| @@ -28,7 +34,7 @@ OptionParser.new do |opts| | |
| 28 34 | 
             
                options[:content] = content
         | 
| 29 35 | 
             
              end
         | 
| 30 36 |  | 
| 31 | 
            -
              opts.on('-r', '--receivers MOBILE,SIP', Array, " | 
| 37 | 
            +
              opts.on('-r', '--receivers MOBILE,SIP', Array, "Receivers' Fetion mobile numbers or fetion sip numbers, if no recievers, send sms to yourself") do |receivers|
         | 
| 32 38 | 
             
                options[:receivers] = receivers
         | 
| 33 39 | 
             
              end
         | 
| 34 40 |  | 
| @@ -37,22 +43,22 @@ OptionParser.new do |opts| | |
| 37 43 | 
             
              end
         | 
| 38 44 |  | 
| 39 45 | 
             
              opts.on('--add-buddy-with-mobile MOBILE', 'Add friend mobile as fetion friend') do |mobile|
         | 
| 40 | 
            -
                options[: | 
| 46 | 
            +
                options[:friend_mobile] = mobile
         | 
| 41 47 | 
             
              end
         | 
| 42 48 |  | 
| 43 49 | 
             
              opts.on('--add-buddy-with-sip SIP', 'Add friend fetion sip as fetion friend') do |sip|
         | 
| 44 | 
            -
                options[: | 
| 50 | 
            +
                options[:friend_sip] = sip
         | 
| 45 51 | 
             
              end
         | 
| 46 52 |  | 
| 47 53 | 
             
              opts.separator ""
         | 
| 48 54 | 
             
              opts.separator "different mode:"
         | 
| 49 55 |  | 
| 50 56 | 
             
              opts.on('--debug', 'debug mode') do
         | 
| 51 | 
            -
                options[: | 
| 57 | 
            +
                options[:logger_level] = Logger::DEBUG
         | 
| 52 58 | 
             
              end
         | 
| 53 59 |  | 
| 54 60 | 
             
              opts.on('--silence', 'silence mode') do
         | 
| 55 | 
            -
                options[: | 
| 61 | 
            +
                options[:logger_level] = Logger::ERROR
         | 
| 56 62 | 
             
              end
         | 
| 57 63 |  | 
| 58 64 | 
             
              opts.separator ""
         | 
| @@ -71,25 +77,18 @@ OptionParser.new do |opts| | |
| 71 77 | 
             
              opts.parse!
         | 
| 72 78 | 
             
            end
         | 
| 73 79 |  | 
| 74 | 
            -
            def level(options)
         | 
| 75 | 
            -
              return Logger::DEBUG if options[:debug]
         | 
| 76 | 
            -
              return Logger::ERROR if options[:silence]
         | 
| 77 | 
            -
              return Logger::INFO
         | 
| 78 | 
            -
            end
         | 
| 79 | 
            -
             | 
| 80 80 | 
             
            begin
         | 
| 81 | 
            -
              if options[: | 
| 82 | 
            -
                raise FetionException.new('You must input your mobile number and password') unless options[:mobile_no] and options[:password]
         | 
| 83 | 
            -
                Fetion. | 
| 84 | 
            -
                Fetion.add_buddy_with_sip(options[:mobile_no], options[:password], options[:add_sip], level(options)) if options[:add_sip]
         | 
| 81 | 
            +
              if options[:friend_mobile] or options[:friend_sip]
         | 
| 82 | 
            +
                raise FetionException.new('You must input your mobile number or fetion sid, and password') unless (options[:mobile_no] or options[:sid]) and options[:password]
         | 
| 83 | 
            +
                Fetion.add_buddy(options)
         | 
| 85 84 | 
             
                exit
         | 
| 86 85 | 
             
              end
         | 
| 87 86 |  | 
| 88 | 
            -
              raise FetionException.new('You must input your mobile number, password and content') unless options[:mobile_no] and options[:password] and options[:content]
         | 
| 87 | 
            +
              raise FetionException.new('You must input your mobile number or fetion sid, password and content') unless (options[:mobile_no] or options[:sid]) and options[:password] and options[:content]
         | 
| 89 88 | 
             
              if options[:time]
         | 
| 90 | 
            -
                Fetion.schedule_sms(options | 
| 89 | 
            +
                Fetion.schedule_sms(options)
         | 
| 91 90 | 
             
              else
         | 
| 92 | 
            -
                Fetion.send_sms(options | 
| 91 | 
            +
                Fetion.send_sms(options)
         | 
| 93 92 | 
             
              end
         | 
| 94 93 | 
             
            rescue FetionException => e
         | 
| 95 94 | 
             
              puts e.message
         | 
    
        data/lib/rfetion/fetion.rb
    CHANGED
    
    | @@ -2,7 +2,7 @@ class FetionException < Exception | |
| 2 2 | 
             
            end
         | 
| 3 3 |  | 
| 4 4 | 
             
            class Fetion
         | 
| 5 | 
            -
              attr_accessor :mobile_no, :password
         | 
| 5 | 
            +
              attr_accessor :mobile_no, :sid, :password
         | 
| 6 6 | 
             
              attr_reader :uri, :contacts
         | 
| 7 7 |  | 
| 8 8 | 
             
              FETION_URL = 'http://221.130.44.194/ht/sd.aspx'
         | 
| @@ -26,17 +26,23 @@ class Fetion | |
| 26 26 | 
             
                @logger.level = level
         | 
| 27 27 | 
             
              end
         | 
| 28 28 |  | 
| 29 | 
            -
               | 
| 30 | 
            -
             | 
| 31 | 
            -
               | 
| 32 | 
            -
             | 
| 33 | 
            -
               | 
| 29 | 
            +
              # options
         | 
| 30 | 
            +
              #   mobile_no
         | 
| 31 | 
            +
              #   sid
         | 
| 32 | 
            +
              #   password
         | 
| 33 | 
            +
              #   receivers
         | 
| 34 | 
            +
              #   content
         | 
| 35 | 
            +
              #   logger_level
         | 
| 36 | 
            +
              def Fetion.send_sms(options)
         | 
| 34 37 | 
             
                fetion = Fetion.new
         | 
| 35 | 
            -
                fetion.logger_level =  | 
| 36 | 
            -
                fetion.mobile_no = mobile_no
         | 
| 37 | 
            -
                fetion. | 
| 38 | 
            +
                fetion.logger_level = options[:logger_level] || Logger::INFO
         | 
| 39 | 
            +
                fetion.mobile_no = options[:mobile_no]
         | 
| 40 | 
            +
                fetion.sid = options[:sid]
         | 
| 41 | 
            +
                fetion.password = options[:password]
         | 
| 38 42 | 
             
                fetion.login
         | 
| 39 43 | 
             
                fetion.register
         | 
| 44 | 
            +
                receivers = options[:receivers]
         | 
| 45 | 
            +
                content = options[:content]
         | 
| 40 46 | 
             
                if receivers
         | 
| 41 47 | 
             
                  receivers = Array(receivers)
         | 
| 42 48 | 
             
                  receivers.collect! {|receiver| receiver.to_s}
         | 
| @@ -54,13 +60,25 @@ class Fetion | |
| 54 60 | 
             
                fetion.logout
         | 
| 55 61 | 
             
              end
         | 
| 56 62 |  | 
| 57 | 
            -
               | 
| 63 | 
            +
              # options
         | 
| 64 | 
            +
              #   mobile_no
         | 
| 65 | 
            +
              #   sid
         | 
| 66 | 
            +
              #   password
         | 
| 67 | 
            +
              #   receivers
         | 
| 68 | 
            +
              #   content
         | 
| 69 | 
            +
              #   time
         | 
| 70 | 
            +
              #   logger_level
         | 
| 71 | 
            +
              def Fetion.schedule_sms(options)
         | 
| 58 72 | 
             
                fetion = Fetion.new
         | 
| 59 | 
            -
                fetion.logger_level =  | 
| 60 | 
            -
                fetion.mobile_no = mobile_no
         | 
| 61 | 
            -
                fetion. | 
| 73 | 
            +
                fetion.logger_level = options[:logger_level] || Logger::INFO
         | 
| 74 | 
            +
                fetion.mobile_no = options[:mobile_no]
         | 
| 75 | 
            +
                fetion.sid = options[:sid]
         | 
| 76 | 
            +
                fetion.password = options[:password]
         | 
| 62 77 | 
             
                fetion.login
         | 
| 63 78 | 
             
                fetion.register
         | 
| 79 | 
            +
                receivers = options[:receivers]
         | 
| 80 | 
            +
                content = options[:content]
         | 
| 81 | 
            +
                time = options[:time]
         | 
| 64 82 | 
             
                fetion.get_buddy_list
         | 
| 65 83 | 
             
                fetion.get_contacts_info
         | 
| 66 84 | 
             
                if receivers
         | 
| @@ -79,33 +97,33 @@ class Fetion | |
| 79 97 | 
             
                fetion.logout
         | 
| 80 98 | 
             
              end
         | 
| 81 99 |  | 
| 82 | 
            -
               | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 85 | 
            -
             | 
| 86 | 
            -
             | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 89 | 
            -
             | 
| 90 | 
            -
                fetion.add_buddy_with_mobile(friend_mobile)
         | 
| 91 | 
            -
                fetion.logout
         | 
| 92 | 
            -
              end
         | 
| 93 | 
            -
             | 
| 94 | 
            -
              def Fetion.add_buddy_with_sip(mobile_no, password, friend_sip, level = Logger::INFO)
         | 
| 100 | 
            +
              # options
         | 
| 101 | 
            +
              #   mobile_no
         | 
| 102 | 
            +
              #   sid
         | 
| 103 | 
            +
              #   password
         | 
| 104 | 
            +
              #   friend_mobile
         | 
| 105 | 
            +
              #   friend_sip
         | 
| 106 | 
            +
              #   logger_level
         | 
| 107 | 
            +
              def Fetion.add_buddy(options)
         | 
| 95 108 | 
             
                fetion = Fetion.new
         | 
| 96 | 
            -
                fetion.logger_level =  | 
| 97 | 
            -
                fetion.mobile_no = mobile_no
         | 
| 98 | 
            -
                fetion. | 
| 109 | 
            +
                fetion.logger_level = options[:logger_level] || Logger::INFO
         | 
| 110 | 
            +
                fetion.mobile_no = options[:mobile_no]
         | 
| 111 | 
            +
                fetion.sid = options[:sid]
         | 
| 112 | 
            +
                fetion.password = options[:password]
         | 
| 99 113 | 
             
                fetion.login
         | 
| 100 114 | 
             
                fetion.register
         | 
| 101 115 | 
             
                fetion.get_personal_info
         | 
| 102 | 
            -
                fetion. | 
| 116 | 
            +
                fetion.add_buddy(options)
         | 
| 103 117 | 
             
                fetion.logout
         | 
| 104 118 | 
             
              end
         | 
| 105 119 |  | 
| 106 120 | 
             
              def login
         | 
| 107 121 | 
             
                @logger.info "fetion login"
         | 
| 108 | 
            -
                 | 
| 122 | 
            +
                if @mobile_no
         | 
| 123 | 
            +
                  uri = URI.parse(FETION_LOGIN_URL + "?mobileno=#{@mobile_no}&pwd=#{@password}")
         | 
| 124 | 
            +
                else
         | 
| 125 | 
            +
                  uri = URI.parse(FETION_LOGIN_URL + "?sid=#{@sid}&pwd=#{@password}")
         | 
| 126 | 
            +
                end
         | 
| 109 127 | 
             
                http = Net::HTTP.new(uri.host, uri.port)
         | 
| 110 128 | 
             
                http.use_ssl = true
         | 
| 111 129 | 
             
                http.verify_mode = OpenSSL::SSL::VERIFY_NONE
         | 
| @@ -282,35 +300,31 @@ class Fetion | |
| 282 300 | 
             
                @logger.info "fetion get personal info success"
         | 
| 283 301 | 
             
              end
         | 
| 284 302 |  | 
| 285 | 
            -
               | 
| 286 | 
            -
             | 
| 287 | 
            -
             | 
| 303 | 
            +
              # options
         | 
| 304 | 
            +
              #   friend_mobile
         | 
| 305 | 
            +
              #   friend_sip
         | 
| 306 | 
            +
              def add_buddy(options)
         | 
| 307 | 
            +
                uri = options[:friend_mobile] ? "tel:#{options[:friend_mobile]}" : "sip:#{options[:friend_sip]}"
         | 
| 308 | 
            +
             | 
| 309 | 
            +
                @logger.info "fetion send request to add #{uri} as friend"
         | 
| 310 | 
            +
                arg = %Q{<args><contacts><buddies><buddy uri="#{uri}" local-name="" buddy-lists="1" desc="#{@person['nickname']}" expose-mobile-no="1" expose-name="1" /></buddies></contacts></args>}
         | 
| 288 311 | 
             
                msg = sip_create('S fetion.com.cn SIP-C/2.0', {'F' => @sid, 'I' => next_call, 'Q' => '1 S', 'N' => 'AddBuddy'}, arg) + FETION_SIPP
         | 
| 289 312 | 
             
                curl_exec(next_url, @ssic, msg)
         | 
| 290 313 | 
             
                response = curl_exec(next_url, @ssic, FETION_SIPP)
         | 
| 291 314 | 
             
                raise FetionException.new("Fetion Error: Add buddy error") unless response.is_a? Net::HTTPSuccess
         | 
| 292 315 |  | 
| 293 316 | 
             
                if response.body =~ /No Subscription/
         | 
| 294 | 
            -
                   | 
| 317 | 
            +
                  raise FetionException.new("Fetion Error: No #{uri}") if options[:friend_sip]
         | 
| 318 | 
            +
             | 
| 319 | 
            +
                  arg = %Q{<args><contacts><mobile-buddies><mobile-buddy uri="#{uri}" local-name="" buddy-lists="1" desc="#{@person['nickname']}" expose-mobile-no="1" expose-name="1" /></mobile-buddies></contacts></args>}
         | 
| 295 320 | 
             
                  msg = sip_create('S fetion.com.cn SIP-C/2.0', {'F' => @sid, 'I' => next_call, 'Q' => '1 S', 'N' => 'AddMobileBuddy'}, arg) + FETION_SIPP
         | 
| 296 321 | 
             
                  curl_exec(next_url, @ssic, msg)
         | 
| 297 322 | 
             
                  response = curl_exec(next_url, @ssic, FETION_SIPP)
         | 
| 298 323 | 
             
                  raise FetionException.new("Fetion Error: Add buddy error") unless response.is_a? Net::HTTPSuccess
         | 
| 299 324 |  | 
| 300 | 
            -
                  raise FetionException.new("Fetion Error: No  | 
| 325 | 
            +
                  raise FetionException.new("Fetion Error: No #{uri}") if response.body =~ /Not Found/
         | 
| 301 326 | 
             
                end
         | 
| 302 | 
            -
                @logger.info "fetion send request to add  | 
| 303 | 
            -
              end
         | 
| 304 | 
            -
             | 
| 305 | 
            -
              def add_buddy_with_sip(sip)
         | 
| 306 | 
            -
                @logger.info "fetion send request to add sip:#{sip} as friend"
         | 
| 307 | 
            -
                arg = %Q{<args><contacts><buddies><buddy uri="sip:#{sip}" local-name="" buddy-lists="1" desc="#{@person['nickname']}" expose-mobile-no="1" expose-name="1" /></buddies></contacts></args>}
         | 
| 308 | 
            -
                msg = sip_create('S fetion.com.cn SIP-C/2.0', {'F' => @sid, 'I' => next_call, 'Q' => '1 S', 'N' => 'AddBuddy'}, arg) + FETION_SIPP
         | 
| 309 | 
            -
                curl_exec(next_url, @ssic, msg)
         | 
| 310 | 
            -
                response = curl_exec(next_url, @ssic, FETION_SIPP)
         | 
| 311 | 
            -
             | 
| 312 | 
            -
                raise FetionException.new("Fetion Error: Add buddy error") unless response.is_a? Net::HTTPSuccess
         | 
| 313 | 
            -
                @logger.info "fetion send request to add sip:#{sip} as friend success"
         | 
| 327 | 
            +
                @logger.info "fetion send request to add #{uri} as friend success"
         | 
| 314 328 | 
             
              end
         | 
| 315 329 |  | 
| 316 330 | 
             
              def logout
         | 
    
        data/rfetion.gemspec
    CHANGED
    
    | @@ -5,11 +5,11 @@ | |
| 5 5 |  | 
| 6 6 | 
             
            Gem::Specification.new do |s|
         | 
| 7 7 | 
             
              s.name = %q{rfetion}
         | 
| 8 | 
            -
              s.version = "0.4. | 
| 8 | 
            +
              s.version = "0.4.3"
         | 
| 9 9 |  | 
| 10 10 | 
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 11 11 | 
             
              s.authors = ["Richard Huang"]
         | 
| 12 | 
            -
              s.date = %q{2009-12- | 
| 12 | 
            +
              s.date = %q{2009-12-17}
         | 
| 13 13 | 
             
              s.description = %q{rfetion is a ruby gem for China Mobile fetion service that you can send SMS free.}
         | 
| 14 14 | 
             
              s.email = %q{flyerhzm@gmail.com}
         | 
| 15 15 | 
             
              s.executables = ["rfetion", "rfetion"]
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: rfetion
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              version: 0.4. | 
| 4 | 
            +
              version: 0.4.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors: 
         | 
| 7 7 | 
             
            - Richard Huang
         | 
| @@ -9,7 +9,7 @@ autorequire: | |
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 11 |  | 
| 12 | 
            -
            date: 2009-12- | 
| 12 | 
            +
            date: 2009-12-17 00:00:00 +08:00
         | 
| 13 13 | 
             
            default_executable: 
         | 
| 14 14 | 
             
            dependencies: 
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency 
         |