Paperclip Remote URL - ruby

I'm working with Rails 3.0.9 and Ruby 1.9.2. I am running the gem Paperclip to upload images, and this works fine.
However, I'm trying to integrate it with an API that returns just an image URL.
The plan is to run a cron job to fetch the XML output of the API, parse it, and store it in the database.
My question is, how can I use just the remote url to display the image in my application? I do not want to have to download all the images, as there are 1000s of images (only 1 per record though).
Can anyone suggest how to do this? Thanks in advance.

Sure in the latest version of paperclip (you might have to link it to the unreleased version in github). (Version > 3.1.3)
You can do something like this
self.your_paperclip_attachment_attribute = URI.parse("http://some.com/url/withimage.png")
That will download and link the attachment to your model.

Related

Riot API How to get summoner profile icon image

I found out i can get Summoner Icon image using this url:
https://ddragon.leagueoflegends.com/cdn/11.14.1/img/profileicon/934.png
The basic form of this is:
https://ddragon.leagueoflegends.com/cdn/{version}/img/profileicon/{profileIconId}.png
i know i can get the second value of {profileIconId} through Riot API but how do i know when i should update the version value? I don't want my app to crash when the version should be changed.
You should not be referencing ddragon for displaying icons or images. In fact, DataDragon specifically requests that you download the archive (.tgz) for each patch/version and host the assets locally or on your own CDN.
Websites like op.gg do this for all of the assets and host the images on their own CDN. They have to update their CDN every patch. You can automate updating the CDN using scripts, but for most small projects the work to automate this process may not be worth it.
Generally, it is considered rude to piggyback off of someone else's CDN without explicit permission to do so. Riot goes a step further and explicitly asks that you do not do this.
If someone is using the data dragon (ddragon) cdn, you can know the latest version looking at this json that they provide:
https://ddragon.leagueoflegends.com/api/versions.json
Just take the first element of the array and you are good to go without any scripting.

Convert emails to HTML or PDF programmatically

I'm trying to convert emails from my mailbox, into either HTML or PDF programatically.
My main motivation is to able to create summary of emails on a web page, and able to expand a particular email and view the entire content of the email.
I figured PDF might be an option since I do not have to worry about linking the contents in the email (eg. image) to the storage location of the image.
I'm starting with the ruby Mail gem and I also came across mhonarc. I'm not sure if mhonarc is a too much for what I'm trying to do, so I decided to ask here to see if there alternatives out there.
Gem pdfkit is used for generating PDFs. Please read readme, gem requires wkhtmltopdf library in your system.
I would approach email conversion via the IMAP library (there might be newer ones out by now) and then serve everything from a simple Sinatra app in the browser. You can use a template language to generate simple html output and logic. Of course you can also use prawn for pdf generation. Many different ways to get there... Not sure why you don't just load emails and show partial content. Life can be so simple.

ruby on rails app and google app scripts

I have a app which runs on ruby on rails and mysql database. I need to generate couple of reports. Presently I am generating csv file but my Idea is to integrate with the google docs, as soon as a user opens a particular doc automatically it has to sync with the my rails app and fetch the data from the database and display in the google docs.
I need little heads up.I have gone through the docs, but couldn't figure out the way of doing it.
Thanks
Check out the to_google_spreadsheets gem. It is well documented and seems to have all the functionality you are looking for.
Cheers,
Sean
You will need to write an onOpen in your gdoc. From there call urlfetch to your app.

Rails 3.1, Paperclip, Multiple file upload

Anybody knows an example tutorial, how to upload multiple files (unlimited quantity) with paperclip & Rails 3.1? All examples I've seen are uploading fixed files count per one upload.
I am also looking for it. I found this page:
https://github.com/blueimp/jQuery-File-Upload/
There is a demo over there. It is not based on paperclip, it seems, but then I also found this one:
https://github.com/tors/jquery-fileupload-rails
Which has a linked repository with an example with paperclip:
https://github.com/tors/jquery-fileupload-rails-paperclip-example
Maybe this one can get us in the right direction!
Good luck!

Choosing a recaptcha gem for rails

I am currently working on a rails 3.1 app that is going to be in the wild soon. I need to add captcha's to a couple of the pages (reset password etc). I think I have decided to go with recaptcha's service but I'm stuck trying to decide which gem to use. The two obvious options are:
ambethia / recaptcha: https://github.com/ambethia/recaptcha
and
rack-recapcha https://github.com/achiu/rack-recaptcha
Does anyone have any experience / suggestions as to which works better with rails 3.1?
I'm succesfully using ambethia/recaptcha.
The main thing is neither of them are using the asset pipeline from rails 3.1.
Anyhow ambethia/recaptcha. works fine.

Resources