zype 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 885c816e47a64af4e43d525e2bed585b63dd35f1c36a68702abed1eafcde4a44
4
+ data.tar.gz: 685efbc97e0c7e5cb6ebd69fd7c40805578ec1885c516113200c417fdab6956f
5
+ SHA512:
6
+ metadata.gz: 3fb60e5447dd3e54e9d68a091fb623353e19a92967fb8c83f92bbf9ea8c01793ebbc6a6cc9fb880edbfdd0800711f91e1bffb92d80a81263a2a8889b1e4c148b
7
+ data.tar.gz: '07874075097e67378d2e7660133fd5cb4e6276526e871712c3d92b9c7399eb73212bdcb8e2b35b0a56f60936958f1a21df0bb2224382476a15ec1cf8e505905c'
@@ -0,0 +1,18 @@
1
+ require 'httparty'
2
+ require 'pry'
3
+ require 'zype/configuration'
4
+ require 'zype/client'
5
+ require 'zype/base_model'
6
+ Dir[File.join(__dir__, '../lib/zype/models', '*.rb')].each { |file| require file }
7
+
8
+ module Zype
9
+ class << self
10
+ def configuration
11
+ @configuration ||= Configuration.new
12
+ end
13
+
14
+ def configure
15
+ yield(configuration)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module Zype
2
+ class BaseModel
3
+ attr_reader :client
4
+
5
+ def initialize
6
+ @client ||= Client.new
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,69 @@
1
+ module Zype
2
+ class Client
3
+ attr_reader :headers
4
+ include HTTParty
5
+ class NoApiKey < StandardError; end
6
+ class NotFound < StandardError; end
7
+ class ServerError < StandardError; end
8
+ class Unauthorized < StandardError; end
9
+ class UnprocessableEntity < StandardError; end
10
+
11
+ # for error types not explicity mapped
12
+ class GenericError < StandardError; end
13
+ ERROR_TYPES = {
14
+ 401 => Unauthorized,
15
+ 404 => NotFound,
16
+ 422 => UnprocessableEntity,
17
+ 500 => ServerError
18
+ }.freeze
19
+ METHODS = %w(live_events encoders)
20
+
21
+ class << self
22
+ METHODS.each do |method|
23
+ define_method method do
24
+ constant = method.split("_").map { |s| s.capitalize }.join("")
25
+ Module.const_get("Zype::#{constant}").new
26
+ end
27
+ end
28
+ end
29
+
30
+ def initialize
31
+ @headers = { "Content-Type" => "application/json", "x-zype-key" => Zype.configuration.api_key }
32
+ self.class.base_uri Zype.configuration.host
33
+ end
34
+
35
+ def get(path:, params: {})
36
+ self.class.get(path, { query: params, headers: headers })
37
+ end
38
+
39
+ def post(path:, params: {})
40
+ self.class.post(path, { query: params, headers: headers })
41
+ end
42
+
43
+ def put(path:, params: {})
44
+ self.class.put(path, { query: params, headers: headers })
45
+ end
46
+
47
+ def delete(path:, params: _)
48
+ self.class.delete(path, { headers: headers })
49
+ end
50
+
51
+ def execute(method:, path:, params: {})
52
+ raise NoApiKey if Zype.configuration.api_key.to_s.empty?
53
+
54
+ resp = self.send(method, path: path, params: params)
55
+ if resp.success?
56
+ resp['response']
57
+ else
58
+ error!(code: resp.code, message: resp['message'])
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def error!(code:, message:)
65
+ error_type = ERROR_TYPES[code] || GenericError
66
+ raise error_type.new(message)
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,10 @@
1
+ module Zype
2
+ class Configuration
3
+ attr_accessor :api_key, :host
4
+
5
+ def initialize
6
+ @api_key = nil
7
+ @host = 'api.zype.com'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ module Zype
2
+ class Encoders < Zype::BaseModel
3
+
4
+ def all
5
+ client.execute(method: :get, path: '/live/encoders')
6
+ end
7
+
8
+ def find(encoder_name:)
9
+ client.execute(method: :get, path: "/live/encoders/#{encoder_name}")
10
+ end
11
+
12
+ def start(encoder_name:)
13
+ client.execute(method: :post, path: "/live/encoders/#{encoder_name}/start")
14
+ end
15
+
16
+ def stop(encoder_name:)
17
+ client.execute(method: :post, path: "/live/encoders/#{encoder_name}/stop")
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ module Zype
2
+ class LiveEvents < Zype::BaseModel
3
+ def all(params: {})
4
+ client.execute(method: :get, path: '/live_events', params: params)
5
+ end
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
+
23
+ def start(id:)
24
+ client.execute(method: :put, path: "/live_events/#{id}/start")
25
+ end
26
+
27
+ def stop(id:)
28
+ client.execute(method: :put, path: "/live_events/#{id}/stop")
29
+ end
30
+
31
+ def archive(id:)
32
+ client.execute(method: :put, path: "/live_events/#{id}/archive")
33
+ end
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zype
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Zype
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.16'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ description: Ruby library to interact with the Zype Platform API
56
+ email:
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - lib/zype.rb
62
+ - lib/zype/base_model.rb
63
+ - lib/zype/client.rb
64
+ - lib/zype/configuration.rb
65
+ - lib/zype/models/encoders.rb
66
+ - lib/zype/models/live_events.rb
67
+ homepage: http://rubygems.org/gems/zype
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.7.3
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Zype Platform Gem
91
+ test_files: []