foobara-http-command-connector 0.0.24 → 0.0.26
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/src/http/request.rb +0 -8
- data/src/http/request_mutators/set_input_to_proc_result.rb +45 -0
- data/src/http.rb +19 -11
- metadata +5 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 29aa9d3315dc94a20e2799a25609724d6c07116d468c0187618916ecb294f424
         | 
| 4 | 
            +
              data.tar.gz: a04bbdca1ed113eb63589e437ce5262e2c483704601473f2665fcfe660c2740b
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9f3860ea8fa74eec452c33bd8065a3ffae94227ea5123103c1354b4547307060139a9a62badeb9eb33c49b300d281dd70aab9e45f21a9589d6e12cc8920c78a2
         | 
| 7 | 
            +
              data.tar.gz: 5c5e6ad45a9d9af5e732121d1cda3433a0d98a7f2ae1765fa62a2de61e18824c6fef07e02c802034ef040ad7c756b5c60caa55c493d30bfc0216ce29fdd03f8c
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/src/http/request.rb
    CHANGED
    
    | @@ -113,14 +113,6 @@ module Foobara | |
| 113 113 | 
             
                                           path
         | 
| 114 114 | 
             
                                         end
         | 
| 115 115 | 
             
                    end
         | 
| 116 | 
            -
             | 
| 117 | 
            -
                    def set_response_header(name, value)
         | 
| 118 | 
            -
                      name = name.to_s
         | 
| 119 | 
            -
                      name = name.downcase
         | 
| 120 | 
            -
             | 
| 121 | 
            -
                      self.response_headers ||= {}
         | 
| 122 | 
            -
                      self.response_headers = response_headers.merge(name => value)
         | 
| 123 | 
            -
                    end
         | 
| 124 116 | 
             
                  end
         | 
| 125 117 | 
             
                end
         | 
| 126 118 | 
             
              end
         | 
| @@ -0,0 +1,45 @@ | |
| 1 | 
            +
            module Foobara
         | 
| 2 | 
            +
              module CommandConnectors
         | 
| 3 | 
            +
                class Http < CommandConnector
         | 
| 4 | 
            +
                  # TODO: We don't really want to mutate the request. We just need access to the authenticated user.
         | 
| 5 | 
            +
                  # consider changing inputs transformer to have access to the command/request somehow
         | 
| 6 | 
            +
                  class SetInputToProcResult < RequestMutator
         | 
| 7 | 
            +
                    class << self
         | 
| 8 | 
            +
                      attr_accessor :attribute_name, :input_value_proc
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                      def for(attribute_name, &input_value_proc)
         | 
| 11 | 
            +
                        subclass = Class.new(self)
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                        subclass.attribute_name = attribute_name
         | 
| 14 | 
            +
                        subclass.input_value_proc = input_value_proc
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                        subclass
         | 
| 17 | 
            +
                      end
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    attr_writer :attribute_name, :input_value_proc
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                    def inputs_type_from(inputs_type)
         | 
| 23 | 
            +
                      new_declaration = TypeDeclarations::Attributes.reject(inputs_type.declaration_data, attribute_name)
         | 
| 24 | 
            +
                      Domain.current.foobara_type_from_declaration(new_declaration)
         | 
| 25 | 
            +
                    end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                    def applicable?(_request)
         | 
| 28 | 
            +
                      true
         | 
| 29 | 
            +
                    end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    def mutate(request)
         | 
| 32 | 
            +
                      request.inputs[attribute_name] = request.instance_exec(&input_value_proc)
         | 
| 33 | 
            +
                    end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                    def attribute_name
         | 
| 36 | 
            +
                      @attribute_name ||= self.class.attribute_name
         | 
| 37 | 
            +
                    end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                    def input_value_proc
         | 
| 40 | 
            +
                      @input_value_proc ||= self.class.input_value_proc
         | 
| 41 | 
            +
                    end
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
            end
         | 
    
        data/src/http.rb
    CHANGED
    
    | @@ -58,24 +58,28 @@ module Foobara | |
| 58 58 | 
             
                    super(*, prefix:, **)
         | 
| 59 59 | 
             
                  end
         | 
| 60 60 |  | 
| 61 | 
            -
                  def  | 
| 61 | 
            +
                  def request_to_command_class(request)
         | 
| 62 62 | 
             
                    if request.method == "OPTIONS"
         | 
| 63 | 
            -
                       | 
| 63 | 
            +
                      Foobara::CommandConnectors::Http::Commands::GetOptions
         | 
| 64 | 
            +
                    else
         | 
| 65 | 
            +
                      super.tap do |command_class|
         | 
| 66 | 
            +
                        if request.action == "help"
         | 
| 67 | 
            +
                          command_class.serializers = [Commands::Help::ResultSerializer]
         | 
| 68 | 
            +
                        end
         | 
| 69 | 
            +
                      end
         | 
| 64 70 | 
             
                    end
         | 
| 71 | 
            +
                  end
         | 
| 65 72 |  | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
                       | 
| 73 | 
            +
                  def request_to_command_inputs(request)
         | 
| 74 | 
            +
                    if request.method == "OPTIONS"
         | 
| 75 | 
            +
                      { request: }
         | 
| 76 | 
            +
                    else
         | 
| 77 | 
            +
                      super
         | 
| 71 78 | 
             
                    end
         | 
| 72 | 
            -
             | 
| 73 | 
            -
                    command
         | 
| 74 79 | 
             
                  end
         | 
| 75 80 |  | 
| 76 81 | 
             
                  def set_response_status(response)
         | 
| 77 | 
            -
                     | 
| 78 | 
            -
                    outcome = command.outcome
         | 
| 82 | 
            +
                    outcome = response.outcome
         | 
| 79 83 |  | 
| 80 84 | 
             
                    response.status = if outcome.success?
         | 
| 81 85 | 
             
                                        200
         | 
| @@ -124,6 +128,10 @@ module Foobara | |
| 124 128 | 
             
                      end
         | 
| 125 129 | 
             
                    end
         | 
| 126 130 |  | 
| 131 | 
            +
                    if request.action == "help"
         | 
| 132 | 
            +
                      response_headers = (response_headers || {}).merge("content-type" => "text/html")
         | 
| 133 | 
            +
                    end
         | 
| 134 | 
            +
             | 
| 127 135 | 
             
                    if response_headers
         | 
| 128 136 | 
             
                      static_headers.merge(response_headers)
         | 
| 129 137 | 
             
                    else
         | 
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: foobara-http-command-connector
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.26
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Miles Georgi
         | 
| 8 8 | 
             
            bindir: bin
         | 
| 9 9 | 
             
            cert_chain: []
         | 
| 10 | 
            -
            date: 2025- | 
| 10 | 
            +
            date: 2025-05-03 00:00:00.000000000 Z
         | 
| 11 11 | 
             
            dependencies:
         | 
| 12 12 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 13 13 | 
             
              name: foobara
         | 
| @@ -15,14 +15,14 @@ dependencies: | |
| 15 15 | 
             
                requirements:
         | 
| 16 16 | 
             
                - - "~>"
         | 
| 17 17 | 
             
                  - !ruby/object:Gem::Version
         | 
| 18 | 
            -
                    version: 0.0. | 
| 18 | 
            +
                    version: 0.0.116
         | 
| 19 19 | 
             
              type: :runtime
         | 
| 20 20 | 
             
              prerelease: false
         | 
| 21 21 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 22 22 | 
             
                requirements:
         | 
| 23 23 | 
             
                - - "~>"
         | 
| 24 24 | 
             
                  - !ruby/object:Gem::Version
         | 
| 25 | 
            -
                    version: 0.0. | 
| 25 | 
            +
                    version: 0.0.116
         | 
| 26 26 | 
             
            email:
         | 
| 27 27 | 
             
            - azimux@gmail.com
         | 
| 28 28 | 
             
            executables: []
         | 
| @@ -67,6 +67,7 @@ files: | |
| 67 67 | 
             
            - src/http/request.rb
         | 
| 68 68 | 
             
            - src/http/request_mutators/set_input_from_cookie.rb
         | 
| 69 69 | 
             
            - src/http/request_mutators/set_input_from_header.rb
         | 
| 70 | 
            +
            - src/http/request_mutators/set_input_to_proc_result.rb
         | 
| 70 71 | 
             
            - src/http/response.rb
         | 
| 71 72 | 
             
            - src/http/response_mutators/move_attribute_to_cookie.rb
         | 
| 72 73 | 
             
            - src/http/response_mutators/move_attribute_to_header.rb
         |