Module: Github::Blob

Defined in:
lib/github/blob.rb

Constant Summary collapse

ENDPOINT =
URI.join(Github::ROOT_ENDPOINT, 'repos/', "#{Github::OWNER}/", "#{Github::REPO}/", 'git/', 'blobs').to_s

Class Method Summary collapse

Class Method Details

.create(content, encoding = 'utf-8') ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/github/blob.rb', line 12

def self.create(content, encoding='utf-8')
  input = {
    'content' => content,
    'encoding' => encoding
  }

  resp = Github.post(ENDPOINT, input)
  raise "Github blob POST failed with http code: #{resp.code}" if resp.code != '201'
  ActiveSupport::JSON.decode(resp.body)['sha']
end

.get(sha) ⇒ Object



5
6
7
8
9
10
# File 'lib/github/blob.rb', line 5

def self.get(sha)
  raise 'invalid sha #{sha} when retrieving github blob' unless Github.valid_sha?(sha)
  resp = Github.get("#{ENDPOINT}/#{sha}")
  raise "Github blob retrieve failed with http code: #{resp.code}" if resp.code != '200'
  ActiveSupport::JSON.decode(resp.body)
end