Class: GerminateGist::GistPublisher

Inherits:
Germinate::Publisher
  • Object
show all
Defined in:
lib/germinate-gist/gist_publisher.rb

Constant Summary collapse

GISTS_URL =
'http://gist.github.com/gists'
NEW_GIST_URL =
'http://gist.github.com/api/v1/xml/new'
EXISTING_GIST_URL =
'http://gist.github.com/api/v1/xml/'
PUBLIC_GIST_URL =
'http://gist.github.com/'

Instance Method Summary collapse

Constructor Details

#initialize(name, librarian, options = {}) ⇒ GistPublisher

Returns a new instance of GistPublisher.



14
15
16
17
18
19
# File 'lib/germinate-gist/gist_publisher.rb', line 14

def initialize(name, librarian, options={})
  @resource_class = options.delete(:resource_class) { RestClient::Resource }
  super
  @git = Git.init
  self.selector = "$SOURCE"
end

Instance Method Details

#github_loginObject



34
35
36
# File 'lib/germinate-gist/gist_publisher.rb', line 34

def 
  @git.config('github.user') or raise GerminateGist::GithubConfigError
end

#github_tokenObject



38
39
40
# File 'lib/germinate-gist/gist_publisher.rb', line 38

def github_token
  @git.config('github.token') or raise GerminateGist::GithubConfigError
end

#publish!(output, extra_options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/germinate-gist/gist_publisher.rb', line 21

def publish!(output, extra_options={})
  if librarian.variables.key?('GIST_ID')
    put_gist!(librarian.variables['GIST_ID'])
  else
    post_gist!
  end

rescue RestClient::ExceptionWithResponse => error
  log.error "Error posting to gist: #{error.message}"
  log.debug "Response from Gist: #{error.response.message}\n#{error.response.body}"
  raise UserError, error.message
end