Sha256: d4e291b687cf06b14ecee89c01dda10847da9b65cf6d8b7ed33c07184295a27a

Contents?: true

Size: 1.76 KB

Versions: 6

Compression:

Stored size: 1.76 KB

Contents

require 'taric/client'
require 'taric/configuration'

require 'taric/version'
require 'memoist'

module Taric
  class << self
    attr_accessor :configuration

    # Creates a [Taric::Client], the main interface to the LoL API. If the api_key is provided
    # in .configure!, then only the region needs to be set. If .configure! is used, but a different
    # api_key is provided, then the latter takes precedence.
    #
    # @see Taric::Client::REGION_ENDPOINT_INFO
    # @param region [Symbol] region code, also accepts [String], default is :na
    # @param api_key [String] rito API key
    # @param config [Taric::Configuration] configuration options. If not provided, then defaults will be used.
    #
    # @return [Taric::Client]
    #
    # @example
    #   # With .configure! (preferred)
    #   Taric.configure! do |config|
    #     config.api_key = 'your-rito-api-key'
    #   end
    #
    #   client = Taric.client(region: :na)
    #
    #   # With arbitrary key.
    #   client = Taric.client(region: :na, api_key: 'your-rito-key')
    def client(region: :na, api_key: nil, config: @configuration ||= Taric::Configuration.new)
      Taric::Client.new(api_key: api_key || config.api_key,
                        region: region.is_a?(String) ? region.to_sym : region,
                        config: config)
    end

    # Sets global configuration. Should only be called once in a process (e.g. Rails initializer)
    #
    # @see Taric::Configuration
    #
    # @example
    #   Taric.configure! do |config|
    #     config.api_key = 'your_api_key'
    #   end
    def configure!
      reset!
      yield(configuration)
    end

    # Resets global configuration.
    # @see Taric::Configuration
    def reset!
      @configuration = Taric::Configuration.new
    end


  end

end


Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
taric-0.3.1 lib/taric.rb
taric-0.3.0 lib/taric.rb
taric-0.2.4 lib/taric.rb
taric-0.2.2 lib/taric.rb
taric-0.2.1 lib/taric.rb
taric-0.2.0 lib/taric.rb