Class: Voyeurb::Streamer

Inherits:
Base
  • Object
show all
Defined in:
lib/voyeurb/streamer.rb

Constant Summary

Constants inherited from Base

Base::ENDPOINT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Streamer

Returns a new instance of Streamer.



5
6
7
8
9
# File 'lib/voyeurb/streamer.rb', line 5

def initialize(attributes)
  @name = attributes["name"]
  @twitch = attributes["twitch"]
  @youtube = attributes["youtube"]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/voyeurb/streamer.rb', line 3

def name
  @name
end

#twitchObject (readonly)

Returns the value of attribute twitch.



3
4
5
# File 'lib/voyeurb/streamer.rb', line 3

def twitch
  @twitch
end

#youtubeObject (readonly)

Returns the value of attribute youtube.



3
4
5
# File 'lib/voyeurb/streamer.rb', line 3

def youtube
  @youtube
end

Class Method Details

.allObject



18
19
20
21
22
# File 'lib/voyeurb/streamer.rb', line 18

def self.all
  response = Faraday.get("#{ENDPOINT}/streamers")
  streamers = JSON.parse(response.body)["data"]
  streamers.map { |attributes| new(attributes) }
end

.by_name(name) ⇒ Object

Raises:



11
12
13
14
15
16
# File 'lib/voyeurb/streamer.rb', line 11

def self.by_name(name)
  response = Faraday.get("#{ENDPOINT}/streamers/#{name}")
  raise StreamerNotFound unless response.success?
  attributes = JSON.parse(response.body)["data"]
  new(attributes)
end

Instance Method Details

#completedObject



36
37
38
39
40
# File 'lib/voyeurb/streamer.rb', line 36

def completed
  response = Faraday.get("#{ENDPOINT}/streamers/#{name}/completed")
  streams = JSON.parse(response.body)["data"]
  streams.map { |attributes| Stream.new(attributes) }
end

#liveObject



24
25
26
27
28
# File 'lib/voyeurb/streamer.rb', line 24

def live
  response = Faraday.get("#{ENDPOINT}/streamers/#{name}/live")
  streams = JSON.parse(response.body)["data"]
  streams.map { |attributes| Stream.new(attributes) }
end

#upcomingObject



30
31
32
33
34
# File 'lib/voyeurb/streamer.rb', line 30

def upcoming
  response = Faraday.get("#{ENDPOINT}/streamers/#{name}/upcoming")
  streams = JSON.parse(response.body)["data"]
  streams.map { |attributes| Stream.new(attributes) }
end