zype 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zype.rb +3 -3
- data/lib/zype/base_model.rb +51 -2
- data/lib/zype/client.rb +6 -5
- data/lib/zype/models/encoders.rb +16 -5
- data/lib/zype/models/live_events.rb +12 -20
- data/lib/zype/models/playlists.rb +36 -0
- data/lib/zype/models/videos.rb +29 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9a2ea73f4d8fbd2a269eac9d311b23d7d0d0a2a0c008e8f95931241c030cc4e
|
4
|
+
data.tar.gz: 7fa7fc82ca88b6aaf5a0396b68b613fec84dd764892b21e8aca866f67b8f1274
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 561add775aca12eb095edd30a8d5b23b5d58b8603df5f2980922744cb87dad216325369ff72555cfc875ce84c985cdd04d04c7d76e4998ce48cca50739becf80
|
7
|
+
data.tar.gz: d1ca32fd59b69988dcbc3b3e7916c54986718959390bd63405400076df1a7aa4529fb2b839294b78e001d8bad8ea8493d19a1e981ed2d9121e11a80bc1228315
|
data/lib/zype.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'httparty'
|
2
|
-
require 'zype/configuration'
|
3
|
-
require 'zype/client'
|
4
|
-
require 'zype/base_model'
|
2
|
+
require './lib/zype/configuration.rb'
|
3
|
+
require './lib/zype/client.rb'
|
4
|
+
require './lib/zype/base_model.rb'
|
5
5
|
Dir[File.join(__dir__, '../lib/zype/models', '*.rb')].each { |file| require file }
|
6
6
|
|
7
7
|
module Zype
|
data/lib/zype/base_model.rb
CHANGED
@@ -1,9 +1,58 @@
|
|
1
1
|
module Zype
|
2
2
|
class BaseModel
|
3
|
-
attr_reader :client
|
3
|
+
attr_reader :client, :path
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
@client
|
6
|
+
@client = Client.new
|
7
|
+
@path = generate_path
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns all objects for given class
|
11
|
+
#
|
12
|
+
# @param params [Hash] the metadata to filter objects by
|
13
|
+
# @return [Array<Hash>] the objects returned from the API
|
14
|
+
def all(params: {})
|
15
|
+
client.execute(method: :get, path: "/#{path}", params: params)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns object matching ID
|
19
|
+
#
|
20
|
+
# @param id [String] the ID of the object
|
21
|
+
# @return [Hash] the object returned from the API
|
22
|
+
def find(id:)
|
23
|
+
client.execute(method: :get, path: "/#{path}/#{id}")
|
24
|
+
end
|
25
|
+
|
26
|
+
# Creates a new object via the API
|
27
|
+
#
|
28
|
+
# @param params [Hash] the properties of the object
|
29
|
+
# @return [Hash] the newly created object
|
30
|
+
def create(params:)
|
31
|
+
client.execute(method: :post, path: "/#{path}", params: params)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Updates an existing object via the API
|
35
|
+
#
|
36
|
+
# @param id [String] the ID of the object
|
37
|
+
# @param params [Hash] the properties to be updated
|
38
|
+
# @return [Hash] the updated object
|
39
|
+
def update(id:, params:)
|
40
|
+
client.execute(method: :put, path: "/#{path}/#{id}", params: params)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Deletes an existing object via the API
|
44
|
+
#
|
45
|
+
# @param id [String] the ID of the object
|
46
|
+
# @return [Hash] the deleted object
|
47
|
+
def delete(id:)
|
48
|
+
client.execute(method: :delete, path: "/#{path}/#{id}")
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def generate_path
|
54
|
+
split = self.class.name.split(/(?=[A-Z])/)
|
55
|
+
split[1..split.length].join('_').downcase
|
7
56
|
end
|
8
57
|
end
|
9
58
|
end
|
data/lib/zype/client.rb
CHANGED
@@ -16,12 +16,13 @@ module Zype
|
|
16
16
|
422 => UnprocessableEntity,
|
17
17
|
500 => ServerError
|
18
18
|
}.freeze
|
19
|
-
METHODS = %w(live_events encoders)
|
20
19
|
|
20
|
+
# Automatically converts all files in lib/zype/models to be used as methods
|
21
21
|
class << self
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
Dir["lib/zype/models/*"].each do |file|
|
23
|
+
model = file[/.*\/(.*?).rb$/, 1]
|
24
|
+
define_method model do
|
25
|
+
constant = model.split("_").map { |s| s.capitalize }.join("")
|
25
26
|
Module.const_get("Zype::#{constant}").new
|
26
27
|
end
|
27
28
|
end
|
@@ -53,7 +54,7 @@ module Zype
|
|
53
54
|
|
54
55
|
resp = self.send(method, path: path, params: params)
|
55
56
|
if resp.success?
|
56
|
-
resp['response']
|
57
|
+
resp['response'].nil? ? resp.parsed_response : resp['response']
|
57
58
|
else
|
58
59
|
error!(code: resp.code, message: resp['message'])
|
59
60
|
end
|
data/lib/zype/models/encoders.rb
CHANGED
@@ -1,20 +1,31 @@
|
|
1
1
|
module Zype
|
2
2
|
class Encoders < Zype::BaseModel
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
# Returns encoder matching the encoder_name
|
4
|
+
#
|
5
|
+
# @param encoder_name [String] the name of the encoder
|
6
|
+
# @return [Hash] properties of the encoder
|
8
7
|
def find(encoder_name:)
|
9
8
|
client.execute(method: :get, path: "/live/encoders/#{encoder_name}")
|
10
9
|
end
|
11
10
|
|
11
|
+
# Starts encoder matching the encoder_name
|
12
|
+
#
|
13
|
+
# @param encoder_name [String] the name of the encoder
|
14
|
+
# @return [Hash] properties of the encoder
|
12
15
|
def start(encoder_name:)
|
13
16
|
client.execute(method: :post, path: "/live/encoders/#{encoder_name}/start")
|
14
17
|
end
|
15
18
|
|
19
|
+
# Stops encoder matching the encoder_name
|
20
|
+
#
|
21
|
+
# @param encoder_name [String] the name of the encoder
|
22
|
+
# @return [Hash] properties of the encoder
|
16
23
|
def stop(encoder_name:)
|
17
24
|
client.execute(method: :post, path: "/live/encoders/#{encoder_name}/stop")
|
18
25
|
end
|
26
|
+
|
27
|
+
def path
|
28
|
+
@path = "live/encoders"
|
29
|
+
end
|
19
30
|
end
|
20
31
|
end
|
@@ -1,33 +1,25 @@
|
|
1
1
|
module Zype
|
2
2
|
class LiveEvents < Zype::BaseModel
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
def find(id:)
|
8
|
-
client.execute(method: :get, path: "/live_events/#{id}")
|
9
|
-
end
|
10
|
-
|
11
|
-
def create(params:)
|
12
|
-
client.execute(method: :post, path: '/live_events', params: params)
|
13
|
-
end
|
14
|
-
|
15
|
-
def update(id:, params:)
|
16
|
-
client.execute(method: :put, path: "/live_events/#{id}", params: params)
|
17
|
-
end
|
18
|
-
|
19
|
-
def delete(id:)
|
20
|
-
client.execute(method: :delete, path: "/live_events/#{id}")
|
21
|
-
end
|
22
|
-
|
3
|
+
# Starts broadcasting a live event
|
4
|
+
#
|
5
|
+
# @param id [String] the ID of the live event
|
6
|
+
# @return [Hash] the live event
|
23
7
|
def start(id:)
|
24
8
|
client.execute(method: :put, path: "/live_events/#{id}/start")
|
25
9
|
end
|
26
10
|
|
11
|
+
# Stops broadcasting a live event
|
12
|
+
#
|
13
|
+
# @param id [String] the ID of the live event
|
14
|
+
# @return [Hash] the live event
|
27
15
|
def stop(id:)
|
28
16
|
client.execute(method: :put, path: "/live_events/#{id}/stop")
|
29
17
|
end
|
30
18
|
|
19
|
+
# Archives the live event
|
20
|
+
#
|
21
|
+
# @param id [String] the ID of the live event
|
22
|
+
# @return [Hash] the live event
|
31
23
|
def archive(id:)
|
32
24
|
client.execute(method: :put, path: "/live_events/#{id}/archive")
|
33
25
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Zype
|
2
|
+
class Playlists < Zype::BaseModel
|
3
|
+
# Returns videos for a playlist
|
4
|
+
#
|
5
|
+
# @param id [String] the ID of the playlist
|
6
|
+
# @return [Array<Hash>] an array of video objects
|
7
|
+
def videos(id:)
|
8
|
+
client.execute(method: :get, path: "/playlists/#{id}/videos")
|
9
|
+
end
|
10
|
+
|
11
|
+
# Adds videos to a playlist
|
12
|
+
#
|
13
|
+
# @param id [String] the ID of the playlist
|
14
|
+
# @param video_ids [Array<String>] the video IDs to add to the playlist
|
15
|
+
# @return [Array<Hash>] an array of video objects
|
16
|
+
def add_videos(id:, video_ids:)
|
17
|
+
client.execute(method: :put, path: "/playlists/#{id}/add_videos", params: { video_id: video_ids })
|
18
|
+
end
|
19
|
+
|
20
|
+
# Removes videos from a playlist
|
21
|
+
#
|
22
|
+
# @param id [String] the ID of the playlist
|
23
|
+
# @param video_ids [Array<String>] the video IDs to remove to the playlist
|
24
|
+
# @return [Array<Hash>] an array of video objects
|
25
|
+
def remove_videos(id:, video_ids:)
|
26
|
+
client.execute(method: :put, path: "/playlists/#{id}/remove_videos", params: { video_id: video_ids })
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns all playlists from the API
|
30
|
+
#
|
31
|
+
# @return [Array<Hash>] all playlists in relational order
|
32
|
+
def relationships
|
33
|
+
client.execute(method: :get, path: '/playlists/relationships')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Zype
|
2
|
+
class Videos < Zype::BaseModel
|
3
|
+
# Adds zobjects to video
|
4
|
+
#
|
5
|
+
# @param id [String] the ID of the video
|
6
|
+
# @param zobject_ids [Array<String>] an array of zobject IDs
|
7
|
+
# @return [Hash] the video object
|
8
|
+
def add_zobjects(id:, zobject_ids:)
|
9
|
+
client.execute(method: :put, path: "/videos/#{id}/add_zobjects", params: { zobject_id: zobject_ids })
|
10
|
+
end
|
11
|
+
|
12
|
+
# Removes zobjects from video
|
13
|
+
#
|
14
|
+
# @param id [String] the ID of the video
|
15
|
+
# @param zobject_ids [Array<String>] an array of zobject IDs
|
16
|
+
# @return [Hash] the video object
|
17
|
+
def remove_zobjects(id:, zobject_ids:)
|
18
|
+
client.execute(method: :put, path: "/videos/#{id}/remove_zobjects", params: { zobject_id: zobject_ids })
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns the original source file for the video
|
22
|
+
#
|
23
|
+
# @param id [String] the ID of the video
|
24
|
+
# @return [Hash] object containing a "url" key for the original source file
|
25
|
+
def download(id:)
|
26
|
+
client.execute(method: :get, path: "/videos/#{id}/download")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zype
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zype
|
@@ -64,6 +64,8 @@ files:
|
|
64
64
|
- lib/zype/configuration.rb
|
65
65
|
- lib/zype/models/encoders.rb
|
66
66
|
- lib/zype/models/live_events.rb
|
67
|
+
- lib/zype/models/playlists.rb
|
68
|
+
- lib/zype/models/videos.rb
|
67
69
|
homepage: http://rubygems.org/gems/zype
|
68
70
|
licenses:
|
69
71
|
- MIT
|