rct 0.3 → 0.5
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/bin/rct +3 -12
- data/lib/rct/baseutils.rb +11 -1
- data/lib/rct/constants.rb +2 -1
- data/lib/rct/rct_cli.rb +11 -1
- data/lib/rct/rct_http.rb +13 -3
- data/lib/rct/rct_init.rb +29 -0
- data/lib/rct/response.rb +7 -2
- data/lib/rct_cli_app.rb +24 -0
- data/lib/rct_client.rb +14 -2
- metadata +18 -18
    
        data/bin/rct
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 | 
            -
            #!/usr/bin/env  | 
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 2 | 
             
            #
         | 
| 3 | 
            -
            #  Copyright 2012 Jyri J. Virkki <jyri@virkki.com>
         | 
| 3 | 
            +
            #  Copyright 2012-2013 Jyri J. Virkki <jyri@virkki.com>
         | 
| 4 4 | 
             
            #
         | 
| 5 5 | 
             
            #  This file is part of rct.
         | 
| 6 6 | 
             
            #
         | 
| @@ -26,16 +26,7 @@ | |
| 26 26 | 
             
            # 
         | 
| 27 27 |  | 
| 28 28 | 
             
            require 'rct'
         | 
| 29 | 
            -
             | 
| 30 | 
            -
            # A few globals:
         | 
| 31 | 
            -
            $HTTP = RCTHTTP.new()
         | 
| 32 | 
            -
            $STATE = State.new()
         | 
| 33 | 
            -
             | 
| 34 | 
            -
            # Set some defaults:
         | 
| 35 | 
            -
            RCT.sset(RCT_MODE, RCT_MODE_CLI)
         | 
| 36 | 
            -
            RCT.sset(SERVER_PROTOCOL, 'http')
         | 
| 37 | 
            -
            RCT.sset(SERVER_HOSTNAME, 'localhost')
         | 
| 38 | 
            -
            RCT.sset(SERVER_PORT, '80')
         | 
| 29 | 
            +
            require 'rct/rct_init'
         | 
| 39 30 |  | 
| 40 31 | 
             
            RCT.parse_global_options()
         | 
| 41 32 |  | 
    
        data/lib/rct/baseutils.rb
    CHANGED
    
    | @@ -19,7 +19,7 @@ | |
| 19 19 |  | 
| 20 20 |  | 
| 21 21 | 
             
            #-----------------------------------------------------------------------------
         | 
| 22 | 
            -
            # Assorted utility methods. TODO: cleanup
         | 
| 22 | 
            +
            # Assorted utility methods of general interest. TODO: cleanup
         | 
| 23 23 | 
             
            #
         | 
| 24 24 | 
             
            class RCT
         | 
| 25 25 |  | 
| @@ -87,6 +87,12 @@ class RCT | |
| 87 87 | 
             
              end
         | 
| 88 88 |  | 
| 89 89 |  | 
| 90 | 
            +
              # define global options (from parse_global_options) so can do error chacking
         | 
| 91 | 
            +
              $GLOBAL_OPTS = {
         | 
| 92 | 
            +
                '-t' => 1, '--test' => 1, '--req' => 1, '-h' => 1, '--host' => 1,
         | 
| 93 | 
            +
                '-p' => 1, '--port' => 1, '-v' => 1
         | 
| 94 | 
            +
              }
         | 
| 95 | 
            +
             | 
| 90 96 | 
             
              def self.parse_global_options
         | 
| 91 97 | 
             
                pos = 0
         | 
| 92 98 |  | 
| @@ -138,6 +144,10 @@ class RCT | |
| 138 144 | 
             
              def self.parse_options(opts, required)
         | 
| 139 145 | 
             
                return if opts == nil
         | 
| 140 146 | 
             
                opts.each { |key, info|
         | 
| 147 | 
            +
                  if ($GLOBAL_OPTS[info[0]] == 1 || $GLOBAL_OPTS[info[1]] == 1)
         | 
| 148 | 
            +
                    bad_invocation("Error in CLI definition: #{info[0]}|#{info[1]} " +
         | 
| 149 | 
            +
                                   "conflicts with global options!")
         | 
| 150 | 
            +
                  end
         | 
| 141 151 | 
             
                  value = get_opt(info)
         | 
| 142 152 | 
             
                  if (required && value == nil)
         | 
| 143 153 | 
             
                    bad_invocation("Required argument #{info[0]}|#{info[1]} has no value!")
         | 
    
        data/lib/rct/constants.rb
    CHANGED
    
    | @@ -17,7 +17,7 @@ | |
| 17 17 | 
             
            #  along with rct.  If not, see <http://www.gnu.org/licenses/>.
         | 
| 18 18 | 
             
            #
         | 
| 19 19 |  | 
| 20 | 
            -
            RCT_VERSION = '0. | 
| 20 | 
            +
            RCT_VERSION = '0.5'
         | 
| 21 21 |  | 
| 22 22 | 
             
            RCT_MODE = '_mode'
         | 
| 23 23 | 
             
            RCT_MODE_CLI = 'cli'
         | 
| @@ -45,4 +45,5 @@ RESULT = 1 | |
| 45 45 | 
             
            INFO = 2
         | 
| 46 46 | 
             
            DEBUG = 3
         | 
| 47 47 |  | 
| 48 | 
            +
            CLI_OUTPUT = '_cli_output'
         | 
| 48 49 |  | 
    
        data/lib/rct/rct_cli.rb
    CHANGED
    
    | @@ -25,6 +25,10 @@ | |
| 25 25 | 
             
            # 'cli' method which provides info about the CLI methods and their
         | 
| 26 26 | 
             
            # arguments.
         | 
| 27 27 | 
             
            #
         | 
| 28 | 
            +
            # Client methods can provide friendly output in CLI mode by setting
         | 
| 29 | 
            +
            # CLI_OUTPUT to the desired text. If it is not set, the raw response body
         | 
| 30 | 
            +
            # is shown.
         | 
| 31 | 
            +
            #
         | 
| 28 32 | 
             
            class RCTCLI
         | 
| 29 33 |  | 
| 30 34 |  | 
| @@ -63,7 +67,13 @@ class RCTCLI | |
| 63 67 | 
             
                }
         | 
| 64 68 |  | 
| 65 69 | 
             
                RCT.log(INFO, response)
         | 
| 66 | 
            -
                 | 
| 70 | 
            +
                cli_output = RCT.sget(CLI_OUTPUT)
         | 
| 71 | 
            +
                if (cli_output != nil)
         | 
| 72 | 
            +
                  puts cli_output
         | 
| 73 | 
            +
                else
         | 
| 74 | 
            +
                  puts response
         | 
| 75 | 
            +
                  puts response.body
         | 
| 76 | 
            +
                end
         | 
| 67 77 | 
             
              end
         | 
| 68 78 |  | 
| 69 79 |  | 
    
        data/lib/rct/rct_http.rb
    CHANGED
    
    | @@ -19,6 +19,7 @@ | |
| 19 19 |  | 
| 20 20 |  | 
| 21 21 | 
             
            require 'httpclient'
         | 
| 22 | 
            +
            require 'base64'
         | 
| 22 23 |  | 
| 23 24 |  | 
| 24 25 | 
             
            #------------------------------------------------------------------------------
         | 
| @@ -104,7 +105,15 @@ class RCTHTTP | |
| 104 105 | 
             
                  if (auth == REQ_AUTH_TYPE_BASIC)
         | 
| 105 106 | 
             
                    name = RCT.sget(REQ_AUTH_NAME)
         | 
| 106 107 | 
             
                    pwd = RCT.sget(REQ_AUTH_PWD)
         | 
| 107 | 
            -
             | 
| 108 | 
            +
             | 
| 109 | 
            +
                    # This does not send the authorization header unless server
         | 
| 110 | 
            +
                    # first responds with 401, which some REST services won't do.
         | 
| 111 | 
            +
                    # So, instead, set header manually below.
         | 
| 112 | 
            +
                    # @http_client.set_auth(nil, name, pwd)
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                    up = "#{name}:#{pwd}"
         | 
| 115 | 
            +
                    encoded = Base64.strict_encode64(up)
         | 
| 116 | 
            +
                    headers['Authorization'] = "Basic #{encoded}"
         | 
| 108 117 | 
             
                  else
         | 
| 109 118 | 
             
                    raise "Requested auth type '#{auth}' unknown"
         | 
| 110 119 | 
             
                  end
         | 
| @@ -139,8 +148,8 @@ class RCTHTTP | |
| 139 148 | 
             
                  return response
         | 
| 140 149 | 
             
                end
         | 
| 141 150 |  | 
| 142 | 
            -
                show_response(res)
         | 
| 143 151 | 
             
                response = Response.new(res)
         | 
| 152 | 
            +
                show_response(response)
         | 
| 144 153 | 
             
                return response
         | 
| 145 154 | 
             
              end
         | 
| 146 155 |  | 
| @@ -177,8 +186,9 @@ class RCTHTTP | |
| 177 186 | 
             
                headers = res.headers
         | 
| 178 187 | 
             
                if (headers != nil)
         | 
| 179 188 | 
             
                  headers.each { |k,v|
         | 
| 180 | 
            -
                    RCT.log(INFO, " | 
| 189 | 
            +
                    RCT.log(INFO, "#{k}: #{v}")
         | 
| 181 190 | 
             
                  }
         | 
| 191 | 
            +
                  RCT.log(INFO, "")
         | 
| 182 192 | 
             
                end
         | 
| 183 193 |  | 
| 184 194 | 
             
                RCT.log(INFO, res.body)
         | 
    
        data/lib/rct/rct_init.rb
    ADDED
    
    | @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            #
         | 
| 2 | 
            +
            #  Copyright 2013 Jyri J. Virkki <jyri@virkki.com>
         | 
| 3 | 
            +
            #
         | 
| 4 | 
            +
            #  This file is part of rct.
         | 
| 5 | 
            +
            #
         | 
| 6 | 
            +
            #  rct is free software: you can redistribute it and/or modify it
         | 
| 7 | 
            +
            #  under the terms of the GNU General Public License as published by
         | 
| 8 | 
            +
            #  the Free Software Foundation, either version 3 of the License, or
         | 
| 9 | 
            +
            #  (at your option) any later version.
         | 
| 10 | 
            +
            #
         | 
| 11 | 
            +
            #  rct is distributed in the hope that it will be useful, but
         | 
| 12 | 
            +
            #  WITHOUT ANY WARRANTY; without even the implied warranty of
         | 
| 13 | 
            +
            #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
         | 
| 14 | 
            +
            #  General Public License for more details.
         | 
| 15 | 
            +
            #
         | 
| 16 | 
            +
            #  You should have received a copy of the GNU General Public License
         | 
| 17 | 
            +
            #  along with rct.  If not, see <http://www.gnu.org/licenses/>.
         | 
| 18 | 
            +
            #
         | 
| 19 | 
            +
             | 
| 20 | 
            +
             | 
| 21 | 
            +
            # A few globals:
         | 
| 22 | 
            +
            $HTTP = RCTHTTP.new()
         | 
| 23 | 
            +
            $STATE = State.new()
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            # Set some defaults:
         | 
| 26 | 
            +
            RCT.sset(RCT_MODE, RCT_MODE_CLI)
         | 
| 27 | 
            +
            RCT.sset(SERVER_PROTOCOL, 'http')
         | 
| 28 | 
            +
            RCT.sset(SERVER_HOSTNAME, 'localhost')
         | 
| 29 | 
            +
            RCT.sset(SERVER_PORT, '80')
         | 
    
        data/lib/rct/response.rb
    CHANGED
    
    | @@ -92,7 +92,7 @@ class Response | |
| 92 92 | 
             
              #
         | 
| 93 93 | 
             
              def headers
         | 
| 94 94 | 
             
                return nil if @res == nil
         | 
| 95 | 
            -
                return @res. | 
| 95 | 
            +
                return @res.headers
         | 
| 96 96 | 
             
              end
         | 
| 97 97 |  | 
| 98 98 |  | 
| @@ -112,7 +112,12 @@ class Response | |
| 112 112 | 
             
              #
         | 
| 113 113 | 
             
              def to_s
         | 
| 114 114 | 
             
                return "error: #{@fail_msg}" if @res == nil
         | 
| 115 | 
            -
             | 
| 115 | 
            +
             | 
| 116 | 
            +
                rv = "#{@res.status} #{@res.reason}"
         | 
| 117 | 
            +
                if (@fail_msg != nil)
         | 
| 118 | 
            +
                  rv += " (#{@fail_msg})"
         | 
| 119 | 
            +
                end
         | 
| 120 | 
            +
                return rv
         | 
| 116 121 | 
             
              end
         | 
| 117 122 |  | 
| 118 123 |  | 
    
        data/lib/rct_cli_app.rb
    ADDED
    
    | @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            #
         | 
| 2 | 
            +
            #  Copyright 2013 Jyri J. Virkki <jyri@virkki.com>
         | 
| 3 | 
            +
            #
         | 
| 4 | 
            +
            #  This file is part of rct.
         | 
| 5 | 
            +
            #
         | 
| 6 | 
            +
            #  rct is free software: you can redistribute it and/or modify it
         | 
| 7 | 
            +
            #  under the terms of the GNU General Public License as published by
         | 
| 8 | 
            +
            #  the Free Software Foundation, either version 3 of the License, or
         | 
| 9 | 
            +
            #  (at your option) any later version.
         | 
| 10 | 
            +
            #
         | 
| 11 | 
            +
            #  rct is distributed in the hope that it will be useful, but
         | 
| 12 | 
            +
            #  WITHOUT ANY WARRANTY; without even the implied warranty of
         | 
| 13 | 
            +
            #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
         | 
| 14 | 
            +
            #  General Public License for more details.
         | 
| 15 | 
            +
            #
         | 
| 16 | 
            +
            #  You should have received a copy of the GNU General Public License
         | 
| 17 | 
            +
            #  along with rct.  If not, see <http://www.gnu.org/licenses/>.
         | 
| 18 | 
            +
            #
         | 
| 19 | 
            +
             | 
| 20 | 
            +
             | 
| 21 | 
            +
            # CLI scripts built on top of rct can require this file to initialize rct.
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            require 'rct'
         | 
| 24 | 
            +
            require 'rct/rct_init'
         | 
    
        data/lib/rct_client.rb
    CHANGED
    
    | @@ -20,6 +20,7 @@ | |
| 20 20 |  | 
| 21 21 | 
             
            require 'securerandom'
         | 
| 22 22 | 
             
            require 'json'
         | 
| 23 | 
            +
            require 'cgi'
         | 
| 23 24 |  | 
| 24 25 |  | 
| 25 26 | 
             
            #------------------------------------------------------------------------------
         | 
| @@ -40,11 +41,12 @@ class RCTClient | |
| 40 41 | 
             
                  return params
         | 
| 41 42 | 
             
                end
         | 
| 42 43 |  | 
| 44 | 
            +
                val = CGI.escape(value)
         | 
| 43 45 | 
             
                if (params == nil || params.empty?)
         | 
| 44 | 
            -
                  return "?#{name}=#{ | 
| 46 | 
            +
                  return "?#{name}=#{val}"
         | 
| 45 47 | 
             
                end
         | 
| 46 48 |  | 
| 47 | 
            -
                return "#{params}&#{name}=#{ | 
| 49 | 
            +
                return "#{params}&#{name}=#{val}"
         | 
| 48 50 | 
             
              end
         | 
| 49 51 |  | 
| 50 52 |  | 
| @@ -121,4 +123,14 @@ class RCTClient | |
| 121 123 | 
             
              end
         | 
| 122 124 |  | 
| 123 125 |  | 
| 126 | 
            +
              #----------------------------------------------------------------------------
         | 
| 127 | 
            +
              # Convenience function, returns true if we're running in CLI mode.
         | 
| 128 | 
            +
              #
         | 
| 129 | 
            +
              def is_cli
         | 
| 130 | 
            +
                mode = sget(RCT_MODE)
         | 
| 131 | 
            +
                return true if (mode == RCT_MODE_CLI)
         | 
| 132 | 
            +
                false
         | 
| 133 | 
            +
              end
         | 
| 134 | 
            +
             | 
| 135 | 
            +
             | 
| 124 136 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,15 +1,15 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rct
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
               | 
| 5 | 
            -
               | 
| 4 | 
            +
              version: '0.5'
         | 
| 5 | 
            +
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| 8 8 | 
             
            - Jyri J. Virkki
         | 
| 9 | 
            -
            autorequire:
         | 
| 9 | 
            +
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2013- | 
| 12 | 
            +
            date: 2013-12-28 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies: []
         | 
| 14 14 | 
             
            description: wip
         | 
| 15 15 | 
             
            email: jyri@virkki.com
         | 
| @@ -18,40 +18,40 @@ executables: | |
| 18 18 | 
             
            extensions: []
         | 
| 19 19 | 
             
            extra_rdoc_files: []
         | 
| 20 20 | 
             
            files:
         | 
| 21 | 
            +
            - lib/rct.rb
         | 
| 21 22 | 
             
            - lib/rct/baseutils.rb
         | 
| 22 | 
            -
            - lib/rct/ | 
| 23 | 
            -
            - lib/rct/constants.rb
         | 
| 24 | 
            -
            - lib/rct/state.rb
         | 
| 25 | 
            -
            - lib/rct/response.rb
         | 
| 23 | 
            +
            - lib/rct/rct_init.rb
         | 
| 26 24 | 
             
            - lib/rct/rct_http.rb
         | 
| 25 | 
            +
            - lib/rct/response.rb
         | 
| 26 | 
            +
            - lib/rct/state.rb
         | 
| 27 | 
            +
            - lib/rct/constants.rb
         | 
| 28 | 
            +
            - lib/rct/rct_cli.rb
         | 
| 27 29 | 
             
            - lib/rct_client.rb
         | 
| 28 | 
            -
            - lib/ | 
| 30 | 
            +
            - lib/rct_cli_app.rb
         | 
| 29 31 | 
             
            - bin/rct
         | 
| 30 32 | 
             
            homepage: https://github.com/jvirkki/rct
         | 
| 31 33 | 
             
            licenses:
         | 
| 32 34 | 
             
            - GPLv3
         | 
| 33 | 
            -
            post_install_message:
         | 
| 35 | 
            +
            post_install_message: 
         | 
| 34 36 | 
             
            rdoc_options: []
         | 
| 35 37 | 
             
            require_paths:
         | 
| 36 38 | 
             
            - lib
         | 
| 37 39 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 40 | 
            +
              none: false
         | 
| 38 41 | 
             
              requirements:
         | 
| 39 42 | 
             
              - - ! '>='
         | 
| 40 43 | 
             
                - !ruby/object:Gem::Version
         | 
| 41 | 
            -
                  version:  | 
| 42 | 
            -
                    MA==
         | 
| 43 | 
            -
              none: false
         | 
| 44 | 
            +
                  version: '0'
         | 
| 44 45 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 46 | 
            +
              none: false
         | 
| 45 47 | 
             
              requirements:
         | 
| 46 48 | 
             
              - - ! '>='
         | 
| 47 49 | 
             
                - !ruby/object:Gem::Version
         | 
| 48 | 
            -
                  version:  | 
| 49 | 
            -
                    MA==
         | 
| 50 | 
            -
              none: false
         | 
| 50 | 
            +
                  version: '0'
         | 
| 51 51 | 
             
            requirements: []
         | 
| 52 52 | 
             
            rubyforge_project: nowarning
         | 
| 53 | 
            -
            rubygems_version: 1.8. | 
| 54 | 
            -
            signing_key:
         | 
| 53 | 
            +
            rubygems_version: 1.8.23
         | 
| 54 | 
            +
            signing_key: 
         | 
| 55 55 | 
             
            specification_version: 3
         | 
| 56 56 | 
             
            summary: rct
         | 
| 57 57 | 
             
            test_files: []
         |