class Onebox::Engine::StackExchangeOnebox
Public Class Methods
domains()
click to toggle source
# File lib/onebox/engine/stack_exchange_onebox.rb, line 10 def self.domains %w(stackexchange.com stackoverflow.com superuser.com serverfault.com askubuntu.com stackapps.com mathoverflow.net) .map { |domain| Regexp.escape(domain) } end
Public Instance Methods
always_https?()
click to toggle source
# File lib/onebox/engine/stack_exchange_onebox.rb, line 17 def always_https? uri.host.split('.').length <= 3 end
Private Instance Methods
data()
click to toggle source
# File lib/onebox/engine/stack_exchange_onebox.rb, line 39 def data return @data if defined?(@data) result = raw['items'][0] if result result['creation_date'] = Time.at(result['creation_date'].to_i).strftime("%I:%M%p - %d %b %y %Z") result['tags'] = result['tags'].take(4).join(', ') result['is_answer'] = result.key?('answer_id') result['is_question'] = result.key?('question_id') end @data = result end
match()
click to toggle source
# File lib/onebox/engine/stack_exchange_onebox.rb, line 23 def match @match ||= @url.match(@@matcher) end
url()
click to toggle source
# File lib/onebox/engine/stack_exchange_onebox.rb, line 27 def url domain = uri.host question_id = match[:question_id] answer_id = match[:answer_id2] || match[:answer_id1] if answer_id "https://api.stackexchange.com/2.2/answers/#{answer_id}?site=#{domain}&filter=!.FjueITQdx6-Rq3Ue9PWG.QZ2WNdW" else "https://api.stackexchange.com/2.2/questions/#{question_id}?site=#{domain}&filter=!5-duuxrJa-iw9oVvOA(JNimB5VIisYwZgwcfNI" end end