Class: PosterManager
- Inherits:
-
Object
- Object
- PosterManager
- Defined in:
- lib/filmaffinity/poster-manager.rb
Instance Method Summary collapse
- #construct_name ⇒ Object
- #load_poster(posterurl) ⇒ Object
- #save_img_locally(posterurl) ⇒ Object
- #upload(posterurl, api_id) ⇒ Object
Instance Method Details
#construct_name ⇒ Object
28 29 30 |
# File 'lib/filmaffinity/poster-manager.rb', line 28 def construct_name (0...8).map { (65 + rand(26)).chr }.join end |
#load_poster(posterurl) ⇒ Object
5 6 7 8 |
# File 'lib/filmaffinity/poster-manager.rb', line 5 def load_poster(posterurl) return posterurl unless FilmAffinity.configuration.imgur_id upload(posterurl, FilmAffinity.configuration.imgur_id) end |
#save_img_locally(posterurl) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/filmaffinity/poster-manager.rb', line 20 def save_img_locally(posterurl) open(posterurl) do |f| File.open(@dir, 'wb') do |file| file.puts f.read end end end |
#upload(posterurl, api_id) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/filmaffinity/poster-manager.rb', line 10 def upload(posterurl, api_id) imgur = Imgur.new(api_id) @dir = __dir__ + '/' + construct_name + '.jpg' save_img_locally(posterurl) local_image = Imgur::LocalImage.new(@dir) uploaded = imgur.upload(local_image) File.delete(@dir) uploaded.link end |