Class: Dragonfly::ImgurDataStore
- Inherits:
-
Object
- Object
- Dragonfly::ImgurDataStore
- Defined in:
- lib/dragonfly/imgur_data_store.rb
Instance Method Summary collapse
- #destroy(uid) ⇒ Object
-
#initialize(opts = {}) ⇒ ImgurDataStore
constructor
A new instance of ImgurDataStore.
- #read(uid) ⇒ Object
- #url_for(uid, opts = {}) ⇒ Object
- #write(content, opts = {}) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ ImgurDataStore
Returns a new instance of ImgurDataStore.
11 12 13 |
# File 'lib/dragonfly/imgur_data_store.rb', line 11 def initialize(opts = {}) @session = Imgurapi::Session.instance(opts) end |
Instance Method Details
#destroy(uid) ⇒ Object
27 28 29 |
# File 'lib/dragonfly/imgur_data_store.rb', line 27 def destroy(uid) @session.image.image_delete(uid) end |
#read(uid) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/dragonfly/imgur_data_store.rb', line 20 def read(uid) body = Net::HTTP.get_response(URI.parse url_for(uid)).body body == '' ? nil : body rescue nil end |
#url_for(uid, opts = {}) ⇒ Object
31 32 33 |
# File 'lib/dragonfly/imgur_data_store.rb', line 31 def url_for(uid, opts = {}) Imgurapi::Image.new(id: uid).url end |
#write(content, opts = {}) ⇒ Object
15 16 17 18 |
# File 'lib/dragonfly/imgur_data_store.rb', line 15 def write(content, opts = {}) image = @session.image.image_upload(content.file) image.id end |