Class: Rusic::Uploaders::Base
- Inherits:
-
Object
- Object
- Rusic::Uploaders::Base
- Includes:
- CommandLineReporter
- Defined in:
- lib/rusic/uploaders/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#api_host ⇒ Object
Returns the value of attribute api_host.
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#file ⇒ Object
Returns the value of attribute file.
-
#theme ⇒ Object
Returns the value of attribute theme.
Instance Method Summary collapse
-
#initialize(file) ⇒ Base
constructor
A new instance of Base.
- #perform ⇒ Object
- #upload_file(options = {}) ⇒ Object
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_host ⇒ Object
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_key ⇒ Object
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/rusic/uploaders/base.rb', line 6 def api_key @api_key end |
#file ⇒ Object
Returns the value of attribute file.
6 7 8 |
# File 'lib/rusic/uploaders/base.rb', line 6 def file @file end |
#theme ⇒ Object
Returns the value of attribute theme.
6 7 8 |
# File 'lib/rusic/uploaders/base.rb', line 6 def theme @theme end |
Instance Method Details
#perform ⇒ Object
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( = {}) @api_key = .fetch('api_key') @api_host = .fetch('api_host', 'api.rusic.com') @theme = .fetch('theme') report(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. exit(1) end |