How to read the first few lines of a website - ruby-on-rails

I am trying to implement a feature to your web application, in which if a user saves a website's url, it is stored and displayed in the library. Now when a web url is saved in facebook, the first few lines of the webpage is also displayed. I also want to implement a similar feature.
I am using Ruby on Rails. I tried using the .load() method of jquery, but using that I am only able to retrieve description of pages which are in the application. I want to save a url in my app, eg, "api.jquery.com/load/";, and while displaying the list of urls, I want to display a description of the page, like its shown in facebook when you enter a url in the status update
Any suggestions on how to do it?

Related

Send email as PDF in ruby on rails in Typo3

I have an web-application in RoR which calculates some energy values and investment money. I use ajax to send the data from the web-browser to the server. It is something like this: Browser-server-Browser-Server-Browser
This web-application is already integrated in typo3 and I want to implement a PDF button to send the results per email (in other words, a photo of the page with the results).
I have heard an option would be to generate some links in RoR to be used in typo3 (when clicking on it, it would open exactly the web-application with the results already calculated). But as a newbie, I do not really know which would be the best approach.
Any recommendation?
A screenshot of the page can be done client-side:
http://html2canvas.hertzen.com/
You could even have another page with the same results that you use only for the rendering of the result page what you use for making a clean screen-shot (you might not want to have the footer, menu and other elements on that page, only the results)
Once you have your screenshot, you can upload it to your server where you can use it to create a PDF of that image and then send it with any mail API you prefer to use.
info about TYPO3's mail api can be found here:
https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Mail/Index.html

direct to and simulate web user to fill in search data(Ruby On Rails)

Currently I'm developing a flight ticket search engine(pretty similar to this-http://www.momondo.com/) which will gather all the information of a site. I' m done with the grab the info from the website.
So for each, search result,it do consist of a button like the site (Select) which will let user to redirect to according site to book the ticket.
Scenario:
on my site, I search for a location(from-to) ,then it comes out with lists of search result. I found out a search result that suit me and I click the 'Book' button and it should be redirect to AirAsia flight ticket with the data filled(like location from-to) on the Airasia site,then can direct book from the AirAsia site.
As I know for ruby on rails, there is a watir gem to simulate the user. But how to achieve this tasks? I do know when direct to the specific site , it need to pass all the parameters to the site in order to simulate or perform searching on the site.
any advice are appreaciated :D It's RoR project.
You could load the remote website in an iframe on the page and then use JavaScript to fill in the required fields.
AFAIK there isn't an easy way to fill in the fields on a remote site without using server side code on the remote site.

How to update iframe page tab content using a form?

I am trying to pass data using a form to a Facebook iFrame page tab but can't seem to figure how to do it.
I have a page tab on my Facebook page with several elements such as links and images directing users to various pages on the main website. This is updated every week, so rather than update the HTML file and upload via FTP everyweek i would like to see if i can create a form to pass the new data to the iframe.
In addition the Facebook page tab cannot be created in PHP as the server is running ASP.NET
I am trying to do this without the use of a database table if possible, using POST or GET would be preferable.
If anyone knows of any tutorials or has any tips i would be very grateful.
Cheers
You can only pass content or interact with iframe content if it's on the same domain as the parent webpage that has the iframe. All browsers have a "same origin policy" that prevent you from being able to do that - sorry :(

How to allow users to embed YouTube & Vimeo videos?

How can I go about allowing users to embed YouTube and Vimeo videos in my Rails app?
I'd provide a text field or text area where users can add the link of the video they wish to embed.
Click add and have my app show a spinner while the details are being gathered.
When the details are found, I'd want them displayed on the page before user can finally submit the post.
I'm guessing the HTML, link details will need to be stored in the database so the video can automatically be displayed every time the page is visited.
HTML5 has a file API that gives me the ability to display users local file data on the fly. Wondering if there is something similar for display remote data or would normal ajax be used?
Is there a standard way of doing this? Also are there any tutorials out there on how to do this in rails? Would like to go about doing this in the most safest and securest way.
I love tutorials and screencasts so I'd really be thankful for info on where I can find one to achieve what I'm trying to achieve.
Try to use open graph protocol to fetch site information before user sending the form.
I suggest the following gem:
https://github.com/intridea/opengraph
Open graph protocol:
http://ogp.me/
And I guess you should store all the fetched information in database.
The Video Thumb gem is probably what you are looking for.
It handles vimeo, youtube and potentially others.
Then you just do:
<%= VideoPlayer::player(library_item.url, 700, 420).html_safe %>
In your view to display an automatically generated embed code.

How to attach a site thumbnail from user submitted links in a facebook application

The Facebook application I had in mind has users submit links from sites. I would like there to be a thumbnail of the site, similar to what happens when you post/message someone a link and a thumbnail automatically shows up. Any thoughts on how to go about doing this?
The sites you link to need to have Open Graph tags (https://developers.facebook.com/docs/opengraph/) on their pages to set the default image, description and title for this to happen. If those meta tags are not set, the first image on the page will be the default along with other generic information Facebook is able to scrape from the page.
If you want to test out a few pages and see what information they have set, use Facebook's URL lint tool (https://developers.facebook.com/tools/debug). Simply copy and paste any URL in there.

Resources