Class: Swiftner::API::Channel

Inherits:
Service
  • Object
show all
Defined in:
lib/swiftner/API/channel.rb

Overview

Represents a Channel service responsible for finding, creating, updating and deleting channels. Inherits from the Service class. Provides methods for interacting with channel.

Constant Summary collapse

REQUIRED_ATTRIBUTES =
i[name type space_id].freeze

Instance Attribute Summary

Attributes inherited from Service

#client, #details, #id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Service

build, client, #initialize, map_collection, validate_required

Constructor Details

This class inherits a constructor from Swiftner::API::Service

Class Method Details

.create(attributes) ⇒ Swiftner::API::Channel

Parameters:

  • attributes (Hash)

Options Hash (attributes):

  • :name (String) — default: required
  • :type (String) — default: required
    • “audio”, “video” or “dual”

  • :space_id (Integer) — default: required
  • :description (String) — default: optional
  • :order (Integer) — default: optional

Returns:



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/swiftner/API/channel.rb', line 33

def self.create(attributes)
  validate_required(attributes, *REQUIRED_ATTRIBUTES)

  response = client.post(
    "/channel/create",
    body: attributes.to_json,
    headers: { "Content-Type" => "application/json" }
  )

  build(response.parsed_response)
end

.find(channel_id) ⇒ Swiftner::API::Channel

Finds channel by its id

Parameters:

  • channel_id (Integer)

Returns:



21
22
23
24
# File 'lib/swiftner/API/channel.rb', line 21

def self.find(channel_id)
  response = client.get("/channel/get/#{channel_id}")
  build(response.parsed_response)
end

.find_channelsArray<Swiftner::API::Channel>

Finds all channels

Returns:



13
14
15
16
# File 'lib/swiftner/API/channel.rb', line 13

def self.find_channels
  response = client.get("/channel/get-channels")
  map_collection(response)
end

Instance Method Details

#deleteHash

Deletes channel by its id

Returns:

  • (Hash)

    response



76
77
78
# File 'lib/swiftner/API/channel.rb', line 76

def delete
  client.delete("/channel/delete/#{id}")
end

#live?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
# File 'lib/swiftner/API/channel.rb', line 46

def live?
  client.get("/channel/is_channel_live?channel_id=#{id}")["status"] == "live"
rescue Swiftner::NotFound
  # ?Why does api return 404 when channel is not live?
  false
end

#update(attributes) ⇒ Swiftner::API::Channel

Parameters:

  • attributes (Hash)

Options Hash (attributes):

  • :name (String) — default: required
  • :type (String) — default: required
    • “audio”, “video” or “dual”

  • :space_id (Integer) — default: required
  • :description (String) — default: optional
  • :order (Integer) — default: optional

Returns:



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/swiftner/API/channel.rb', line 60

def update(attributes)
  attributes = attributes.transform_keys(&:to_s)
  @details = @details.merge(attributes)

  self.class.validate_required(@details, *REQUIRED_ATTRIBUTES)

  client.put(
    "/channel/update/#{id}",
    body: @details.to_json,
    headers: { "Content-Type" => "application/json" }
  )
  self
end