Class: Ayadn::NowWatching
- Inherits:
-
Object
- Object
- Ayadn::NowWatching
- Defined in:
- lib/ayadn/nowwatching.rb
Instance Method Summary collapse
- #find_by_title(args, options = {}) ⇒ Object
- #format_plot(response, text) ⇒ Object
- #format_post(response) ⇒ Object
-
#initialize(view) ⇒ NowWatching
constructor
A new instance of NowWatching.
- #post(args, options) ⇒ Object
Constructor Details
#initialize(view) ⇒ NowWatching
Returns a new instance of NowWatching.
8 9 10 11 |
# File 'lib/ayadn/nowwatching.rb', line 8 def initialize view @view = view @spotlite = Spotlite::Movie end |
Instance Method Details
#find_by_title(args, options = {}) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/ayadn/nowwatching.rb', line 37 def find_by_title args, = {} resp = @spotlite.find(args.join(' ')) if ['alt'] resp[1] else resp[0] end end |
#format_plot(response, text) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ayadn/nowwatching.rb', line 54 def format_plot response, text max = 239 - (text.length + Settings.[:movie][:hashtag].length) short = max - 3 plot = response.description if plot.length > max "#{plot[0..short]}..." else plot end end |
#format_post(response) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/ayadn/nowwatching.rb', line 46 def format_post response tag = Settings.[:movie][:hashtag] text_1 = "'#{response.title}' (#{response.year})" link = "[IMDb](#{response.url})" plot = format_plot(response, text_1) "#{text_1}\n \n#{plot}\n \n#{link}\n \n##{tag}\n\n" end |
#post(args, options) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ayadn/nowwatching.rb', line 13 def post args, puts "\nContacting IMDb.com...".color(:cyan) response = find_by_title(args, ) text = format_post(response) show_post(text) reg = /[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]/ filename = "#{response.title.downcase.strip.gsub(reg, '_').split(' ').join('_')}.jpg" FileOps.download_url(filename, response.poster_url) @view.clear_screen puts "\nPosting and uploading the movie poster...\n".color(:green) file = ["#{Settings.config[:paths][:downloads]}/#{filename}"] dic = { 'text' => text, 'data' => FileOps.upload_files(file), 'title' => response.title, 'source' => 'IMDb' } resp = Post.new.send_movie(dic) FileOps.save_post(resp) if Settings.[:backup][:auto_save_sent_posts] @view.clear_screen puts Status.yourpost @view.show_posted(resp) end |