Class: Zype::BaseModel
- Inherits:
-
Object
- Object
- Zype::BaseModel
- Defined in:
- lib/zype/base_model.rb
Direct Known Subclasses
AdTags, Apps, Zype::Base::Categories, Zype::Base::Consumers, Zype::Base::Playlists, Zype::Base::Videos, Categories, Consumers, DeviceCategories, Devices, Encoders, GeoIp, LiveEvents, LiveManifests, Manifests, Oauth, Pin, Plans, Players, Playlists, ProgramGuides, RedemptionCodes, RevenueModels, Subscriptions, Subtitles, Transactions, Users, VideoImports, VideoSources, Videos, ZobjectTypes, Zobjects
Defined Under Namespace
Classes: InvalidKey
Constant Summary collapse
- ACCEPTED_KEYS =
%i(api_key app_key)
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#all(params: {}) ⇒ Array<Hash>
Returns all objects for given class.
-
#auth=(auth_method) ⇒ Object
Sets the authentication method for calling the API.
-
#create(params:) ⇒ Hash
Creates a new object via the API.
-
#delete(id:) ⇒ Hash
Deletes an existing object via the API.
-
#find(id:) ⇒ Hash
Returns object matching ID.
-
#initialize(auth_method = 'api_key') ⇒ BaseModel
constructor
A new instance of BaseModel.
-
#update(id:, params:) ⇒ Hash
Updates an existing object via the API.
Constructor Details
#initialize(auth_method = 'api_key') ⇒ BaseModel
Returns a new instance of BaseModel.
7 8 9 10 |
# File 'lib/zype/base_model.rb', line 7 def initialize(auth_method='api_key') @client = client_class.new(auth_method) @path = generate_path end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/zype/base_model.rb', line 3 def client @client end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/zype/base_model.rb', line 3 def path @path end |
Instance Method Details
#all(params: {}) ⇒ Array<Hash>
Returns all objects for given class
16 17 18 |
# File 'lib/zype/base_model.rb', line 16 def all(params: {}) client.execute(method: :get, path: "/#{path}", params: params) end |
#auth=(auth_method) ⇒ Object
Sets the authentication method for calling the API
56 57 58 59 60 |
# File 'lib/zype/base_model.rb', line 56 def auth=(auth_method) raise InvalidKey unless ACCEPTED_KEYS.include?(auth_method.to_sym) @client = client_class.new(auth_method) end |
#create(params:) ⇒ Hash
Creates a new object via the API
32 33 34 |
# File 'lib/zype/base_model.rb', line 32 def create(params:) client.execute(method: :post, path: "/#{path}", params: params) end |
#delete(id:) ⇒ Hash
Deletes an existing object via the API
49 50 51 |
# File 'lib/zype/base_model.rb', line 49 def delete(id:) client.execute(method: :delete, path: "/#{path}/#{id}") end |
#find(id:) ⇒ Hash
Returns object matching ID
24 25 26 |
# File 'lib/zype/base_model.rb', line 24 def find(id:) client.execute(method: :get, path: "/#{path}/#{id}") end |
#update(id:, params:) ⇒ Hash
Updates an existing object via the API
41 42 43 |
# File 'lib/zype/base_model.rb', line 41 def update(id:, params:) client.execute(method: :put, path: "/#{path}/#{id}", params: params) end |