class SonyCiBasic
Attributes
access_token[R]
verbose[R]
workspace_id[R]
Public Class Methods
new(opts = {})
click to toggle source
Either credentials_path
or a credentials
object itself must be supplied.
# File lib/sony_ci_api/sony_ci_basic.rb, line 12 def initialize(opts = {}) # rubocop:disable PerceivedComplexity, CyclomaticComplexity unrecognized_opts = opts.keys - [:verbose, :credentials_path, :credentials] fail "Unrecognized options #{unrecognized_opts}" unless unrecognized_opts == [] @verbose = opts[:verbose] ? true : false fail 'Credentials specified twice' if opts[:credentials_path] && opts[:credentials] fail 'No credentials given' if !opts[:credentials_path] && !opts[:credentials] credentials = opts[:credentials] || YAML.load_file(opts[:credentials_path]) credentials.keys.sort.tap do |actual| expected = %w(username password client_id client_secret workspace_id).sort fail "Expected #{expected} in ci credentials, not #{actual}" if actual != expected end params = { 'grant_type' => 'password', 'client_id' => credentials['client_id'], 'client_secret' => credentials['client_secret'] }.map { |k, v| Curl::PostField.content(k, v) } curl = Curl::Easy.http_post('https://api.cimediacloud.com/oauth2/token', *params) do |c| c.verbose = @verbose c.http_auth_types = :basic c.username = credentials['username'] c.password = credentials['password'] # c.on_missing { |curl, data| puts "4xx: #{data}" } # c.on_failure { |curl, data| puts "5xx: #{data}" } end @access_token = JSON.parse(curl.body_str)['access_token'] fail 'OAuth failed' unless @access_token @workspace_id = credentials['workspace_id'] end
Public Instance Methods
download(asset_id)
click to toggle source
Generate a temporary download URL for an asset.
# File lib/sony_ci_api/sony_ci_basic.rb, line 49 def download(asset_id) Downloader.new(self).download(asset_id) end