Class: Swiftner::API::Channel
- 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
Class Method Summary collapse
- .create(attributes) ⇒ Swiftner::API::Channel
-
.find(channel_id) ⇒ Swiftner::API::Channel
Finds channel by its id.
-
.find_channels ⇒ Array<Swiftner::API::Channel>
Finds all channels.
Instance Method Summary collapse
-
#delete ⇒ Hash
Deletes channel by its id.
- #live? ⇒ Boolean
- #update(attributes) ⇒ Swiftner::API::Channel
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
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
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_channels ⇒ Array<Swiftner::API::Channel>
Finds all channels
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
#delete ⇒ Hash
Deletes channel by its id
76 77 78 |
# File 'lib/swiftner/API/channel.rb', line 76 def delete client.delete("/channel/delete/#{id}") end |
#live? ⇒ 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
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 |