Class: SonyCiBasic
- Inherits:
-
Object
- Object
- SonyCiBasic
- Defined in:
- lib/sony_ci_api/sony_ci_basic.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Downloader
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
-
#workspace_id ⇒ Object
readonly
Returns the value of attribute workspace_id.
Instance Method Summary collapse
-
#download(asset_id) ⇒ Object
Generate a temporary download URL for an asset.
-
#initialize(opts = {}) ⇒ SonyCiBasic
constructor
Either
credentials_pathor acredentialsobject itself must be supplied.
Constructor Details
#initialize(opts = {}) ⇒ SonyCiBasic
Either credentials_path or a credentials object itself must be supplied.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
7 8 9 |
# File 'lib/sony_ci_api/sony_ci_basic.rb', line 7 def access_token @access_token end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
8 9 10 |
# File 'lib/sony_ci_api/sony_ci_basic.rb', line 8 def verbose @verbose end |
#workspace_id ⇒ Object (readonly)
Returns the value of attribute workspace_id.
9 10 11 |
# File 'lib/sony_ci_api/sony_ci_basic.rb', line 9 def workspace_id @workspace_id end |
Instance Method Details
#download(asset_id) ⇒ Object
Generate a temporary download URL for an asset.
49 50 51 |
# File 'lib/sony_ci_api/sony_ci_basic.rb', line 49 def download(asset_id) Downloader.new(self).download(asset_id) end |