nabaztag_hack_kit 0.1.0.beta1 → 0.1.0.beta2
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/examples/basic/config.ru
    CHANGED
    
    
| @@ -32,9 +32,7 @@ module NabaztagHackKit | |
| 32 32 |  | 
| 33 33 | 
             
                    app.post "/playground/bunnies/:bunnyid" do #  {"command"=>["40"], "command_values"=>[["1,2,3,4"],[]]}
         | 
| 34 34 | 
             
                      if bunny = Bunny.find(params[:bunnyid])
         | 
| 35 | 
            -
                        bunny.queue_commands( | 
| 36 | 
            -
                          [command, *values.split(",")]
         | 
| 37 | 
            -
                        end)
         | 
| 35 | 
            +
                        bunny.queue_commands commands(params[:command], params[:command_values])
         | 
| 38 36 | 
             
                        bunny.to_json
         | 
| 39 37 | 
             
                      end
         | 
| 40 38 | 
             
                    end
         | 
| @@ -42,9 +40,7 @@ module NabaztagHackKit | |
| 42 40 | 
             
                    app.post "/playground/bunnies" do #  {"bunny"=>["0019db9c2daf"], "command"=>["40"], "command_values"=>[["1,2,3,4"],[]]}
         | 
| 43 41 | 
             
                      Array(params[:bunny]).uniq.each do |bunnyid|
         | 
| 44 42 | 
             
                        if bunny = Bunny.find(bunnyid)
         | 
| 45 | 
            -
                          bunny.queue_commands( | 
| 46 | 
            -
                            [command, *values.split(",")]
         | 
| 47 | 
            -
                          end)
         | 
| 43 | 
            +
                          bunny.queue_commands commands(params[:command], params[:command_values])
         | 
| 48 44 | 
             
                        end
         | 
| 49 45 | 
             
                      end
         | 
| 50 46 |  | 
| @@ -67,6 +63,22 @@ module NabaztagHackKit | |
| 67 63 | 
             
                    end
         | 
| 68 64 | 
             
                  end
         | 
| 69 65 |  | 
| 66 | 
            +
                  private
         | 
| 67 | 
            +
                  def commands(commands, command_values)
         | 
| 68 | 
            +
                    Array(commands).zip(command_values).map do |command, values|
         | 
| 69 | 
            +
                      [command] + int_array(values.split(","))
         | 
| 70 | 
            +
                    end
         | 
| 71 | 
            +
                  end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                  def int_array(array)
         | 
| 74 | 
            +
                    array.map do |entry|
         | 
| 75 | 
            +
                      if entry.to_i.to_s == entry
         | 
| 76 | 
            +
                        entry.to_i
         | 
| 77 | 
            +
                      else
         | 
| 78 | 
            +
                        entry
         | 
| 79 | 
            +
                      end
         | 
| 80 | 
            +
                    end
         | 
| 81 | 
            +
                  end
         | 
| 70 82 | 
             
                end
         | 
| 71 83 | 
             
              end
         | 
| 72 84 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: nabaztag_hack_kit
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1.0. | 
| 4 | 
            +
              version: 0.1.0.beta2
         | 
| 5 5 | 
             
              prerelease: 6
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bytecode/bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2013-01- | 
| 12 | 
            +
            date: 2013-01-07 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: sinatra
         | 
| @@ -225,7 +225,6 @@ files: | |
| 225 225 | 
             
            - lib/nabaztag_hack_kit/public/index.html
         | 
| 226 226 | 
             
            - lib/nabaztag_hack_kit/public/jquery.min.js
         | 
| 227 227 | 
             
            - lib/nabaztag_hack_kit/public/jquery.timeago.js
         | 
| 228 | 
            -
            - lib/nabaztag_hack_kit/redirect.rb
         | 
| 229 228 | 
             
            - lib/nabaztag_hack_kit/server.rb
         | 
| 230 229 | 
             
            - lib/nabaztag_hack_kit/version.rb
         | 
| 231 230 | 
             
            - nabaztag_hack_kit.gemspec
         | 
| @@ -1,37 +0,0 @@ | |
| 1 | 
            -
            require 'open-uri'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            # a rack middleware to redirect(Proxy through) certain request to another service
         | 
| 4 | 
            -
            #
         | 
| 5 | 
            -
            # it's the prefered solution for developing, so your bunny still points to live server but any request
         | 
| 6 | 
            -
            # get forwarded to dev machine
         | 
| 7 | 
            -
            module NabaztagHackKit
         | 
| 8 | 
            -
              class Redirect
         | 
| 9 | 
            -
                def initialize(app)
         | 
| 10 | 
            -
                  @app = app
         | 
| 11 | 
            -
                end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
                def call(env)
         | 
| 14 | 
            -
                  path  = env['PATH_INFO']
         | 
| 15 | 
            -
                  query = env['QUERY_STRING']
         | 
| 16 | 
            -
                  if path =~ /\/redirect/
         | 
| 17 | 
            -
                    req = Rack::Request.new(env)
         | 
| 18 | 
            -
                    if (to = req.params["to"]) && !to.empty?
         | 
| 19 | 
            -
                      @redirect = to
         | 
| 20 | 
            -
                      render "Redirect turned on to #{@redirect}"
         | 
| 21 | 
            -
                    else
         | 
| 22 | 
            -
                      @redirect = nil
         | 
| 23 | 
            -
                      render "Redirect turned off"
         | 
| 24 | 
            -
                    end
         | 
| 25 | 
            -
                  elsif @redirect
         | 
| 26 | 
            -
                    render open("#{@redirect}#{path}?#{query}")
         | 
| 27 | 
            -
                  else
         | 
| 28 | 
            -
                    @app.call(env)
         | 
| 29 | 
            -
                  end
         | 
| 30 | 
            -
                end
         | 
| 31 | 
            -
             | 
| 32 | 
            -
                private
         | 
| 33 | 
            -
                def render(response)
         | 
| 34 | 
            -
                  [response.status.first.to_i, {"Content-Type" => response.content_type}, Array(response)]
         | 
| 35 | 
            -
                end
         | 
| 36 | 
            -
              end
         | 
| 37 | 
            -
            end
         |