Class: Rusic::Uploaders::Base

Inherits:
Object
  • Object
show all
Includes:
CommandLineReporter
Defined in:
lib/rusic/uploaders/base.rb

Direct Known Subclasses

Asset, CustomAttributes, EditableAsset, Template

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Base

Returns a new instance of Base.



8
9
10
# File 'lib/rusic/uploaders/base.rb', line 8

def initialize(file)
  @file = file
end

Instance Attribute Details

#api_hostObject

Returns the value of attribute api_host.



6
7
8
# File 'lib/rusic/uploaders/base.rb', line 6

def api_host
  @api_host
end

#api_keyObject

Returns the value of attribute api_key.



6
7
8
# File 'lib/rusic/uploaders/base.rb', line 6

def api_key
  @api_key
end

#fileObject

Returns the value of attribute file.



6
7
8
# File 'lib/rusic/uploaders/base.rb', line 6

def file
  @file
end

#themeObject

Returns the value of attribute theme.



6
7
8
# File 'lib/rusic/uploaders/base.rb', line 6

def theme
  @theme
end

Instance Method Details

#performObject



32
33
34
# File 'lib/rusic/uploaders/base.rb', line 32

def perform
  fail NotImplementedError, 'define a #perform method on your uploader'
end

#upload_file(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rusic/uploaders/base.rb', line 12

def upload_file(options = {})
  @api_key = options.fetch('api_key')
  @api_host = options.fetch('api_host', 'api.rusic.com')
  @theme = options.fetch('theme')

  report(message: message, complete: '', type: 'inline', indent_size: 2) do
    begin
      perform
      print(' [done]'.green)
    rescue RestClient::UnprocessableEntity, RestClient::Exception => e
      puts e
      print(' [failed]'.red)
    end
  end
rescue KeyError => e
  puts
  puts e.message
  exit(1)
end