Class: Vmix::Api
- Inherits:
-
Object
show all
- Includes:
- HTTParty
- Defined in:
- lib/vmix/api.rb
Direct Known Subclasses
Client
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Api
Returns a new instance of Api.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Handle all methods from vmix
TODO: Better error handling
53
54
55
56
57
58
59
60
|
# File 'lib/vmix/api.rb', line 53
def method_missing(method, *args,&block)
puts "method: #{method}"
if valid_method?(method.to_s)
get(method.to_sym, *args)
else
raise NoMethodError, 'Invalid Vmix API Call'
end
end
|
Instance Method Details
#available_api_methods ⇒ Object
31
32
33
|
# File 'lib/vmix/api.rb', line 31
def available_api_methods
@valid_methods
end
|
#download_url(download_token, &block) ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/vmix/api.rb', line 21
def download_url(download_token, &block)
expires = block.nil? ? (Time.now + 6 * 24 * 60 * 60).to_i : block.call.to_i
digest = OpenSSL::Digest::Digest.new('sha1')
enc_string = "#{expires}\n#{self.api_password}\n/vmixcore/download?token=#{download_token}"
hmac = OpenSSL::HMAC.digest(digest,self.api_password,enc_string)
signature = URI.escape(Base64.encode64(hmac).strip)
download_url = "http://#{self.download_endpoint}?token=#{download_token}&expires=#{expires}&signature=#{signature}"
end
|
#valid_method?(method) ⇒ Boolean
35
36
37
38
39
40
41
42
|
# File 'lib/vmix/api.rb', line 35
def valid_method?(method)
method = method.to_s
if respond_to?(method)
return true
else
return !@valid_methods.select {|k,v| v.include? method}.empty?
end
end
|