comment out twitter onebox, it is bust
This commit is contained in:
parent
270161d8b8
commit
c47239b536
|
@ -31,8 +31,12 @@ module Oneboxer
|
|||
{'User-Agent' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3'}
|
||||
end
|
||||
|
||||
def fetch_html
|
||||
open(translate_url, http_params).read
|
||||
end
|
||||
|
||||
def onebox
|
||||
html = open(translate_url, http_params).read
|
||||
html = fetch_html
|
||||
args = parse(html)
|
||||
return default_url unless args.present?
|
||||
args[:original_url] = @url
|
||||
|
|
|
@ -1,19 +1,28 @@
|
|||
# TODO implement per: http://meta.discourse.org/t/twitter-oneboxes-are-bust/7410/3
|
||||
require_dependency 'oneboxer/handlebars_onebox'
|
||||
|
||||
module Oneboxer
|
||||
class TwitterOnebox < HandlebarsOnebox
|
||||
|
||||
matcher /^https?:\/\/(?:www\.)?twitter.com\/.*$/
|
||||
REGEX = /^https?:\/\/(?:www\.)?twitter.com\/(?<user>[^\/]+)\/status\/(?<id>\d+)$/
|
||||
# matcher REGEX
|
||||
|
||||
# TODO: use zocial instead
|
||||
favicon 'twitter.png'
|
||||
|
||||
def translate_url
|
||||
m = @url.match(/\/(?<user>[^\/]+)\/status\/(?<id>\d+)/mi)
|
||||
return "http://api.twitter.com/1/statuses/show/#{URI::encode(m[:id])}.json" if m.present?
|
||||
@url
|
||||
def fetch_html
|
||||
m = @url.match(REGEX)
|
||||
|
||||
if SiteSetting.twitter_consumer_key.present? && SiteSetting.twitter_consumer_secret.present?
|
||||
token = prepare_access_token(SiteSetting.twitter_consumer_key, SiteSetting.twitter_consumer_secret)
|
||||
token.request(:get, "https://api.twitter.com/1.1/statuses/show/#{URI::encode(m[:id])}.json")
|
||||
else
|
||||
# perhaps?
|
||||
raise Discourse::SiteSettingMissing
|
||||
end
|
||||
end
|
||||
|
||||
def parse(data)
|
||||
|
||||
result = JSON.parse(data)
|
||||
|
||||
result["created_at"] = Time.parse(result["created_at"]).strftime("%I:%M%p - %d %b %y")
|
||||
|
@ -26,5 +35,13 @@ module Oneboxer
|
|||
result
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def get_message_json(consumer_key, consumer_secret)
|
||||
raise "NOT IMPLEMENTED"
|
||||
# implement per http://meta.discourse.org/t/twitter-oneboxes-are-bust/7410/3
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue