vidispine 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b384b244a314c8b4323b69ccc16c7824ae52ac2d
4
- data.tar.gz: 1df54b7818102417191b43ba2be89e5b2c38ba2a
3
+ metadata.gz: fad78c8b766bf87d952d77f3a73a667d887b064f
4
+ data.tar.gz: eb13dce39554cdd7a0b4b1b00e212ecb7a5abe72
5
5
  SHA512:
6
- metadata.gz: ae8d940adecdc9e174b60116ec9d911701b9e6796092261c4afb1917d03dae57368a8b8f5a5adbed4c5bdb55b94ac0c6370a61c41ec4e8a6405dbea71136ed1e
7
- data.tar.gz: 5452d7e0cedb685b8874a352fc73709669e753a298c263eac6ae115b489c41982e6e397bb296444351aab9c43293750c57e6d11c5d0f1dec8a27210bc494d393
6
+ metadata.gz: 18a6979587fe7a8d85f90dcb248c7cb45558e6d8393a0064a921fa6d8000a7206b33b5f9d483f5bf5fee1ff7d074cfd6905e58b8849f3e9989361991efed13bf
7
+ data.tar.gz: 867ace58974e2d2615bfba584b00585010db7438aeff9dd6dc6c520944898be4990d7f3b9409fd1370e45662340e535885523501245c39526b244656d97a5c86
@@ -9,7 +9,16 @@ module Vidispine
9
9
 
10
10
  attr_accessor :http_client, :request, :response, :logger
11
11
 
12
+ attr_accessor :api_endpoint_prefix, :api_noauth_endpoint_prefix
13
+
12
14
  def initialize(args = { })
15
+
16
+ # API Path
17
+ @api_endpoint_prefix = args.fetch(:api_endpoint_prefix, 'API')
18
+
19
+ # APInoAuth Path
20
+ @api_noauth_endpoint_prefix = args.fetch(:api_noauth_endpoint_prefix, 'APInoauth')
21
+
13
22
  @http_client = HTTPClient.new(args)
14
23
  @logger = http_client.logger
15
24
  end
@@ -20,7 +29,7 @@ module Vidispine
20
29
  request.client = self unless request.client
21
30
  options ||= request.options
22
31
  logger.warn { "Request is Missing Required Arguments: #{request.missing_required_arguments.inspect}" } unless request.missing_required_arguments.empty?
23
- @response = http_client.call_method(request.http_method, { :path => request.path, :query => request.query, :body => request.body }, options)
32
+ @response = http_client.build_and_send_request(request.http_method, { :path => request.path, :query => request.query, :body => request.body }, options)
24
33
  end
25
34
 
26
35
  def process_request_using_class(request_class, args, options = { })
@@ -137,7 +146,8 @@ module Vidispine
137
146
  _args = _data[:arguments_out]
138
147
  _args[:collection_id]
139
148
  end
140
- http(:delete, "/collection/#{collection_id}")
149
+ path = File.join(api_endpoint_prefix, "/collection/#{collection_id}")
150
+ http(:delete, path)
141
151
  end
142
152
 
143
153
  # @see http://apidoc.vidispine.com/4.2/ref/collection.html#retrieve-the-contents-of-a-collection
@@ -147,7 +157,8 @@ module Vidispine
147
157
  _args = _data[:arguments_out]
148
158
  _args[:collection_id]
149
159
  end
150
- http(:get, "/collection/#{collection_id}")
160
+ path = File.join(api_endpoint_prefix, "/collection/#{collection_id}")
161
+ http(:get, path)
151
162
  end
152
163
  alias :collection :collection_get
153
164
 
@@ -158,7 +169,8 @@ module Vidispine
158
169
  _args = _data[:arguments_out]
159
170
  _args[:collection_id]
160
171
  end
161
- http(:get, "collection/#{collection_id}/item")
172
+ path = File.join(api_endpoint_prefix, "collection/#{collection_id}/item")
173
+ http(:get, path)
162
174
  end
163
175
  alias :collection_items :collection_items_get
164
176
 
@@ -170,7 +182,8 @@ module Vidispine
170
182
  _args = _data[:arguments_out]
171
183
  _args[:collection_id]
172
184
  end
173
- http(:get, "/collection/#{collection_id}/metadata")
185
+ path = File.join(api_endpoint_prefix, "/collection/#{collection_id}/metadata")
186
+ http(:get, path)
174
187
  end
175
188
 
176
189
  # @see http://apidoc.vidispine.com/4.2/ref/collection.html#update-collection-metadata
@@ -317,7 +330,8 @@ module Vidispine
317
330
  _args = _data[:arguments_out]
318
331
  _args[:item_id]
319
332
  end
320
- http(:get, "/item/#{item_id}/collections")
333
+ path = File.join(api_endpoint_prefix, "/item/#{item_id}/collections")
334
+ http(:get, path)
321
335
  end
322
336
  alias :item_collections :item_collections_get
323
337
 
@@ -504,7 +518,8 @@ module Vidispine
504
518
  query[:priority] = priority if priority
505
519
  query[:jobmetadata] = job_metadata if job_metadata
506
520
 
507
- http(:post, "/item/#{item_id}/shape", '', :query => query)
521
+ path = File.join(api_endpoint_prefix, "/item/#{item_id}/shape")
522
+ http(:post, path, '', :query => query)
508
523
  end
509
524
 
510
525
  def item_sidecar_import(args = { }, options = { })
@@ -740,12 +755,14 @@ module Vidispine
740
755
  def metadata_field_terse_schema(args = { }, options = { })
741
756
  default_options = { :headers => { 'accept' => '*/*' } }
742
757
  _options = default_options.merge(options)
743
- http(:get, 'metadata-field/terse-schema', _options)
758
+ path = File.join(api_endpoint_prefix, 'metadata-field/terse-schema')
759
+ http(:get, path, _options)
744
760
  end
745
761
 
746
762
  # @see http://apidoc.vidispine.com/4.2/ref/metadata/field.html#get--metadata-field
747
763
  def metadata_fields_get(args = { }, options = { })
748
- http(:get, 'metadata-field', options)
764
+ path = File.join(api_endpoint_prefix, 'metadata-field')
765
+ http(:get, path, options)
749
766
  end
750
767
  alias :metadata_fields :metadata_fields_get
751
768
 
@@ -936,7 +953,8 @@ module Vidispine
936
953
  _args = _data[:arguments_out]
937
954
  _args[:storage_id]
938
955
  end
939
- http(:post, "storage/#{storage_id ? "#{storage_id}/" : ''}rescan", '')
956
+ path = File.join(api_endpoint_prefix, "storage/#{storage_id ? "#{storage_id}/" : ''}rescan")
957
+ http(:post, path, '')
940
958
  end
941
959
 
942
960
  # @see http://apidoc.vidispine.com/4.2/ref/storage/storage.html#retrieve-list-of-storages
@@ -961,7 +979,7 @@ module Vidispine
961
979
  alias :storages :storages_get
962
980
 
963
981
  def version(args = { }, options = { })
964
- http(:get, 'API/version')
982
+ http(:get, File.join(api_endpoint_prefix, 'version'))
965
983
  end
966
984
 
967
985
  # @!endgroup API Endpoints
@@ -25,7 +25,7 @@ module Vidispine
25
25
 
26
26
  DEFAULT_USERNAME = 'admin'
27
27
  DEFAULT_PASSWORD = 'password'
28
- DEFAULT_BASE_PATH = 'API/'
28
+ DEFAULT_BASE_PATH = '/'
29
29
 
30
30
  DEFAULT_HEADER_CONTENT_TYPE = 'application/json; charset=utf-8'
31
31
  DEFAULT_HEADER_ACCEPTS = 'application/json'
@@ -40,19 +40,21 @@ module Vidispine
40
40
 
41
41
  logger.debug { "#{self.class.name}::#{__method__} Arguments: #{args.inspect}" }
42
42
 
43
- @username = args[:username] || DEFAULT_USERNAME
44
- @password = args[:password] || DEFAULT_PASSWORD
45
- @authorization_header_value = args[:authorization_header_value]
46
-
47
43
  @base_uri = args[:base_uri] || "http#{http.use_ssl? ? 's' : ''}://#{http.address}:#{http.port}"
48
- @default_base_path = args[:default_base_path] || DEFAULT_BASE_PATH
44
+ @default_base_path = args.fetch(:default_base_path, DEFAULT_BASE_PATH)
49
45
 
50
46
  @default_query_data = args[:default_query_data] || { }
51
47
 
52
48
  # @user_agent_default = "#{@hostname}:#{@username} Ruby SDK Version #{Vidispine::VERSION}"
53
49
 
54
- @authorization_header_key ||= 'Authorization' #CaseSensitiveHeaderKey.new('Authorization')
55
- @authorization_header_value ||= %(Basic #{["#{username}:#{password}"].pack('m').delete("\r\n")})
50
+ @username = args[:username] || DEFAULT_USERNAME
51
+ @password = args[:password] || DEFAULT_PASSWORD
52
+
53
+ @authorization_header_key = args.fetch(:authorization_header_key, 'Authorization')
54
+ @authorization_header_value = args.fetch(:authorization_header_value,
55
+ %(Basic #{["#{username}:#{password}"]
56
+ .pack('m')
57
+ .delete("\r\n")}))
56
58
 
57
59
  content_type = args[:content_type_header] ||= DEFAULT_HEADER_CONTENT_TYPE
58
60
  accepts = args[:accepts_header] ||= args[:accept_header] || DEFAULT_HEADER_ACCEPTS
@@ -144,13 +146,26 @@ module Vidispine
144
146
  end
145
147
  end
146
148
 
149
+ # Compiles a full URI
150
+ #
147
151
  # @param [String] path
148
152
  # @param [Hash|String|Nil] query
153
+ # @param [Hash] options
154
+ # @option options [Hash] :default_query_data
155
+ # @option options [Hash] :default_base_path
156
+ #
149
157
  # @return [URI]
150
- def build_uri(path = '', query = nil)
151
- _query = query.is_a?(Hash) ? default_query_data.merge(query.map { |k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.respond_to?(:to_s) ? v.to_s : v)}" }.join('&')) : query
158
+ def build_uri(path = '', query = nil, options = { })
159
+ _default_query_data = options.fetch(:default_query_data, default_query_data) || { }
160
+ _default_base_path = options.fetch(:default_base_path, default_base_path)
161
+
162
+ query = { } if query.nil?
163
+
164
+ _query = query.is_a?(Hash) ? (default_query_data.merge(query)).map { |k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.respond_to?(:to_s) ? v.to_s : v)}" }.join('&') : query
152
165
  _path = "#{path}#{_query and _query.respond_to?(:empty?) and !_query.empty? ? "?#{_query}" : ''}"
153
- URI.parse(File.join(base_uri, _path))
166
+ _path = File.join(_default_base_path, _path) if _default_base_path
167
+ _path = File.join(base_uri, _path)
168
+ URI.parse(_path)
154
169
  end
155
170
 
156
171
  if RUBY_VERSION.start_with? '1.8.'
@@ -163,6 +178,8 @@ module Vidispine
163
178
  end
164
179
  end
165
180
 
181
+ # Builds the HTTP request
182
+ #
166
183
  # @param [Symbol] method_name (:get)
167
184
  # @param [Hash] args
168
185
  # @option args [Hash] :headers ({})
@@ -171,7 +188,7 @@ module Vidispine
171
188
  # @option args [Any] :body (nil)
172
189
  # @param [Hash] options
173
190
  # @option options [Hash] :default_request_headers (@default_request_headers)
174
- def call_method(method_name = :get, args = { }, options = { })
191
+ def build_request(method_name = :get, args = { }, options = { })
175
192
  headers = args[:headers] || options[:headers] || { }
176
193
  path = args[:path] || ''
177
194
  query = args[:query] || { }
@@ -182,102 +199,59 @@ module Vidispine
182
199
  _default_request_headers ||= { }
183
200
  _headers = _default_request_headers.merge(headers)
184
201
 
185
- @uri = build_uri(path, query)
202
+ @uri = build_uri(path, query, options)
186
203
  klass_name = request_method_name_to_class_name(method_name)
187
204
  klass = Net::HTTP.const_get(klass_name)
188
205
 
189
- request = klass.new(@uri.request_uri, _headers)
206
+ _request = klass.new(@uri.request_uri, _headers)
190
207
 
191
- if request.request_body_permitted?
208
+ if _request.request_body_permitted?
192
209
  _body = (body and !body.is_a?(String)) ? JSON.generate(body) : body
193
210
  logger.debug { "Processing Body: '#{_body}'" }
194
- request.body = _body if _body
211
+ _request.body = _body if _body
195
212
  end
196
213
 
197
- send_request(request)
214
+ _request
215
+ end
216
+
217
+ # First builds and then sends the HTTP request
218
+ #
219
+ # @param [Symbol] method_name (:get)
220
+ # @param [Hash] args
221
+ # @option args [Hash] :headers ({})
222
+ # @option args [String] :path ('')
223
+ # @option args [Hash] :query ({})
224
+ # @option args [Any] :body (nil)
225
+ #
226
+ # @param [Hash] options
227
+ # @option options [Hash] :default_request_headers (@default_request_headers)
228
+ def build_and_send_request(method_name = :get, args = { }, options = { })
229
+ _request = build_request(method_name, args, options)
230
+ send_request(_request)
198
231
  end
199
232
 
200
233
  def delete(path, options = { })
201
- query = options.fetch(:query, { })
202
- base_path = options[:base_path] || ( path.start_with?(@default_base_path) ? '' : @default_base_path )
203
- @uri = build_uri(File.join(base_path, path), query)
204
- request = Net::HTTP::Delete.new(@uri.request_uri, default_request_headers)
205
- send_request(request)
234
+ build_and_send_request(:delete, { :path => path }, options)
206
235
  end
207
236
 
208
237
  def get(path, options = { })
209
- # Allow the default request headers to be overridden
210
- headers = options[:headers] || { }
211
- _default_request_headers = options.fetch(:default_request_headers, default_request_headers) || { }
212
- _headers = _default_request_headers.merge(headers)
213
-
214
- query ||= options.fetch(:query, { })
215
- base_path = options[:base_path] || ( path.start_with?(@default_base_path) ? '' : @default_base_path )
216
- @uri = build_uri(File.join(base_path, path), query)
217
- request = Net::HTTP::Get.new(@uri.request_uri, _headers)
218
- send_request(request)
238
+ build_and_send_request(:get, { :path => path }, options)
219
239
  end
220
240
 
221
241
  def head(path, options = { })
222
- # Allow the default request headers to be overridden
223
- headers = options[:headers] || { }
224
- _default_request_headers = options.fetch(:default_request_headers, default_request_headers) || { }
225
- _headers = _default_request_headers.merge(headers)
226
-
227
- query ||= options.fetch(:query, { })
228
- base_path = options[:base_path] || ( path.start_with?(@default_base_path) ? '' : @default_base_path )
229
- @uri = build_uri(File.join(base_path, path), query)
230
-
231
- request = Net::HTTP::Head.new(@uri.request_uri, _headers)
232
- send_request(request)
242
+ build_and_send_request(:head, { :path => path }, options)
233
243
  end
234
244
 
235
245
  def options(path, options = { })
236
- # Allow the default request headers to be overridden
237
- headers = options[:headers] || { }
238
- _default_request_headers = options.fetch(:default_request_headers, default_request_headers) || { }
239
- _headers = _default_request_headers.merge(headers)
240
-
241
- query ||= options.fetch(:query, { })
242
- base_path = options[:base_path] || ( path.start_with?(@default_base_path) ? '' : @default_base_path )
243
- @uri = build_uri(File.join(base_path, path), query)
244
- request = Net::HTTP::Options.new(@uri.request_uri, _headers)
245
- send_request(request)
246
+ build_and_send_request(:options, { :path => path }, options)
246
247
  end
247
248
 
248
249
  def put(path, body, options = { })
249
- # Allow the default request headers to be overridden
250
- headers = options[:headers] || { }
251
- _default_request_headers = options.fetch(:default_request_headers, default_request_headers) || { }
252
- _headers = _default_request_headers.merge(headers)
253
-
254
- query = options.fetch(:query, { })
255
- base_path = options[:base_path] || ( path.start_with?(@default_base_path) ? '' : @default_base_path )
256
- @uri = build_uri(File.join(base_path, path), query)
257
- request = Net::HTTP::Put.new(@uri.request_uri, _headers)
258
-
259
- body = JSON.generate(body) if body and !body.is_a?(String)
260
-
261
- request.body = body if body
262
- send_request(request)
250
+ build_and_send_request(:put, { :path => path, :body => body }, options)
263
251
  end
264
252
 
265
253
  def post(path, body, options = { })
266
- # Allow the default request headers to be overridden
267
- headers = options[:headers] || { }
268
- _default_request_headers = options.fetch(:default_request_headers, default_request_headers) || { }
269
- _headers = _default_request_headers.merge(headers)
270
-
271
- query = options.fetch(:query, { })
272
- base_path = options[:base_path] || ( path.start_with?(@default_base_path) ? '' : @default_base_path )
273
- @uri = build_uri(File.join(base_path, path), query)
274
-
275
- request = Net::HTTP::Post.new(@uri.request_uri, _headers)
276
-
277
- body = JSON.generate(body) if body and !body.is_a?(String)
278
-
279
- request.body = body if body
280
- send_request(request)
254
+ build_and_send_request(:post, { :path => path, :body => body }, options)
281
255
  end
282
256
 
283
257
  # HTTPClient
@@ -9,7 +9,7 @@ module Vidispine
9
9
  class BaseRequest
10
10
 
11
11
  HTTP_METHOD = :get
12
- HTTP_BASE_PATH = '/API/'
12
+ HTTP_BASE_PATH = '/API/' # Not used, using client.api_endpoint_prefix instead
13
13
  HTTP_PATH = ''
14
14
  HTTP_SUCCESS_CODE = '200'
15
15
 
@@ -150,7 +150,7 @@ module Vidispine
150
150
  end
151
151
 
152
152
  def base_path
153
- @base_path ||= self.class::HTTP_BASE_PATH
153
+ @base_path ||= client.api_endpoint_prefix # self.class::HTTP_BASE_PATH
154
154
  end
155
155
 
156
156
  def body_arguments
@@ -1,3 +1,3 @@
1
1
  module Vidispine
2
- VERSION = '1.5.0'
2
+ VERSION = '1.5.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vidispine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Whitson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-20 00:00:00.000000000 Z
11
+ date: 2018-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler