Class: Msgtrail::GitHub
- Inherits:
-
Object
- Object
- Msgtrail::GitHub
- Defined in:
- lib/msgtrail/github.rb
Constant Summary collapse
- SUPPORTED_MIME_TYPE =
'text/plain'.freeze
- SUPPORTED_LANGUAGE =
'Markdown'.freeze
- GIST_API_ENDPOINT =
"https://api.github.com/gists/%s".freeze
Class Method Summary collapse
Class Method Details
.fetch_gist(gist_id) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/msgtrail/github.rb', line 24 def self.fetch_gist(gist_id) begin url = GIST_API_ENDPOINT % gist_id result = HTTP.get(url) rescue puts("Can't access '#{url}' (#{$!})") exit(2) end begin json = MultiJson.load(result.to_s, symbolize_keys: true) rescue puts("Invalid JSON from '#{url}' (#{$!})") exit(2) end json end |
.gist_bodies(gist_id) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/msgtrail/github.rb', line 8 def self.gist_bodies(gist_id) json = fetch_gist(gist_id) source = json[:html_url] bodies = [] json[:files].each do |key, value| if SUPPORTED_MIME_TYPE == value[:type] && SUPPORTED_LANGUAGE == value[:language] bodies << { body: value[:content], source: source, type: Article::TYPE_GIST } end end bodies end |