class Msgtrail::GitHub

Constants

GIST_API_ENDPOINT
SUPPORTED_LANGUAGE
SUPPORTED_MIME_TYPE

Public Class Methods

fetch_gist(gist_id) click to toggle source
# 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) click to toggle source
# 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