Class: Gist::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/rgist/content.rb

Constant Summary collapse

PATH =
'https://api.github.com/users/%s/gists'

Instance Method Summary collapse

Instance Method Details

#get(user, file) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rgist/content.rb', line 6

def get(user, file)
  begin
    response = curl(PATH % user)
    json     = JSON.parse(response)

    result = nil

    json.each do |gist|
      files = gist['files']

      if files.keys.include?(file)
        result = files[file]['raw_url']
      end
    end

    if result
      puts curl(result)
    else
      # Raise content not found
    end
  rescue Exception => exception
    raise exception
  end
end