Class: DocRepo::GithubFile
- Inherits:
-
Object
- Object
- DocRepo::GithubFile
- Defined in:
- lib/doc_repo/github_file.rb
Instance Attribute Summary collapse
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#org ⇒ Object
readonly
Returns the value of attribute org.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Instance Method Summary collapse
- #headers ⇒ Object
-
#initialize(file, org: DocRepo.configuration.org, repo: DocRepo.configuration.repo, branch: DocRepo.configuration.branch) ⇒ GithubFile
constructor
A new instance of GithubFile.
- #read_remote_file ⇒ Object
- #redirect_url ⇒ Object
- #url(file) ⇒ Object
Constructor Details
#initialize(file, org: DocRepo.configuration.org, repo: DocRepo.configuration.repo, branch: DocRepo.configuration.branch) ⇒ GithubFile
7 8 9 10 11 12 13 14 15 |
# File 'lib/doc_repo/github_file.rb', line 7 def initialize(file, org: DocRepo.configuration.org, repo: DocRepo.configuration.repo, branch: DocRepo.configuration.branch) @file = file @org = org @repo = repo @branch = branch end |
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
6 7 8 |
# File 'lib/doc_repo/github_file.rb', line 6 def branch @branch end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
6 7 8 |
# File 'lib/doc_repo/github_file.rb', line 6 def file @file end |
#org ⇒ Object (readonly)
Returns the value of attribute org.
6 7 8 |
# File 'lib/doc_repo/github_file.rb', line 6 def org @org end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
6 7 8 |
# File 'lib/doc_repo/github_file.rb', line 6 def repo @repo end |
Instance Method Details
#headers ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/doc_repo/github_file.rb', line 27 def headers hash = { "Accept" => "application/vnd.github.v3.raw", "User-Agent" => "RadiusNetworks-ProximityKit", } if ENV["GITHUB_TOKEN"] hash["Authorization"] = "token #{ENV["GITHUB_TOKEN"]}" end hash end |
#read_remote_file ⇒ Object
21 22 23 24 25 |
# File 'lib/doc_repo/github_file.rb', line 21 def read_remote_file open(url(file), headers).read rescue OpenURI::HTTPError => http_error raise DocRepo::NotFound.new(base: http_error) end |
#redirect_url ⇒ Object
17 18 19 |
# File 'lib/doc_repo/github_file.rb', line 17 def redirect_url "https://github.com/#{org}/#{repo}/raw/#{branch}/docs/#{file}" end |
#url(file) ⇒ Object
40 41 42 |
# File 'lib/doc_repo/github_file.rb', line 40 def url(file) "https://api.github.com/repos/#{org}/#{repo}/contents/docs/#{file}?ref=#{branch}" end |