Class: Kinescope::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/kinescope/client.rb

Constant Summary collapse

DEFAULT_API_URL =
'https://api.kinescope.io'.freeze
DEFAULT_TIMEOUT =
120
DEFAULT_OPEN_TIMEOUT =
60

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
19
# File 'lib/kinescope/client.rb', line 13

def initialize(options = {})
  @access_token = options[:access_token]
  @api_url = options[:api_url] || DEFAULT_API_URL
  @open_timeout = options[:open_timeout] || DEFAULT_OPEN_TIMEOUT
  @timeout = options[:timeout] || DEFAULT_TIMEOUT
  @user_agent = options[:user_agent]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/kinescope/client.rb', line 41

def method_missing(name, *args, &block)
  if self.class.resources.keys.include?(name)
    resources[name] ||= self.class.resources[name].new(connection: connection)
    resources[name]
  else
    super
  end
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



11
12
13
# File 'lib/kinescope/client.rb', line 11

def access_token
  @access_token
end

#api_urlObject (readonly)

Returns the value of attribute api_url.



11
12
13
# File 'lib/kinescope/client.rb', line 11

def api_url
  @api_url
end

#open_timeoutObject (readonly)

Returns the value of attribute open_timeout.



11
12
13
# File 'lib/kinescope/client.rb', line 11

def open_timeout
  @open_timeout
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



11
12
13
# File 'lib/kinescope/client.rb', line 11

def timeout
  @timeout
end

#user_agentObject (readonly)

Returns the value of attribute user_agent.



11
12
13
# File 'lib/kinescope/client.rb', line 11

def user_agent
  @user_agent
end

Class Method Details

.resourcesObject



29
30
31
32
33
34
35
# File 'lib/kinescope/client.rb', line 29

def self.resources
  {
    drm: DRMResource,
    projects: ProjectResource,
    videos: VideoResource
  }
end

Instance Method Details

#connectionObject



21
22
23
24
25
26
27
# File 'lib/kinescope/client.rb', line 21

def connection
  @connection ||= Faraday.new(connection_options) do |req|
    req.adapter :net_http
    req.options.timeout = timeout
    req.options.open_timeout = open_timeout
  end
end

#default_user_agentObject



50
51
52
# File 'lib/kinescope/client.rb', line 50

def default_user_agent
  "kinescope-rb/#{Kinescope::VERSION}"
end

#resourcesObject



37
38
39
# File 'lib/kinescope/client.rb', line 37

def resources
  @resources ||= {}
end