Class: Potatochop::GithubInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/potatochop/github_interface.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, gh_options = {}) ⇒ GithubInterface

Returns a new instance of GithubInterface.



5
6
7
8
# File 'lib/potatochop/github_interface.rb', line 5

def initialize(repo, gh_options = {})
  @source = repo
  @gh_client = Octokit::Client.new access_token: gh_options[:access_token]
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



3
4
5
# File 'lib/potatochop/github_interface.rb', line 3

def source
  @source
end

Instance Method Details

#exists?(file_name) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
# File 'lib/potatochop/github_interface.rb', line 10

def exists?(file_name)
  begin
    @gh_client.contents(@source, path: file_name, accept: 'application/vnd.github.raw')
    true
  rescue Octokit::NotFound
    false
  end
end

#read(file_name) ⇒ Object



19
20
21
# File 'lib/potatochop/github_interface.rb', line 19

def read(file_name)
  @gh_client.contents(@source, path: file_name, accept: 'application/vnd.github.raw')
end