Class: Swiftner::API::Service
- Inherits:
-
Object
- Object
- Swiftner::API::Service
- Defined in:
- lib/swiftner/API/service.rb
Overview
The ‘Service` class acts as a base class for API operations and data encapsulation.
Direct Known Subclasses
Channel, Chapter, LinkedContent, Meeting, Organisation, Space, Transcription, Upload, VideoContent
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
- .build(details) ⇒ Object
- .client ⇒ Object
- .map_collection(response) ⇒ Object
- .validate_required(attributes, *keys) ⇒ Object
Instance Method Summary collapse
-
#initialize(attributes = {}, client = self.class.client) ⇒ Service
constructor
A new instance of Service.
Constructor Details
#initialize(attributes = {}, client = self.class.client) ⇒ Service
Returns a new instance of Service.
30 31 32 33 34 35 36 |
# File 'lib/swiftner/API/service.rb', line 30 def initialize(attributes = {}, client = self.class.client) raise Swiftner::Error, "Client must be set" if client.nil? @id = attributes["id"] @details = attributes @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/swiftner/API/service.rb', line 7 def client @client end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
7 8 9 |
# File 'lib/swiftner/API/service.rb', line 7 def details @details end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/swiftner/API/service.rb', line 7 def id @id end |
Class Method Details
.build(details) ⇒ Object
9 10 11 |
# File 'lib/swiftner/API/service.rb', line 9 def self.build(details) new(details) end |
.client ⇒ Object
13 14 15 |
# File 'lib/swiftner/API/service.rb', line 13 def self.client Swiftner.configuration.client end |
.map_collection(response) ⇒ Object
26 27 28 |
# File 'lib/swiftner/API/service.rb', line 26 def self.map_collection(response) response.map { |item| build(item) } end |
.validate_required(attributes, *keys) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/swiftner/API/service.rb', line 17 def self.validate_required(attributes, *keys) attr_str_keys = attributes.transform_keys(&:to_s) missing_keys = keys.map(&:to_s).reject { |key| attr_str_keys.key?(key) } return unless missing_keys.any? raise ArgumentError, "Key(s) '#{missing_keys.join(", ")}' are missing in attributes. #{attributes.inspect}" end |