forked from discourse/discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
martin sarsale
committed
Jul 10, 2013
1 parent
88ca51b
commit 21b29b4
Showing
3 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require_dependency 'oneboxer/handlebars_onebox' | ||
|
||
module Oneboxer | ||
class FacebookOnebox < HandlebarsOnebox | ||
|
||
matcher /^https?:\/\/www\.facebook\.com\/[a-z0-9_.-]+$/i | ||
favicon 'facebook.png' | ||
|
||
def template | ||
template_path('simple_onebox') | ||
end | ||
|
||
def translate_url | ||
uri = URI.parse(@url) | ||
"http://graph.facebook.com#{uri.path}" | ||
end | ||
|
||
def parse(json) | ||
|
||
data = JSON.parse(json) | ||
|
||
result = {} | ||
|
||
result[:title] = data["name"] | ||
|
||
result[:image] = data["cover"]["source"] if data["cover"] and data["cover"]["source"] | ||
|
||
text = [] | ||
text << data["about"] | ||
text << [data["location"]["street"],data["location"]["city"],data["location"]["state"],data["location"]["country"]].reject(&:blank?).join(", ") | ||
text << data["products"] | ||
text << data['website'] | ||
|
||
result[:text] = text.join("\n") | ||
|
||
result | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# encoding: utf-8 | ||
|
||
require 'spec_helper' | ||
require 'oneboxer' | ||
require 'oneboxer/amazon_onebox' | ||
|
||
describe Oneboxer::FacebookOnebox do | ||
before(:each) do | ||
@o = Oneboxer::FacebookOnebox.new("https://www.facebook.com/ArepasLaJuanita") | ||
FakeWeb.register_uri(:get, @o.translate_url, response: fixture_file('oneboxer/facebook.response')) | ||
end | ||
|
||
it "translates the URL" do | ||
@o.translate_url.should == "http://graph.facebook.com/ArepasLaJuanita" | ||
end | ||
|
||
it "generates the expected onebox for Facebook" do | ||
@o.onebox.should match_html expected_facebook_result | ||
end | ||
|
||
private | ||
def expected_facebook_result | ||
<<EXPECTED | ||
<div class='onebox-result'> | ||
<div class='source'> | ||
<div class='info'> | ||
<a href='https://www.facebook.com/ArepasLaJuanita' class="track-link" target="_blank"> | ||
<img class='favicon' src="/assets/favicons/facebook.png"> facebook.com | ||
</a> | ||
</div> | ||
</div> | ||
<div class='onebox-result-body'> | ||
<img src="http://sphotos-c.ak.fbcdn.net/hphotos-ak-prn1/s720x720/1010918_541800915877822_1282590823_n.jpg" class="thumbnail"> | ||
<h3><a href="https://www.facebook.com/ArepasLaJuanita" target="_blank">Arepas La Juanita</a></h3> | ||
Ricas arepas colombianas de puro maíz, elaboración artesanal. | ||
Buenos Aires, Argentina | ||
Arepas medianas amarillas, paquete x 5 unidades. | ||
Arepas medianas blancas, paquete x 5 unidades. | ||
</div> | ||
<div class='clearfix'></div> | ||
</div> | ||
EXPECTED | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
HTTP/1.1 200 OK | ||
Access-Control-Allow-Origin: * | ||
Cache-Control: private, no-cache, no-store, must-revalidate | ||
Content-Type: application/json; charset=UTF-8 | ||
ETag: "0e5049ec62f6471abcdb79ac0333ef691e48e300" | ||
Expires: Sat, 01 Jan 2000 00:00:00 GMT | ||
Pragma: no-cache | ||
X-FB-Rev: 869646 | ||
X-FB-Debug: UHGex33z4e8o80zsfE4jqwgcRE9g2dRqr4idlhGkNKc= | ||
Date: Tue, 09 Jul 2013 12:43:09 GMT | ||
Connection: keep-alive | ||
Content-Length: 715 | ||
|
||
{"about":"Ricas arepas colombianas de puro ma\u00edz, elaboraci\u00f3n artesanal.","category":"Food\/beverages","is_published":true,"location":{"street":"","city":"Buenos Aires","state":"","country":"Argentina","zip":""},"phone":"4345-4567","products":"Arepas medianas amarillas, paquete x 5 unidades.\nArepas medianas blancas, paquete x 5 unidades. ","talking_about_count":15,"username":"ArepasLaJuanita","were_here_count":0,"id":"517042601686987","name":"Arepas La Juanita","link":"http:\/\/www.facebook.com\/ArepasLaJuanita","likes":94,"cover":{"cover_id":541800915877822,"source":"http:\/\/sphotos-c.ak.fbcdn.net\/hphotos-ak-prn1\/s720x720\/1010918_541800915877822_1282590823_n.jpg","offset_y":38,"offset_x":0}} |