vidispine 1.4.0 → 1.5.0

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
- SHA256:
3
- metadata.gz: 4d9919ba4f728d001342ea3e8c254eed8ecd59ae29a4fbf759b8faefac79fcfd
4
- data.tar.gz: 1b4f5580669b0ed5edc15692f2d7deb19e6616ab1c8b98e2e52802e9e256b001
2
+ SHA1:
3
+ metadata.gz: b384b244a314c8b4323b69ccc16c7824ae52ac2d
4
+ data.tar.gz: 1df54b7818102417191b43ba2be89e5b2c38ba2a
5
5
  SHA512:
6
- metadata.gz: b7359a1382a8edeb9b33ec53178c4f9588a70b363378bc292cfe0f12a41260771b1b3b5e77603c86a7eae34bf1b5d6458fd1e361cd660771dfbeb023b8a0eea9
7
- data.tar.gz: f97825f0cb2874fe8445dc98b8766b47750f41bf89f6b64586f974838970e8a334fd9fc58e235edbf45771824c19141f0fd2d3ef945bd846f2163522b8bfd644
6
+ metadata.gz: ae8d940adecdc9e174b60116ec9d911701b9e6796092261c4afb1917d03dae57368a8b8f5a5adbed4c5bdb55b94ac0c6370a61c41ec4e8a6405dbea71136ed1e
7
+ data.tar.gz: 5452d7e0cedb685b8874a352fc73709669e753a298c263eac6ae115b489c41982e6e397bb296444351aab9c43293750c57e6d11c5d0f1dec8a27210bc494d393
data/Gemfile CHANGED
@@ -1,7 +1,5 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'aws-sdk-s3', '~> 1'
4
-
5
3
  gem 'json', '~> 1.8', :platforms => :mri_18
6
4
  # gem 'mini_portile', '~> 0.5.0', :platforms => :mri_18
7
5
  # gem 'mime-types', '~> 1.25.1', :platforms => :mri_18
@@ -4,239 +4,14 @@ require 'logger'
4
4
  require 'optparse'
5
5
  require 'pp'
6
6
 
7
- ARGV << '--uri'
8
- ARGV << 'https://o6h5m0r0ih.execute-api.us-east-1.amazonaws.com/latest/vidispine/notification'
9
- ARGV << '{changeSetId=[VX-460], userName=[admin], itemId=[VX-90], portal_mf201890=[3], sequenceNumber=[0]}'
10
- puts 'Arguments:'
11
- pp ARGV
12
-
13
-
14
7
  module Vidispine
15
8
 
16
- class HTTPClient
17
-
18
- class HTTPAuthorizationError < RuntimeError; end
19
-
20
- attr_accessor :logger, :http, :http_host_address, :http_host_port, :base_uri, :default_base_path
21
- attr_accessor :username, :password
22
-
23
- attr_accessor :default_request_headers,
24
- :authorization_header_key, :authorization_header_value
25
-
26
- attr_accessor :log_request_body, :log_response_body, :log_pretty_print_body
27
-
28
- attr_accessor :request, :response, :use_exceptions
29
-
30
- DEFAULT_HTTP_HOST_ADDRESS = 'localhost'
31
- DEFAULT_HTTP_HOST_PORT = 80
32
-
33
- DEFAULT_USERNAME = ''
34
- DEFAULT_PASSWORD = ''
35
- DEFAULT_BASE_PATH = '/'
36
-
37
- DEFAULT_HEADER_CONTENT_TYPE = 'application/json; charset=utf-8'
38
- DEFAULT_HEADER_ACCEPTS = 'application/json'
39
-
40
- def initialize(args = { })
41
- args = args.dup
42
-
43
- @use_exceptions = args.fetch(:use_exceptions, true)
44
-
45
- initialize_logger(args)
46
- initialize_http(args)
47
-
48
- logger.debug { "#{self.class.name}::#{__method__} Arguments: #{args.inspect}" }
49
-
50
- @username = args[:username] || DEFAULT_USERNAME
51
- @password = args[:password] || DEFAULT_PASSWORD
52
- @authorization_header_value = args[:authorization_header_value]
53
-
54
- @base_uri = "http#{http.use_ssl? ? 's' : ''}://#{http.address}:#{http.port}"
55
- @default_base_path = args[:default_base_path] || DEFAULT_BASE_PATH
56
-
57
- content_type = args[:content_type_header] ||= DEFAULT_HEADER_CONTENT_TYPE
58
- accepts = args[:accepts_header] ||= args[:accept_header] || DEFAULT_HEADER_ACCEPTS
59
-
60
- @default_request_headers = {
61
- 'Content-Type' => content_type,
62
- 'Accept' => accepts,
63
- }
64
-
65
- if !username.empty? && !password.empty?
66
- @authorization_header_key ||= 'Authorization' #CaseSensitiveHeaderKey.new('Authorization')
67
- @authorization_header_value ||= %(Basic #{["#{username}:#{password}"].pack('m').delete("\r\n")})
68
- @default_request_headers[authorization_header_key] = authorization_header_value
69
- end
70
-
71
- @log_request_body = args.fetch(:log_request_body, true)
72
- @log_response_body = args.fetch(:log_response_body, true)
73
- @log_pretty_print_body = args.fetch(:log_pretty_print_body, true)
74
-
75
- @parse_response = args.fetch(:parse_response, true)
76
- end
77
-
78
- def initialize_logger(args = { })
79
- @logger = args[:logger] ||= Logger.new(args[:log_to] || STDOUT)
80
- log_level = args[:log_level]
81
- if log_level
82
- @logger.level = log_level
83
- args[:logger] = @logger
84
- end
85
- @logger
86
- end
87
-
88
- def initialize_http(args = { })
89
- @http_host_address = args[:http_host_address] ||= DEFAULT_HTTP_HOST_ADDRESS
90
- @http_host_port = args[:http_host_port] ||= DEFAULT_HTTP_HOST_PORT
91
- @http = Net::HTTP.new(http_host_address, http_host_port)
92
-
93
- use_ssl = args[:http_host_use_ssl]
94
- if use_ssl
95
- # @TODO Add SSL Support
96
- http.use_ssl = true
97
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
98
- end
99
-
100
- http
101
- end
102
-
103
- # Formats a HTTPRequest or HTTPResponse body for log output.
104
- # @param [HTTPRequest|HTTPResponse] obj
105
- # @return [String]
106
- def format_body_for_log_output(obj)
107
- if obj.content_type == 'application/json'
108
- if @log_pretty_print_body
109
- _body = obj.body
110
- output = JSON.pretty_generate(JSON.parse(_body)) rescue _body
111
- return output
112
- else
113
- return obj.body
114
- end
115
- elsif obj.content_type == 'application/xml'
116
- return obj.body
117
- else
118
- return obj.body.inspect
119
- end
120
- end
121
-
122
- # @param [HTTPRequest] request
123
- def send_request(request)
124
- @response_parsed = nil
125
- @request = request
126
- logger.debug { %(REQUEST: #{request.method} http#{http.use_ssl? ? 's' : ''}://#{http.address}:#{http.port}#{request.path} HEADERS: #{request.to_hash.inspect} #{log_request_body and request.request_body_permitted? ? "\n-- BODY BEGIN --\n#{format_body_for_log_output(request)}\n-- BODY END --" : ''}) }
127
-
128
- @request_time_start = Time.now
129
- @response = http.request(request)
130
- @request_time_end = Time.now
131
- logger.debug { %(RESPONSE: #{response.inspect} HEADERS: #{response.to_hash.inspect} #{log_response_body and response.respond_to?(:body) ? "\n-- BODY BEGIN --\n#{format_body_for_log_output(response)}\n-- BODY END--" : ''}\nTook: #{@request_time_end - @request_time_start} seconds) }
132
- #logger.debug { "Parse Response? #{@parse_response}" }
133
-
134
- raise HTTPAuthorizationError if @use_exceptions && @response.code == '401'
135
-
136
- @parse_response ? response_parsed : response.body
137
- end
138
-
139
- def response_parsed
140
- @response_parsed ||= begin
141
- response_body = response.respond_to?(:body) ? response.body : ''
142
- logger.debug { "Parsing Response. #{response_body.inspect}" }
143
-
144
- case response.content_type
145
- when 'application/json'
146
- response_body.empty? ? response_body : JSON.parse(response_body) # rescue response
147
- else
148
- response_body
149
- end
150
- end
151
- end
152
-
153
- # @param [String] path
154
- # @param [Hash|String|Nil] query
155
- # @return [URI]
156
- def build_uri(path = '', query = nil)
157
- _query = query.is_a?(Hash) ? query.map { |k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.respond_to?(:to_s) ? v.to_s : v)}" }.join('&') : query
158
- _path = "#{path}#{_query and _query.respond_to?(:empty?) and !_query.empty? ? "?#{_query}" : ''}"
159
- URI.parse(File.join(base_uri, _path))
160
- end
161
-
162
- if RUBY_VERSION.start_with? '1.8.'
163
- def request_method_name_to_class_name(method_name)
164
- method_name.to_s.capitalize
165
- end
166
- else
167
- def request_method_name_to_class_name(method_name)
168
- method_name.to_s.capitalize.to_sym
169
- end
170
- end
171
-
172
- # @param [Symbol] method_name (:get)
173
- # @param [Hash] args
174
- # @option args [Hash] :headers ({})
175
- # @option args [String] :path ('')
176
- # @option args [Hash] :query ({})
177
- # @option args [Any] :body (nil)
178
- # @param [Hash] options
179
- # @option options [Hash] :default_request_headers (@default_request_headers)
180
- def call_method(method_name = :get, args = { }, options = { })
181
- headers = args[:headers] || options[:headers] || { }
182
- path = args[:path] || ''
183
- query = args[:query] || { }
184
- body = args[:body]
185
-
186
- # Allow the default request headers to be overridden
187
- _default_request_headers = options.fetch(:default_request_headers, default_request_headers)
188
- _default_request_headers ||= { }
189
- _headers = _default_request_headers.merge(headers)
190
-
191
- @uri = build_uri(path, query)
192
- klass_name = request_method_name_to_class_name(method_name)
193
- klass = Net::HTTP.const_get(klass_name)
194
-
195
- request = klass.new(@uri.request_uri, _headers)
196
-
197
- if request.request_body_permitted?
198
- _body = (body and !body.is_a?(String)) ? JSON.generate(body) : body
199
- logger.debug { "Processing Body: '#{_body}'" }
200
- request.body = _body if _body
201
- end
202
-
203
- send_request(request)
204
- end
205
-
206
- def delete(path, options = { })
207
- call_method(:delete, { :path => path }, options)
208
- end
209
-
210
- def get(path, options = { })
211
- call_method(:get, { :path => path }, options)
212
- end
213
-
214
- def head(path, options = { })
215
- call_method(:head, { :path => path }, options)
216
- end
217
-
218
- def options(path, options = { })
219
- call_method(:options, { :path => path }, options)
220
- end
221
-
222
- def put(path, body, options = { })
223
- call_method(:put, { :path => path, :body => body }, options)
224
- end
225
-
226
- def post(path, body, options = { })
227
- call_method(:post, { :path => path, :body => body }, options)
228
- end
229
-
230
- # HTTPClient
231
- end
232
-
233
9
  class NotificationHandler
234
10
 
235
11
  attr_accessor :logger
236
12
 
237
13
  def initialize(args = { })
238
14
  initialize_logger(args)
239
- initialize_http(args)
240
15
  end
241
16
 
242
17
  def initialize_logger(args = { })
@@ -247,93 +22,22 @@ module Vidispine
247
22
  end
248
23
  end
249
24
 
250
- def initialize_http(args = { })
251
- uri_as_str = args[:uri]
252
-
253
- uri = URI(uri_as_str)
254
-
255
- args[:http_host_address] = uri.host
256
- args[:http_host_port] = uri.port
257
- args[:http_host_use_ssl] = uri.scheme == 'https'
258
- args[:username] = uri.user
259
- args[:password] = uri.password
260
- args[:default_base_path] = uri.request_uri
261
-
262
- @http_client = HTTPClient.new(args)
263
- end
264
-
265
- def forward_notification(notification)
266
- @http_client.call_method(:post, :body => notification)
267
- end
268
-
269
25
  end
270
26
 
271
27
  end
272
28
 
273
- LOGGING_LEVELS = {
274
- :debug => Logger::DEBUG,
275
- :info => Logger::INFO,
276
- :warn => Logger::WARN,
277
- :error => Logger::ERROR,
278
- :fatal => Logger::FATAL
279
- }
280
-
281
- DEFAULT_HEADER_CONTENT_TYPE = 'application/json; charset=utf-8'
282
-
283
- def log_to_as_string
284
- _log_to = arguments[:log_to]
285
- case _log_to
286
- when STDERR; 'STDERR'
287
- when STDOUT; 'STDOUT'
288
- else _log_to
289
- end
290
- end
291
-
292
29
 
293
- default_arguments = {
30
+ args = {
294
31
  :log_to => "/tmp/#{File.basename($0)}.log",
295
- :log_level => Logger::DEBUG,
296
- :options_file_path => File.expand_path(File.basename($0, '.*'), '~/.options'),
297
- :http_method => :post
32
+ :log_level => Logger::DEBUG
298
33
  }
299
- @arguments = default_arguments.dup
300
- def arguments; @arguments end
301
-
302
- argument_parser = OptionParser.new
303
- argument_parser.on('--uri URI', 'The address of the server to communicate with.') { |v| arguments[:uri] = v }
304
-
305
- argument_parser.on('--content-type VALUE', 'The value for the Content-Type header sent in each request.', "\tdefault: #{DEFAULT_HEADER_CONTENT_TYPE}") { |v| arguments[:content_type] = v }
306
- argument_parser.on('--method METHOD', 'The HTTP method to use when submitting the notification.', "\tdefault: #{arguments[:http_method]}") { |v| arguments[:http_method] = v.to_sym }
307
- argument_parser.on('--pretty-print', 'Will format the output to be more human readable.') { |v| arguments[:pretty_print] = v }
308
-
309
- argument_parser.on('--log-to FILENAME', 'Log file location.', "\tdefault: #{log_to_as_string}") { |v| arguments[:log_to] = v }
310
- argument_parser.on('--log-level LEVEL', LOGGING_LEVELS.keys, "Logging level. Available Options: #{LOGGING_LEVELS.keys.join(', ')}",
311
- "\tdefault: #{LOGGING_LEVELS.invert[arguments[:log_level]]}") { |v| arguments[:log_level] = LOGGING_LEVELS[v] }
312
-
313
- argument_parser.on('--[no-]options-file [FILENAME]', 'Path to a file which contains default command line arguments.', "\tdefault: #{arguments[:options_file_path]}" ) { |v| arguments[:options_file_path] = v}
314
- argument_parser.on_tail('-h', '--help', 'Display this message.') { puts help; exit }
315
-
316
- arguments.clear
317
- original_argv_args = ARGV.dup
318
- argument_parser.parse!(ARGV)
319
- remaining_argv_args = ARGV.dup
320
- arguments_from_command_line = arguments.dup
321
-
322
- options_file_path = arguments_from_command_line[:options_file_path] || default_arguments[:options_file_path]
323
-
324
- arguments.clear
325
- argument_parser.load(options_file_path)
326
- arguments_from_options_file = arguments.dup
327
-
328
- arguments = default_arguments.merge(arguments_from_options_file).merge(arguments_from_command_line)
329
-
330
- pp arguments
331
- # @handler = Vidispine::NotificationHandler.new(arguments)
332
- # def logger; @handler.logger end
333
- # logger.debug { "ARGUMENTS: #{remaining_argv_args.inspect}" }
334
-
335
34
 
35
+ @handler = Vidispine::NotificationHandler.new(args)
36
+ def logger; @handler.logger end
37
+ logger.debug { "ARGUMENTS: #{ARGV.inspect}" }
336
38
 
337
- # @handler.forward_notification(remaining_argv_args)
39
+ # ARGV << '{changeSetId=[VX-460], userName=[admin], itemId=[VX-90], portal_mf201890=[3], sequenceNumber=[0]}'
40
+ # puts 'Arguments:'
41
+ # pp ARGV
338
42
 
339
43
 
@@ -389,10 +389,6 @@ module Vidispine
389
389
  end
390
390
  alias :item_shape_files :item_shape_files_get
391
391
 
392
- def item_shape_add(args = { }, options = { })
393
-
394
- end
395
-
396
392
  # @see http://apidoc.vidispine.com/4.2.6/ref/item/shape.html#get-shape
397
393
  def item_shape_get(args = { }, options = { })
398
394
  _request = Requests::BaseRequest.new(
@@ -9,7 +9,8 @@ module Vidispine
9
9
 
10
10
  class HTTPAuthorizationError < RuntimeError; end
11
11
 
12
- attr_accessor :logger, :http, :http_host_address, :http_host_port, :base_uri, :default_base_path
12
+ attr_accessor :logger, :http, :http_host_address, :http_host_port, :base_uri, :default_base_path,
13
+ :default_query_data
13
14
  attr_accessor :username, :password
14
15
 
15
16
  attr_accessor :default_request_headers,
@@ -46,6 +47,8 @@ module Vidispine
46
47
  @base_uri = args[:base_uri] || "http#{http.use_ssl? ? 's' : ''}://#{http.address}:#{http.port}"
47
48
  @default_base_path = args[:default_base_path] || DEFAULT_BASE_PATH
48
49
 
50
+ @default_query_data = args[:default_query_data] || { }
51
+
49
52
  # @user_agent_default = "#{@hostname}:#{@username} Ruby SDK Version #{Vidispine::VERSION}"
50
53
 
51
54
  @authorization_header_key ||= 'Authorization' #CaseSensitiveHeaderKey.new('Authorization')
@@ -81,12 +84,11 @@ module Vidispine
81
84
  @http_host_address = args[:http_host_address] ||= DEFAULT_HTTP_HOST_ADDRESS
82
85
  @http_host_port = args[:http_host_port] ||= DEFAULT_HTTP_HOST_PORT
83
86
  @http = Net::HTTP.new(http_host_address, http_host_port)
84
-
85
87
  use_ssl = args[:http_host_use_ssl]
86
88
  if use_ssl
87
- # @TODO Add SSL Support
89
+ http_verify_mode = args.fetch(:http_verify_mode, OpenSSL::SSL::VERIFY_NONE)
88
90
  http.use_ssl = true
89
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
91
+ http.verify_mode = http_verify_mode if http_verify_mode
90
92
  end
91
93
 
92
94
  http
@@ -146,7 +148,7 @@ module Vidispine
146
148
  # @param [Hash|String|Nil] query
147
149
  # @return [URI]
148
150
  def build_uri(path = '', query = nil)
149
- _query = query.is_a?(Hash) ? query.map { |k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.respond_to?(:to_s) ? v.to_s : v)}" }.join('&') : query
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
150
152
  _path = "#{path}#{_query and _query.respond_to?(:empty?) and !_query.empty? ? "?#{_query}" : ''}"
151
153
  URI.parse(File.join(base_uri, _path))
152
154
  end
@@ -13,6 +13,7 @@ module Vidispine::API::Client::Requests
13
13
  :fileId,
14
14
  :tag,
15
15
  :original,
16
+ :createPosters,
16
17
  :createThumbnails,
17
18
  :overrideFastStart,
18
19
  :requireFastStart,
@@ -592,7 +592,7 @@ module Vidispine
592
592
  file = { 'id' => file_id }
593
593
  end
594
594
 
595
- if file and !file['item']
595
+ if file_id && file && !file['item']
596
596
  # If the passed file doesn't have an item then requery to verify that the item is absent
597
597
  storage_file_get_response = storage_file_get(:storage_id => storage_id, :file_id => file_id, :include_item => true)
598
598
 
@@ -21,7 +21,7 @@ module Vidispine
21
21
  def self.default_arguments
22
22
  @default_arguments ||= {
23
23
  :options_file_path => default_options_file_path,
24
- :log_level => Logger::DEBUG,
24
+ :log_level => Logger::ERROR,
25
25
  :log_to => STDERR,
26
26
  }
27
27
  end
@@ -137,7 +137,6 @@ Options:
137
137
 
138
138
  def self.run(args = nil, init_options = { }, run_options = nil)
139
139
  args ||= parse_arguments
140
- # puts "Arguments: #{args.inspect}"
141
140
  run_options ||= init_options
142
141
  new(args, init_options).run(args, run_options)
143
142
  end
@@ -1,3 +1,3 @@
1
1
  module Vidispine
2
- VERSION = '1.4.0'
2
+ VERSION = '1.5.0'
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['john.whitson@gmail.com']
11
11
  spec.summary = %q{A Library to Interact with the Vidispine API}
12
12
  spec.description = %q{}
13
- spec.homepage = 'https://github.com/XPlatform-Consulting/vidispine'
13
+ spec.homepage = ''
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -23,4 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'bundler', '~> 1.7'
24
24
  spec.add_development_dependency 'rake', '~> 10.0'
25
25
 
26
+ # spec.add_runtime_dependency 'xml-simple', '~> 1.1.4'
27
+ # spec.add_runtime_dependency 'sinatra', '~> 1.4.5'
26
28
  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.4.0
4
+ version: 1.5.0
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-05-08 00:00:00.000000000 Z
11
+ date: 2018-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -90,7 +90,7 @@ files:
90
90
  - lib/vidispine/version.rb
91
91
  - resources/postman/Vidispine API (From WADL v4.11).postman_collection.json
92
92
  - vidispine.gemspec
93
- homepage: https://github.com/XPlatform-Consulting/vidispine
93
+ homepage: ''
94
94
  licenses:
95
95
  - MIT
96
96
  metadata: {}
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  version: '0'
111
111
  requirements: []
112
112
  rubyforge_project:
113
- rubygems_version: 2.7.6
113
+ rubygems_version: 2.5.2
114
114
  signing_key:
115
115
  specification_version: 4
116
116
  summary: A Library to Interact with the Vidispine API