Class: OmniAuth::Strategies::Twitchtv

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/twitchtv.rb

Instance Method Summary collapse

Instance Method Details

#info_urlObject



40
41
42
43
44
45
46
47
# File 'lib/omniauth/strategies/twitchtv.rb', line 40

def info_url
  unless self.options.scopes && (self.options.scopes.index("user_read") || self.options.scopes.index(:user_read)) ||
      self.options.scopes && (self.options.scopes.index("user_read") || self.options.scopes.index(:user_read)) ||
      self.options.scope.to_sym == :user_read || self.options.scope.to_sym == :channel_read
    raise Omniauth::Twitchtv::TwitchtvError.new("Must include at least either the channel or user read scope in omniauth-twitchtv initializer")
  end
  "https://api.twitch.tv/kraken/user"
end

#raw_infoObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/omniauth/strategies/twitchtv.rb', line 27

def raw_info
  get_hash_from_channel = lambda do |token|
    http_client = HTTPClient.new
    header = {"Authorization"=>"OAuth #{token}"}
    response = http_client.get(info_url, "", header)
    if response.code != "200" && response.code != 200
      raise Omniauth::Twitchtv::TwitchtvError.new("Failed to get user details from twitchtv")
    end
    response
  end
  @raw_info ||= JSON.parse(get_hash_from_channel.call(access_token.token).body)
end