zaikio-hub 0.9.1 → 0.10.0
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 +4 -0
- data/lib/zaikio/hub/client.rb +2 -0
- data/lib/zaikio/hub/configuration.rb +9 -32
- data/lib/zaikio/hub/version.rb +1 -1
- data/lib/zaikio/hub.rb +10 -17
- metadata +6 -7
- data/lib/zaikio/hub/authorization_middleware.rb +0 -32
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: e6de6ed1ed5cb7442b72ffa036df6de0cf7f371d59d52018b4458850b7e71848
         | 
| 4 | 
            +
              data.tar.gz: 5dc770e601267c847094fdb07875651529ec14458676c5d5be558af9c0d15c39
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 2b168642b4f8c6ac5607602a7e2237224e98fe52b4991c3f06b3a61591eeeacb6a6d76a60f63acaa272fe55cb9ee43f42f0a7aea871a3eeca7a2a770abc5f8ae
         | 
| 7 | 
            +
              data.tar.gz: 4aca04231bccaf9dc4d85ebf752ef4663f365cc7bc788a8b55d979983047e4eb78e3978bf2bd28ef274186f7408ce2d5288941b08e4bdb40329ed6468ab000dc
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |
| 7 7 |  | 
| 8 8 | 
             
            ## [Unreleased]
         | 
| 9 9 |  | 
| 10 | 
            +
            ## [0.10.0] - 2022-08-15
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            * Update `zaikio-client-helpers` and reuse logic to use `Zaikio::Client.with_token`
         | 
| 13 | 
            +
             | 
| 10 14 | 
             
            ## [0.9.1] - 2022-01-05
         | 
| 11 15 |  | 
| 12 16 | 
             
            * Fix warning about redefined methods in BasicAuthMiddleware
         | 
    
        data/lib/zaikio/hub/client.rb
    CHANGED
    
    
| @@ -2,38 +2,15 @@ require "logger" | |
| 2 2 |  | 
| 3 3 | 
             
            module Zaikio
         | 
| 4 4 | 
             
              module Hub
         | 
| 5 | 
            -
                class Configuration
         | 
| 6 | 
            -
                   | 
| 7 | 
            -
                     | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
                  attr_accessor :host
         | 
| 15 | 
            -
                  attr_reader :environment
         | 
| 16 | 
            -
                  attr_writer :logger
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                  def initialize
         | 
| 19 | 
            -
                    @environment = :sandbox
         | 
| 20 | 
            -
                  end
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                  def logger
         | 
| 23 | 
            -
                    @logger ||= Logger.new($stdout)
         | 
| 24 | 
            -
                  end
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                  def environment=(env)
         | 
| 27 | 
            -
                    @environment = env.to_sym
         | 
| 28 | 
            -
                    @host = host_for(environment)
         | 
| 29 | 
            -
                  end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                  private
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                  def host_for(environment)
         | 
| 34 | 
            -
                    HOSTS.fetch(environment) do
         | 
| 35 | 
            -
                      raise StandardError.new, "Invalid Zaikio::Hub environment '#{environment}'"
         | 
| 36 | 
            -
                    end
         | 
| 5 | 
            +
                class Configuration < Zaikio::Client::Helpers::Configuration
         | 
| 6 | 
            +
                  def self.hosts
         | 
| 7 | 
            +
                    {
         | 
| 8 | 
            +
                      development: "https://hub.zaikio.test/api/v1",
         | 
| 9 | 
            +
                      test: "https://hub.zaikio.test/api/v1",
         | 
| 10 | 
            +
                      staging: "https://hub.staging.zaikio.com/api/v1",
         | 
| 11 | 
            +
                      sandbox: "https://hub.sandbox.zaikio.com/api/v1",
         | 
| 12 | 
            +
                      production: "https://hub.zaikio.com/api/v1"
         | 
| 13 | 
            +
                    }.freeze
         | 
| 37 14 | 
             
                  end
         | 
| 38 15 | 
             
                end
         | 
| 39 16 | 
             
              end
         | 
    
        data/lib/zaikio/hub/version.rb
    CHANGED
    
    
    
        data/lib/zaikio/hub.rb
    CHANGED
    
    | @@ -3,7 +3,6 @@ require "spyke" | |
| 3 3 | 
             
            require "zaikio-client-helpers"
         | 
| 4 4 |  | 
| 5 5 | 
             
            require "zaikio/hub/configuration"
         | 
| 6 | 
            -
            require "zaikio/hub/authorization_middleware"
         | 
| 7 6 | 
             
            require "zaikio/hub/basic_auth_middleware"
         | 
| 8 7 |  | 
| 9 8 | 
             
            # Models
         | 
| @@ -44,11 +43,8 @@ module Zaikio | |
| 44 43 | 
             
                    Base.connection = create_connection
         | 
| 45 44 | 
             
                  end
         | 
| 46 45 |  | 
| 47 | 
            -
                  def with_token(token)
         | 
| 48 | 
            -
                     | 
| 49 | 
            -
                    yield
         | 
| 50 | 
            -
                  ensure
         | 
| 51 | 
            -
                    AuthorizationMiddleware.reset_token
         | 
| 46 | 
            +
                  def with_token(token, &block)
         | 
| 47 | 
            +
                    Zaikio::Client.with_token(token, &block)
         | 
| 52 48 | 
             
                  end
         | 
| 53 49 |  | 
| 54 50 | 
             
                  def with_basic_auth(login, password)
         | 
| @@ -59,23 +55,20 @@ module Zaikio | |
| 59 55 | 
             
                  end
         | 
| 60 56 |  | 
| 61 57 | 
             
                  def current_token_data
         | 
| 62 | 
            -
                    return unless AuthorizationMiddleware.token
         | 
| 58 | 
            +
                    return unless Zaikio::Client::Helpers::AuthorizationMiddleware.token
         | 
| 63 59 |  | 
| 64 | 
            -
                    payload = JWT.decode( | 
| 60 | 
            +
                    payload = JWT.decode(
         | 
| 61 | 
            +
                      Zaikio::Client::Helpers::AuthorizationMiddleware.token,
         | 
| 62 | 
            +
                      nil,
         | 
| 63 | 
            +
                      false
         | 
| 64 | 
            +
                    ).first
         | 
| 65 65 |  | 
| 66 66 | 
             
                    create_token_data(payload)
         | 
| 67 67 | 
             
                  end
         | 
| 68 68 |  | 
| 69 69 | 
             
                  def create_connection
         | 
| 70 | 
            -
                    self.connection =  | 
| 71 | 
            -
             | 
| 72 | 
            -
                      c.request     :json
         | 
| 73 | 
            -
                      c.response    :logger, configuration&.logger, headers: false
         | 
| 74 | 
            -
                      c.use         Zaikio::Client::Helpers::Pagination::FaradayMiddleware
         | 
| 75 | 
            -
                      c.use         Zaikio::Client::Helpers::JSONParser
         | 
| 76 | 
            -
                      c.use         AuthorizationMiddleware
         | 
| 77 | 
            -
                      c.use         BasicAuthMiddleware
         | 
| 78 | 
            -
                      c.adapter     Faraday.default_adapter
         | 
| 70 | 
            +
                    self.connection = Zaikio::Client.create_connection(configuration).tap do |c|
         | 
| 71 | 
            +
                      c.use BasicAuthMiddleware
         | 
| 79 72 | 
             
                    end
         | 
| 80 73 | 
             
                  end
         | 
| 81 74 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: zaikio-hub
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.10.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - crispymtn
         | 
| @@ -10,7 +10,7 @@ authors: | |
| 10 10 | 
             
            autorequire: 
         | 
| 11 11 | 
             
            bindir: bin
         | 
| 12 12 | 
             
            cert_chain: []
         | 
| 13 | 
            -
            date: 2022- | 
| 13 | 
            +
            date: 2022-08-15 00:00:00.000000000 Z
         | 
| 14 14 | 
             
            dependencies:
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 16 16 | 
             
              name: concurrent-ruby
         | 
| @@ -35,7 +35,7 @@ dependencies: | |
| 35 35 | 
             
                    version: 2.2.1
         | 
| 36 36 | 
             
                - - "<"
         | 
| 37 37 | 
             
                  - !ruby/object:Gem::Version
         | 
| 38 | 
            -
                    version: 2. | 
| 38 | 
            +
                    version: 2.5.0
         | 
| 39 39 | 
             
              type: :runtime
         | 
| 40 40 | 
             
              prerelease: false
         | 
| 41 41 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| @@ -45,7 +45,7 @@ dependencies: | |
| 45 45 | 
             
                    version: 2.2.1
         | 
| 46 46 | 
             
                - - "<"
         | 
| 47 47 | 
             
                  - !ruby/object:Gem::Version
         | 
| 48 | 
            -
                    version: 2. | 
| 48 | 
            +
                    version: 2.5.0
         | 
| 49 49 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 50 50 | 
             
              name: multi_json
         | 
| 51 51 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -112,14 +112,14 @@ dependencies: | |
| 112 112 | 
             
                requirements:
         | 
| 113 113 | 
             
                - - "~>"
         | 
| 114 114 | 
             
                  - !ruby/object:Gem::Version
         | 
| 115 | 
            -
                    version: '0. | 
| 115 | 
            +
                    version: '0.3'
         | 
| 116 116 | 
             
              type: :runtime
         | 
| 117 117 | 
             
              prerelease: false
         | 
| 118 118 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 119 119 | 
             
                requirements:
         | 
| 120 120 | 
             
                - - "~>"
         | 
| 121 121 | 
             
                  - !ruby/object:Gem::Version
         | 
| 122 | 
            -
                    version: '0. | 
| 122 | 
            +
                    version: '0.3'
         | 
| 123 123 | 
             
            description: Ruby API Client for Zaikio's Hub
         | 
| 124 124 | 
             
            email:
         | 
| 125 125 | 
             
            - op@crispymtn.com
         | 
| @@ -137,7 +137,6 @@ files: | |
| 137 137 | 
             
            - lib/zaikio/hub/address.rb
         | 
| 138 138 | 
             
            - lib/zaikio/hub/app.rb
         | 
| 139 139 | 
             
            - lib/zaikio/hub/asset.rb
         | 
| 140 | 
            -
            - lib/zaikio/hub/authorization_middleware.rb
         | 
| 141 140 | 
             
            - lib/zaikio/hub/base.rb
         | 
| 142 141 | 
             
            - lib/zaikio/hub/basic_auth_middleware.rb
         | 
| 143 142 | 
             
            - lib/zaikio/hub/business_relationship.rb
         | 
| @@ -1,32 +0,0 @@ | |
| 1 | 
            -
            require "faraday"
         | 
| 2 | 
            -
            require "jwt"
         | 
| 3 | 
            -
            require "concurrent"
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            module Zaikio
         | 
| 6 | 
            -
              module Hub
         | 
| 7 | 
            -
                class AuthorizationMiddleware < Faraday::Middleware
         | 
| 8 | 
            -
                  def self.token
         | 
| 9 | 
            -
                    @token ||= Concurrent::ThreadLocalVar.new { nil }
         | 
| 10 | 
            -
                    @token.value
         | 
| 11 | 
            -
                  end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
                  def self.token=(value)
         | 
| 14 | 
            -
                    @token ||= Concurrent::ThreadLocalVar.new { nil }
         | 
| 15 | 
            -
                    @token.value = value
         | 
| 16 | 
            -
                  end
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                  def self.reset_token
         | 
| 19 | 
            -
                    self.token = nil
         | 
| 20 | 
            -
                  end
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                  def call(request_env)
         | 
| 23 | 
            -
                    if self.class.token
         | 
| 24 | 
            -
                      request_env[:request_headers]["Authorization"] = "Bearer #{self.class.token}"
         | 
| 25 | 
            -
                    end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                    @app.call(request_env).on_complete do |response_env|
         | 
| 28 | 
            -
                    end
         | 
| 29 | 
            -
                  end
         | 
| 30 | 
            -
                end
         | 
| 31 | 
            -
              end
         | 
| 32 | 
            -
            end
         |