Class: Voyeurb::Stream

Inherits:
Base
  • Object
show all
Defined in:
lib/voyeurb/stream.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) ⇒ Stream

Returns a new instance of Stream.



7
8
9
10
11
12
13
14
15
16
# File 'lib/voyeurb/stream.rb', line 7

def initialize(attributes)
  @id = attributes["id"]
  @scheduled_start_time = attributes["scheduled_start_time"]
  @actual_start_time = attributes["actual_start_time"]
  @site = attributes["site"]
  @title = attributes["title"]
  @url = attributes["url"]
  @user = attributes["user"]
  @viewers = attributes["viewers"]
end

Instance Attribute Details

#actual_start_timeObject (readonly)

Returns the value of attribute actual_start_time.



4
5
6
# File 'lib/voyeurb/stream.rb', line 4

def actual_start_time
  @actual_start_time
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/voyeurb/stream.rb', line 4

def id
  @id
end

#scheduled_start_timeObject (readonly)

Returns the value of attribute scheduled_start_time.



4
5
6
# File 'lib/voyeurb/stream.rb', line 4

def scheduled_start_time
  @scheduled_start_time
end

#siteObject (readonly)

Returns the value of attribute site.



4
5
6
# File 'lib/voyeurb/stream.rb', line 4

def site
  @site
end

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/voyeurb/stream.rb', line 4

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



4
5
6
# File 'lib/voyeurb/stream.rb', line 4

def url
  @url
end

#userObject (readonly)

Returns the value of attribute user.



4
5
6
# File 'lib/voyeurb/stream.rb', line 4

def user
  @user
end

#viewersObject (readonly)

Returns the value of attribute viewers.



4
5
6
# File 'lib/voyeurb/stream.rb', line 4

def viewers
  @viewers
end

Class Method Details

.completedObject



37
38
39
40
41
42
43
44
# File 'lib/voyeurb/stream.rb', line 37

def self.completed
  # The endpoint for completed returns an error when trying to hit it the API
  # Will implement when is back working again.

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

.find(id) ⇒ Object

Raises:



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

def self.find(id)
  response = Faraday.get("#{ENDPOINT}/streams/#{id}")
  raise StreamNotFound unless response.success?
  attributes = JSON.parse(response.body)["data"]
  new(attributes)
end

.liveObject



25
26
27
28
29
# File 'lib/voyeurb/stream.rb', line 25

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

.upcomingObject



31
32
33
34
35
# File 'lib/voyeurb/stream.rb', line 31

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