lib/vidispine/api/client.rb in vidispine-1.5.0 vs lib/vidispine/api/client.rb in vidispine-1.5.1
- old
+ new
@@ -7,22 +7,31 @@
module API
class Client
attr_accessor :http_client, :request, :response, :logger
+ attr_accessor :api_endpoint_prefix, :api_noauth_endpoint_prefix
+
def initialize(args = { })
+
+ # API Path
+ @api_endpoint_prefix = args.fetch(:api_endpoint_prefix, 'API')
+
+ # APInoAuth Path
+ @api_noauth_endpoint_prefix = args.fetch(:api_noauth_endpoint_prefix, 'APInoauth')
+
@http_client = HTTPClient.new(args)
@logger = http_client.logger
end
def process_request(request, options = nil)
@response = nil
@request = request
request.client = self unless request.client
options ||= request.options
logger.warn { "Request is Missing Required Arguments: #{request.missing_required_arguments.inspect}" } unless request.missing_required_arguments.empty?
- @response = http_client.call_method(request.http_method, { :path => request.path, :query => request.query, :body => request.body }, options)
+ @response = http_client.build_and_send_request(request.http_method, { :path => request.path, :query => request.query, :body => request.body }, options)
end
def process_request_using_class(request_class, args, options = { })
@response = nil
@request = request_class.new(args, options.merge(:client => self))
@@ -135,32 +144,35 @@
collection_id = args.is_a?(String) ? args : begin
_data = Requests::BaseRequest.process_parameters([ { :name => :collection_id, :aliases => [ :id ] } ], args)
_args = _data[:arguments_out]
_args[:collection_id]
end
- http(:delete, "/collection/#{collection_id}")
+ path = File.join(api_endpoint_prefix, "/collection/#{collection_id}")
+ http(:delete, path)
end
# @see http://apidoc.vidispine.com/4.2/ref/collection.html#retrieve-the-contents-of-a-collection
def collection_get(args = { }, options = { })
collection_id = args.is_a?(String) ? args : begin
_data = Requests::BaseRequest.process_parameters([ { :name => :collection_id, :aliases => [ :id ] } ], args)
_args = _data[:arguments_out]
_args[:collection_id]
end
- http(:get, "/collection/#{collection_id}")
+ path = File.join(api_endpoint_prefix, "/collection/#{collection_id}")
+ http(:get, path)
end
alias :collection :collection_get
# @see http://apidoc.vidispine.com/4.2/ref/collection.html#retrieve-the-items-of-a-collection
def collection_items_get(args = { }, options = { })
collection_id = args.is_a?(String) ? args : begin
_data = Requests::BaseRequest.process_parameters([ { :name => :collection_id, :aliases => [ :id ] } ], args)
_args = _data[:arguments_out]
_args[:collection_id]
end
- http(:get, "collection/#{collection_id}/item")
+ path = File.join(api_endpoint_prefix, "collection/#{collection_id}/item")
+ http(:get, path)
end
alias :collection_items :collection_items_get
# @see http://apidoc.vidispine.com/4.2/ref/collection.html#retrieve-collection-metadata
@@ -168,11 +180,12 @@
collection_id = args.is_a?(String) ? args : begin
_data = Requests::BaseRequest.process_parameters([ { :name => :collection_id, :aliases => [ :id ] } ], args)
_args = _data[:arguments_out]
_args[:collection_id]
end
- http(:get, "/collection/#{collection_id}/metadata")
+ path = File.join(api_endpoint_prefix, "/collection/#{collection_id}/metadata")
+ http(:get, path)
end
# @see http://apidoc.vidispine.com/4.2/ref/collection.html#update-collection-metadata
def collection_metadata_set(args = { }, options = { })
process_request_using_class(Requests::CollectionMetadataSet, args, options)
@@ -315,11 +328,12 @@
item_id = args.is_a?(String) ? args : begin
_data = Requests::BaseRequest.process_parameters([ { :name => :item_id, :aliases => [ :id ] } ], args)
_args = _data[:arguments_out]
_args[:item_id]
end
- http(:get, "/item/#{item_id}/collections")
+ path = File.join(api_endpoint_prefix, "/item/#{item_id}/collections")
+ http(:get, path)
end
alias :item_collections :item_collections_get
# @see http://apidoc.vidispine.com/latest/ref/item/item.html#delete-a-single-item
def item_delete(args = { }, options = { })
@@ -502,11 +516,12 @@
query[:notification] = notification if notification
query[:notificationData] = notification_data if notification_data
query[:priority] = priority if priority
query[:jobmetadata] = job_metadata if job_metadata
- http(:post, "/item/#{item_id}/shape", '', :query => query)
+ path = File.join(api_endpoint_prefix, "/item/#{item_id}/shape")
+ http(:post, path, '', :query => query)
end
def item_sidecar_import(args = { }, options = { })
_request = Requests::BaseRequest.new(
args,
@@ -738,16 +753,18 @@
# @see http://apidoc.vidispine.com/4.2/ref/metadata/field.html#retrieve-terse-metadata-schema
def metadata_field_terse_schema(args = { }, options = { })
default_options = { :headers => { 'accept' => '*/*' } }
_options = default_options.merge(options)
- http(:get, 'metadata-field/terse-schema', _options)
+ path = File.join(api_endpoint_prefix, 'metadata-field/terse-schema')
+ http(:get, path, _options)
end
# @see http://apidoc.vidispine.com/4.2/ref/metadata/field.html#get--metadata-field
def metadata_fields_get(args = { }, options = { })
- http(:get, 'metadata-field', options)
+ path = File.join(api_endpoint_prefix, 'metadata-field')
+ http(:get, path, options)
end
alias :metadata_fields :metadata_fields_get
# @see http://apidoc.vidispine.com/latest/ref/search.html#id2
# @example search(:content => :metadata, :field => :title, :item_search_document => { :field => [ { :name => 'title', :value => [ { :value => 'something' } ] } ] } )
@@ -934,11 +951,12 @@
storage_id = args.is_a?(String) ? args : begin
_data = Requests::BaseRequest.process_parameters([ { :name => :storage_id, :aliases => [ :id ] } ], args)
_args = _data[:arguments_out]
_args[:storage_id]
end
- http(:post, "storage/#{storage_id ? "#{storage_id}/" : ''}rescan", '')
+ path = File.join(api_endpoint_prefix, "storage/#{storage_id ? "#{storage_id}/" : ''}rescan")
+ http(:post, path, '')
end
# @see http://apidoc.vidispine.com/4.2/ref/storage/storage.html#retrieve-list-of-storages
def storages_get(args = { }, options = { })
_request = Requests::BaseRequest.new(
@@ -959,10 +977,10 @@
process_request(_request, options)
end
alias :storages :storages_get
def version(args = { }, options = { })
- http(:get, 'API/version')
+ http(:get, File.join(api_endpoint_prefix, 'version'))
end
# @!endgroup API Endpoints
# ############################################################################################################## #
\ No newline at end of file