Sha256: 8f24023b7c4c7e844d56f7e897f3542b6aa0bdc7eb4cac30f75e43049eabfd5b

Contents?: true

Size: 1.08 KB

Versions: 14

Compression:

Stored size: 1.08 KB

Contents

# typed: strict
# frozen_string_literal: true

module DearInventory
  class Resource
    extend T::Sig
    extend DearInventory::IsASubclass

    sig do
      params(
        action: Symbol,
        model: T.class_of(DearInventory::Model),
        endpoint: T.nilable(String),
        params: T::Hash[Symbol, T.untyped]
      ).returns(DearInventory::Response)
    end
    def request(action, model:, endpoint: nil, params: {})
      uri = resource_uri(endpoint)
      params = DearInventory::Parameters.convert(self.class, endpoint, params)

      request = DearInventory::Models::Request.new(
        action: action,
        model: model,
        params: params,
        uri: uri
      )
      DearInventory::Request.(request)
    end

    private

    URI_BASE = "https://inventory.dearsystems.com/ExternalApi/v2"

    sig { params(endpoint: T.nilable(String)).returns(String) }
    def resource_uri(endpoint)
      resource = T.must(self.class.name).split("::").last
      uri = "#{URI_BASE}/#{T.must(resource).downcase}"
      uri += "/#{endpoint}" unless endpoint.nil?
      uri
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
dear_inventory-0.7.5 lib/dear_inventory/resource.rb
dear_inventory-0.7.4 lib/dear_inventory/resource.rb
dear_inventory-0.7.3 lib/dear_inventory/resource.rb
dear_inventory-0.7.2 lib/dear_inventory/resource.rb
dear_inventory-0.7.1 lib/dear_inventory/resource.rb
dear_inventory-0.7.0 lib/dear_inventory/resource.rb
dear_inventory-0.6.3 lib/dear_inventory/resource.rb
dear_inventory-0.6.2 lib/dear_inventory/resource.rb
dear_inventory-0.6.1 lib/dear_inventory/resource.rb
dear_inventory-0.6.0 lib/dear_inventory/resource.rb
dear_inventory-0.5.0 lib/dear_inventory/resource.rb
dear_inventory-0.4.1 lib/dear_inventory/resource.rb
dear_inventory-0.4.0 lib/dear_inventory/resource.rb
dear_inventory-0.3.0 lib/dear_inventory/resource.rb