How do I grab meta data from other websites and display on mine in ruby on rails? - ruby-on-rails

When using FB or Google + I can paste a link of any website into the status update box and it will instant load information about that website with the option of flicking through thumbnail images.
How can I go about achieving this in ruby on rails? All my searches seem to bring up php methods on how to do this.
For grabbing video data info I use the Ruby Open Graph Protocol gem. Is there any thing for grabbing data the way FB and G+ do? If not is there a standard way this is done in rails/ruby, if so.. how is this done?
Kind regards

I think you're looking for something like oembed. I've found a gems for that, so I propose you to take look at it: https://github.com/judofyr/ruby-oembed or https://github.com/embedly/embedly-ruby

You should likely use a gem like http://nokogiri.org/
It allows you to work with a html page just as you would do with jQuery. Very handy.

Related

Display all tweets with a certain hashtag with simple design

I'm developing some website using Rails. I want to add "our users' tweets" part to the main page. I need an advice how I can do it better. I hoped to get standard way to do it, may be some Twitter widget or something else. I used Google, but I've found nothing. Please, point me to the right path. Sorry if my questions is very simple, but I don't really know how to do it. I hope that I needn't parse JSON and add styles independently; I need simple design from Twitter :)
To answer your [ambiguous] question, there are a number of things to consider:
How will you retrieve the tweets?
How will you store / access them?
How will the data be displayed on front-end?
The two methods you have are either to use the Twitter gem, or the TwitterFetcher JS plugin:
Gem
The Twitter gem uses the Twitter API to pull data from the official Twitter API. This means you've got the throttling & authentication to build into your app
The benefits of using this gem is it gives you a HUGE amount of flexibility with the data. You can pull as much data as you need / want, in whatever format you want - all formatted in JSON & can be displayed on your site
This gem is best suited to storing your tweets, either in a DB or in Redis etc, otherwise you'll have massive synchronous dependency on Twitter's API - which is never good for performance
JS
The TwitterFetcher JS plugin is epic - basically takes a Twitter widget & strips out the HTML, allowing you to style it how you like
This is the most effective way to retrieve Twitter data on-the-fly, as it's asynchronous, relies on Twitter's widget system (far more robust than API), and stores no data locally

how to get twitter feeds in shopify

I am trying to get twitter feeds in to my shopify site. I want to get the feeds and style them as I want and thus cant use a app.
I know how to do it using PHP but can not use that code in shopify and looking for a way I can use OAuth in shopify and get the feeds. I tried the shopify docs but without an example its kinda hard to actually get my head around it.
http://docs.shopify.com/api/tutorials/oauth
Thats the link I am using as a guide. If anyone can direct me to an example which might be similar that would be awesome. (google didnt seem to be that helpful this time either)
Cheers
I know you said you didn't want to use an app, but can I suggest taking a look at Twitify? You can use custom CSS to style your tweets. Also see discussions about Twitify here and here.
Twitter changed their display guidelines and policies on embedding of tweets on websites in June 2013. One of the themes I used for a client earlier in the year had custom styling of tweets, and they have now changed it to use the official Twitter widget to meet the new guidelines. In fact, the images on the Shopify theme store show how it used to look before Twitter changed things:
And after:
I think using an app like Twitify would be the easiest way to deal with these changes to embedding tweets.
Thanx for the suggestion. I did take a look at that before I posted this question. This is a project for a client and I dont think getting a plug in is a viable option. Anyways I found a work around.
Hosted the file on a server and then accessed it. So that resolved the problem. :)
I used node.js to write the script and get the posts as required.
Cheers.
you can use the app for that Twitify https://apps.shopify.com/twitify or you can Embed a Twitter feed in your online store
Go to your Twitter settings.
Click Widgets to open the widgets menu.
Create a new widget, following Twitter's instructions.
Copy the embed code.

Click on Print gives a screen shot to save in rails3

I may fall under the list of possible duplicates but still i could not find the answer according to my req.In my rails application i have some web pages with a link of print option.
Now what i need is when i click on this print ,i should get a screen shot of the current web page and a popup box to save the image .Is there any plugin available for the same.
Also any queries for code are welcome
Thanx
You could go for phantomJs. Where you can alter the page HTML, manipulate CSS, insert & call javascript snippets, the way you need it.
Good documentation available and also you can find great deal of help in stackoverflow-phantomjs
Regards,
HBK
May i suggest that you use http://www.w3.org/TR/css-print/
if you want to make a screeenshot you have to work with the user env, so i suggest you look at this topic How do I take screenshots of web pages using ruby and a unix server?

dynamic web badge in rails without javascript

I'm trying to create a web badge with user ranking. Intend for it to be used in forums where javascript might not be enabled. I have come across this
<img src='http://www.x.com/vendor.gif.aspx?id=123' style='width:50px; height:50px'/>
from How does one get about making a dynamic web badge using client side javascript?
But i'm using ruby on rails.
Anybody has an alternative method or some hints? Thanks much.
You can create an image using RMagick (uses imagemagick). Use the annotate method to put text in your image.
You don't need JavaScript. Just create a Rails action, which serves the image or whatever you want to be the badge.
<img src="/users/123/badge" ....>
You may want to ask how to create an image with Rails, but that will be a different story ;-)
(ImageMagick comes to mind)
You can create the image with RMagick on the server and then return it to the browser.
Here is a link to an article explaining how to create images.
You'll then need the send_data method in Rails.
I'll try and dig up a link that explains this exactly.

How do I add a twitter search feed to my Ruby on Rails application?

I want to add a twitter feed for a specific keyword search to my rails application. Where should I start?
You might start with one of the Twitter API libraries written for Ruby.
You may want to consider grabbing the RSS feed for the search and parsing that. I show that in Railscasts episode 168. If you need something more fancy the API is the way to go as Dav mentioned.
But whichever solution you choose, it's important to cache the search results locally on your end. This way your site isn't hitting Twitter every time someone goes to the page. This improves performance and will make your site more stable (not breaking when twitter breaks). You can have the cache auto-update every 10 minutes (or whatever fits) using a cron task.
We download and store the tweets in a local database. I recently wrote a blog post about how I achieved this:
http://www.arctickiwi.com/blog/16-download-you-twitter-feed-using-ruby-on-rails-with-oauth
You can then use will_paginate to handle your pagination and go back as far as you want.

Resources