Sha256: 196bb290eee0961c489a870ac0bc3f107ddf89917083af1d15583ebd7219ce92

Contents?: true

Size: 906 Bytes

Versions: 1

Compression:

Stored size: 906 Bytes

Contents

# frozen_string_literal: true

require "uri"

# TronHttp
module TronHttp
  # Config
  class Config
    def self.hostnames
      TronHttp::DATA["hostnames"]
    end

    def self.endpoints
      TronHttp::DATA["endpoints"]
    end

    def self.scaffold
      define_network_methods
      define_endpoint_methods
    end

    def self.define_network_methods
      hostnames.each_key do |network|
        TronHttp.define_singleton_method(network) do
          Client.new network
        end
      end
    end

    def self.define_endpoint_methods
      endpoints.each do |endpoint, options|
        path = options["path"]
        method = options["method"]
        variables = options["variables"]

        Client.define_method(endpoint) do |params = {}|
          Helpers.validate_variables variables, params
          HTTP.send method, URI(@hostname + path), params
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tron_http-0.1.1 lib/tron_http/config.rb