Class: Cathodic::TwitchData

Inherits:
Object
  • Object
show all
Defined in:
lib/cathodic.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, embed_width = 640, embed_height = 360) ⇒ TwitchData

Returns a new instance of TwitchData.



17
18
19
20
21
22
23
24
25
# File 'lib/cathodic.rb', line 17

def initialize(url, embed_width = 640, embed_height = 360)
	@entry_point = "https://api.twitch.tv/kraken"
	@url = url
	
	@query_point = @entry_point + "/streams/" + @account_name
   @embed_width = embed_width
   @embed_height = embed_height
	extract_data
end

Instance Attribute Details

#account_nameObject

Returns the value of attribute account_name.



15
16
17
# File 'lib/cathodic.rb', line 15

def 
  @account_name
end

Returns the value of attribute banner.



15
16
17
# File 'lib/cathodic.rb', line 15

def banner
  @banner
end

#chatObject

Returns the value of attribute chat.



15
16
17
# File 'lib/cathodic.rb', line 15

def chat
  @chat
end

#embedObject

Returns the value of attribute embed.



15
16
17
# File 'lib/cathodic.rb', line 15

def embed
  @embed
end

#embed_heightObject

Returns the value of attribute embed_height.



15
16
17
# File 'lib/cathodic.rb', line 15

def embed_height
  @embed_height
end

#embed_widthObject

Returns the value of attribute embed_width.



15
16
17
# File 'lib/cathodic.rb', line 15

def embed_width
  @embed_width
end

#entry_pointObject

Returns the value of attribute entry_point.



15
16
17
# File 'lib/cathodic.rb', line 15

def entry_point
  @entry_point
end

#gameObject

Returns the value of attribute game.



15
16
17
# File 'lib/cathodic.rb', line 15

def game
  @game
end

#logoObject

Returns the value of attribute logo.



15
16
17
# File 'lib/cathodic.rb', line 15

def 
  @logo
end

#onlineObject

Returns the value of attribute online.



15
16
17
# File 'lib/cathodic.rb', line 15

def online
  @online
end

#statusObject

Returns the value of attribute status.



15
16
17
# File 'lib/cathodic.rb', line 15

def status
  @status
end

#stream_nameObject

Returns the value of attribute stream_name.



15
16
17
# File 'lib/cathodic.rb', line 15

def stream_name
  @stream_name
end

#thumbnailObject

Returns the value of attribute thumbnail.



15
16
17
# File 'lib/cathodic.rb', line 15

def thumbnail
  @thumbnail
end

#urlObject

Returns the value of attribute url.



15
16
17
# File 'lib/cathodic.rb', line 15

def url
  @url
end

#viewersObject

Returns the value of attribute viewers.



15
16
17
# File 'lib/cathodic.rb', line 15

def viewers
  @viewers
end

Instance Method Details

#refresh_dataObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cathodic.rb', line 27

def refresh_data
  answer_string = open(@query_point).read
  parsed_answer = JSON.parse(answer_string)

  if parsed_answer["stream"] == nil
    @online = false
  else
    @online = true
    stream = parsed_answer.fetch("stream")
    channel = stream.fetch("channel")
    @game = stream["game"]
    @viewers = stream["viewers"]
    @status = channel["status"]
  end
end