lib/onebox/engine/github_gist_onebox.rb in onebox-1.1.0 vs lib/onebox/engine/github_gist_onebox.rb in onebox-1.2.0
- old
+ new
@@ -1,33 +1,33 @@
module Onebox
module Engine
class GithubGistOnebox
include Engine
- include JSON
matches do
http
with("gist.")
domain("github")
tld("com")
end
def url
- "https://api.github.com/gists/#{match[:number]}"
+ "https://api.github.com/gists/#{match[:sha]}"
end
+ def to_html
+ "<script src=\"http://gist.github.com/#{match[:sha]}.js\"></script>"
+ end
+
private
- def match
- @url.match(/gist\.github\.com\/([^\/]+\/)?(?<number>[0-9a-f]+)/)
+ def data
+ { sha: match[:sha], title: match[:sha], link: @url }
end
- def data
- {
- url: @url,
- content: raw["files"].first[1]["content"],
- author: raw["user"]["login"]
- }
+ def match
+ @match ||= @url.match(%r{gist\.github\.com/([^/]+/)?(?<sha>[0-9a-f]+)})
end
+
end
end
end