10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/cantemo/portal/api/client.rb', line 10
def self.new(args = { })
api_host = args[:host]
api_port = args[:port]
api_host_use_ssl = args[:ssl]
api_username = args[:username]
api_password = args[:password]
api_auth_token = args[:api_auth_token]
api_base_path = args[:api_base_path]
api_default_query_data = args[:default_query_data]
api_log_level = args[:log_level]
api_log_to = args[:log_to]
api_logger = args[:logger]
api_url = args[:url] || args[:uri]
if api_url
api_uri = URI(api_url)
api_host ||= api_uri.host
api_port ||= api_uri.port
api_userinfo = api_uri.userinfo
if api_userinfo
_api_username, _api_password = api_userinfo.split(':')
api_username ||= _api_username
api_password ||= _api_password
end
api_host_use_ssl = api_uri.scheme == 'https' if api_host_use_ssl.nil?
api_uri_query = api_uri.query
api_default_query_data ||= Hash[api_uri_query.split('&').map { |kp| kp.split('=') }]
api_base_path ||= api_uri.path
end
api_port ||= (api_host_use_ssl ? 443 : 80)
api_base_path ||= '/'
api_endpoint_prefix = 'VSAPI'
api_noauth_endpoint_prefix = 'APInoauth'
client_args = {}
client_args[:http_host_address] = api_host if api_host
client_args[:http_host_port] = api_port if api_port
client_args[:http_host_use_ssl] = api_host_use_ssl if api_host_use_ssl
client_args[:username] = api_username if api_username
client_args[:password] = api_password if api_password
client_args[:default_base_path] = api_base_path if api_base_path
client_args[:default_query_data] = api_default_query_data if api_default_query_data
client_args[:api_endpoint_prefix] = api_endpoint_prefix
client_args[:api_noauth_endpoint_prefix] = api_noauth_endpoint_prefix
client_args[:log_level] = api_log_level if api_log_level
client_args[:log_to] = api_log_to if api_log_to
client_args[:logger] = api_logger if api_logger
if api_auth_token
client_args[:authorization_header_key] = 'Auth-Token'
client_args[:authorization_header_value] = api_auth_token
end
_client = ::Vidispine::API::Utilities.new(client_args)
_client.http_client.user_agent = "Cantemo Portal Agent v#{Cantemo::Portal::Agent::VERSION} - #{_client.http_client.user_agent}"
_client
end
|