Changeset 32862 for lang

Show
Ignore:
Timestamp:
04/27/09 21:54:13 (4 years ago)
Author:
cho45
Message:

typo モード実装

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/net-irc/trunk/examples/hig.rb

    r29366 r32862  
    243243                                channel = "" if "##{channel}" == main_channel 
    244244                                rid = rid_for(reply) if reply 
    245                                 ret = api("statuses/update", {"status" => message, "in_reply_to_status_id" => rid, "keyword" => channel}) 
     245                                if @typo 
     246                                        log "typo mode. requesting..." 
     247                                        message.gsub!(/\\n/, "\n") 
     248                                        file = Net::HTTP.get(URI("http://lab.lowreal.net/test/haiku.rb/?text=" + URI.escape(message))) 
     249                                        ret = api("statuses/update", {"file" => file, "in_reply_to_status_id" => rid, "keyword" => channel}) 
     250                                else 
     251                                        ret = api("statuses/update", {"status" => message, "in_reply_to_status_id" => rid, "keyword" => channel}) 
     252                                end 
    246253                                log "Status Updated via API" 
    247254                        end 
     
    249256                        check_timeline 
    250257                rescue => e 
    251                         @log.error [retry_count, e.inspect].inspect 
     258                        @log.error [retry_count, e.message, e.inspect, e.backtrace].inspect 
    252259                        if retry_count > 0 
    253260                                retry_count -= 1 
    254261                                @log.debug "Retry to setting status..." 
    255                                 retry 
     262                                # retry 
    256263                        else 
    257264                                log "Some Error Happened on Sending #{message}. #{e}" 
     
    316323                                post nil, NOTICE, main_channel, "No such id #{tid}" 
    317324                        end 
     325                when "typo" 
     326                        @typo = !@typo 
     327                        post nil, NOTICE, main_channel, "typo mode: #{@typo}" 
    318328                end 
    319329        rescue ApiFailed => e 
     
    554564                if require_post?(path) 
    555565                        req = Net::HTTP::Post.new(uri.path) 
    556                         req.body = uri.query 
     566                        if q["file"] 
     567                                boundary = (rand(0x1_00_00_00_00_00) + 0x1_00_00_00_00_00).to_s(16) 
     568                                @log.info boundary 
     569                                req["content-type"] = "multipart/form-data; boundary=#{boundary}" 
     570 
     571                                body = "" 
     572                                q.each do |k, v| 
     573                                        body << "--#{boundary}\r\n" 
     574                                        if k == "file" 
     575                                                body << "Content-Disposition: form-data; name=\"#{k}\"; filename=\"temp.png\";\r\n" 
     576                                                body << "Content-Transfer-Encoding: binary\r\n" 
     577                                                body << "Content-Type: image/png\r\n" 
     578                                        else 
     579                                                body << "Content-Disposition: form-data; name=\"#{k}\";\r\n" 
     580                                        end 
     581                                        body << "\r\n" 
     582                                        body << v.to_s 
     583                                        body << "\r\n" 
     584                                end 
     585                                body << "--#{boundary}--\r\n" 
     586 
     587                                req.body = body 
     588                                uri.query = "" 
     589                        else 
     590                                req.body = uri.query 
     591                        end 
    557592                else 
    558593                        req = Net::HTTP::Get.new(uri.request_uri)