Module: Twitch

Defined in:
lib/kappa/errors.rb,
lib/kappa/status.rb,
lib/kappa/version.rb,
lib/kappa/connection.rb,
lib/kappa/id_equality.rb,
lib/kappa/configuration.rb

Defined Under Namespace

Modules: V2 Classes: Error

Constant Summary collapse

VERSION =
'1.0.2'

Class Method Summary collapse

Class Method Details

.configure(&block) ⇒ nil

Configure global settings for interacting with Twitch. Future requests through the Twitch module will use these settings.

Examples:

Twitch.configure do |config|
  config.client_id = 'sc2daily-v1.0.0'
  config.api = Twitch::V2
end

streams = Twitch.streams.featured(:limit => 10)

Parameters:

  • client_id (String)

    When making requests to Twitch, you must specify a client ID for your application. If you do not specify a client ID, Twitch reserves the right to rate-limit your application without warning. If unspecified, this defaults to a random string, but in real applications, you should set this explicitly.

  • api (Module)

    The version of the Twitch API to use. Defaults to Twitch::V2, the only API version currently supported.

Returns:

  • (nil)

    nil



22
23
24
25
# File 'lib/kappa/configuration.rb', line 22

def self.configure(&block)
  @query = instance(&block)
  nil
end

.instance(&block) ⇒ Object

Create a new interface to Twitch. This allows you to have multiple separate connections to Twitch in the same process, each with its own configuration.

Examples:

client_a = Twitch.instance do |config|
  config.client_id = 'App-A-v2.0.0'
end

client_b = Twitch.instance do |config|
  config.client_id = 'App-B-v3.0.0'
end

streams = client_a.streams.featured(:limit => 10)
channel = client_b.channels.get('destiny')

Parameters:

  • client_id (String)

    When making requests to Twitch, you must specify a client ID for your application. If you do not specify a client ID, Twitch reserves the right to rate-limit your application without warning. If unspecified, this defaults to a random string, but in real applications, you should set this explicitly.

  • api (Module)

    The version of the Twitch API to use. Defaults to Twitch::V2, the only API version currently supported.

Returns:

  • (Object)

    A Twitch query object through which you can make requests. The methods on this object are the same as the methods on the default Twitch object.



48
49
50
51
52
53
# File 'lib/kappa/configuration.rb', line 48

def self.instance(&block)
  config = Configuration.new
  config.instance_eval(&block)
  connection = config.create(:Connection, config.client_id)
  return config.create(:Query, connection)
end