sony-ci-api 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c344e4f79a93bc0fab03b439d9279c3a49a4710d
4
- data.tar.gz: 8071312023cf6bb2652931f383c431888a11401e
3
+ metadata.gz: c56ac6f9cc51f695641456413698265e1d82ec2e
4
+ data.tar.gz: dab28c484e7a829b236331ee28888597f72a4872
5
5
  SHA512:
6
- metadata.gz: bc671a8b8b8c98a98d06b32cd15715e687cf97b6c3210d02fae851f27d722f2812fb4831cc94769ab8fdf971c65cc71707945ebc02facd6577c33e1881d165f8
7
- data.tar.gz: 626375b4070d753c6a3239f09905d5d185f871234159304e2d7ca83d3af1d3e171b8728949e26361dc5ea6f0408239a2192aaacd34665e9edcf232411c6cf5f2
6
+ metadata.gz: 269293d95e6e5af47ab029cc23d7b0496c579d8f5d257852fc555a7158d038abc8e2018a38875bc5a00d7d50c7acbe969227b98d833a7ce131a5674222deacf0
7
+ data.tar.gz: 145424cd8926db041ec2739cf8e7b05a66ec6a15d599ade73b10498b99017e0e5349974e0593ce441b8380be76185cc024e0d13835cd94d6674199a35f887c7a
@@ -15,7 +15,7 @@ ci = SonyCiAdmin.new(
15
15
  begin
16
16
  case args.keys.sort
17
17
 
18
- when ['log', 'up']
18
+ when %w(log up)
19
19
  fail ArgumentError.new if args['log'].empty? || args['up'].empty?
20
20
  args['up'].each { |path| ci.upload(path, args['log'].first) }
21
21
 
@@ -1,4 +1,4 @@
1
1
  require_relative 'sony-ci-api/sony_ci_admin'
2
- # Nothing else: The outside world doesn't need to worry
3
- # about the particular classes which are required, and
4
- # sony_ci_admin.rb loads its own dependencies.
2
+ # Nothing else: The outside world doesn't need to worry
3
+ # about the particular classes which are required, and
4
+ # sony_ci_admin.rb loads its own dependencies.
@@ -19,7 +19,7 @@ class SonyCiAdmin < SonyCiBasic
19
19
  end
20
20
 
21
21
  # Full metadata for a windowed set of items.
22
- def list(limit=50, offset=0)
22
+ def list(limit = 50, offset = 0)
23
23
  Lister.new(self).list(limit, offset)
24
24
  end
25
25
 
@@ -38,6 +38,10 @@ class SonyCiAdmin < SonyCiBasic
38
38
  Detailer.new(self).detail(asset_id)
39
39
  end
40
40
 
41
+ def multi_details(asset_ids, fields)
42
+ Detailer.new(self).multi_details(asset_ids, fields)
43
+ end
44
+
41
45
  class Detailer < SonyCiClient #:nodoc:
42
46
  def initialize(ci)
43
47
  @ci = ci
@@ -50,6 +54,17 @@ class SonyCiAdmin < SonyCiBasic
50
54
  handle_errors(curl)
51
55
  JSON.parse(curl.body_str)
52
56
  end
57
+
58
+ def multi_details(asset_ids, fields)
59
+ curl = Curl::Easy.http_post('https:''//api.cimediacloud.com/assets/details/bulk',
60
+ JSON.generate('assetIds' => asset_ids,
61
+ 'fields' => fields)
62
+ ) do |c|
63
+ add_headers(c, 'application/json')
64
+ end
65
+ handle_errors(curl)
66
+ JSON.parse(curl.body_str)
67
+ end
53
68
  end
54
69
 
55
70
  class Deleter < SonyCiClient #:nodoc:
@@ -105,9 +120,7 @@ class SonyCiAdmin < SonyCiBasic
105
120
  if file.size >= 5 * 1024 * 1024
106
121
  initiate_multipart_upload(file)
107
122
  part = 0
108
- while part do
109
- part = do_multipart_upload_part(file, part)
110
- end
123
+ part = do_multipart_upload_part(file, part) while part
111
124
  complete_multipart_upload
112
125
  else
113
126
  singlepart_upload(file)
@@ -151,7 +164,7 @@ class SonyCiAdmin < SonyCiBasic
151
164
  end
152
165
 
153
166
  CHUNK_SIZE = 10 * 1024 * 1024
154
-
167
+
155
168
  def do_multipart_upload_part(file, part)
156
169
  fragment = file.read(CHUNK_SIZE)
157
170
  return unless fragment
@@ -159,7 +172,7 @@ class SonyCiAdmin < SonyCiBasic
159
172
  add_headers(c, 'application/octet-stream')
160
173
  end
161
174
  handle_errors(curl)
162
- return part + 1
175
+ part + 1
163
176
  end
164
177
 
165
178
  def complete_multipart_upload
@@ -170,4 +183,3 @@ class SonyCiAdmin < SonyCiBasic
170
183
  end
171
184
  end
172
185
  end
173
-
@@ -9,7 +9,7 @@ class SonyCiBasic
9
9
  attr_reader :workspace_id
10
10
 
11
11
  # Either +credentials_path+ or a +credentials+ object itself must be supplied.
12
- def initialize(opts={}) # rubocop:disable PerceivedComplexity, CyclomaticComplexity
12
+ def initialize(opts = {}) # rubocop:disable PerceivedComplexity, CyclomaticComplexity
13
13
  unrecognized_opts = opts.keys - [:verbose, :credentials_path, :credentials]
14
14
  fail "Unrecognized options #{unrecognized_opts}" unless unrecognized_opts == []
15
15
 
@@ -20,7 +20,7 @@ class SonyCiBasic
20
20
  credentials = opts[:credentials] || YAML.load_file(opts[:credentials_path])
21
21
 
22
22
  credentials.keys.sort.tap do |actual|
23
- expected = ['username', 'password', 'client_id', 'client_secret', 'workspace_id'].sort
23
+ expected = %w(username password client_id client_secret workspace_id).sort
24
24
  fail "Expected #{expected} in ci credentials, not #{actual}" if actual != expected
25
25
  end
26
26
 
@@ -60,7 +60,7 @@ class SonyCiBasic
60
60
  def download(asset_id)
61
61
  hit = @@cache[asset_id]
62
62
  if !hit || hit[:expires] < Time.now
63
-
63
+
64
64
  curl = Curl::Easy.http_get('https'"://api.cimediacloud.com/assets/#{asset_id}/download") do |c|
65
65
  add_headers(c)
66
66
  end
@@ -1,5 +1,5 @@
1
1
  class SonyCiClient #:nodoc:
2
- def add_headers(curl, mime=nil)
2
+ def add_headers(curl, mime = nil)
3
3
  # on_missing and on_failure exist...
4
4
  # but any exceptions are caught and turned into warnings:
5
5
  # You need to check the response code at the end
@@ -8,7 +8,8 @@ class SonyCiClient #:nodoc:
8
8
  curl.headers['Authorization'] = "Bearer #{@ci.access_token}"
9
9
  curl.headers['Content-Type'] = mime if mime
10
10
  end
11
+
11
12
  def handle_errors(curl)
12
- raise "#{curl.status}: #{curl.url}" if curl.response_code.to_s !~ /^2../
13
+ fail "#{curl.status}: #{curl.url}\nHEADERS: #{curl.headers}\nPOST: #{curl.post_body}\nRESPONSE: #{curl.body}" if curl.response_code.to_s !~ /^2../
13
14
  end
14
- end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sony-ci-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuck McCallum
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-28 00:00:00.000000000 Z
11
+ date: 2015-10-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Wrapper for the Sony Ci API (http://developers.cimediacloud.com/)
14
14
  email: chuck_mccallum@wgbh.org