Class: StateSync::GithubFetcher
- Inherits:
-
Object
- Object
- StateSync::GithubFetcher
- Defined in:
- lib/state_sync/fetchers/github_fetcher.rb
Constant Summary collapse
- API_BASE =
"https://api.github.com"
Instance Method Summary collapse
-
#fetch(path) ⇒ Object
Fetches raw file content (string) from GitHub.
-
#initialize(config) ⇒ GithubFetcher
constructor
A new instance of GithubFetcher.
Constructor Details
#initialize(config) ⇒ GithubFetcher
Returns a new instance of GithubFetcher.
9 10 11 |
# File 'lib/state_sync/fetchers/github_fetcher.rb', line 9 def initialize(config) @config = config end |
Instance Method Details
#fetch(path) ⇒ Object
Fetches raw file content (string) from GitHub. No ?ref= param — GitHub uses the repo’s default branch automatically.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/state_sync/fetchers/github_fetcher.rb', line 15 def fetch(path) uri = URI("#{API_BASE}/repos/#{@config.repo}/contents/#{path}") request = Net::HTTP::Get.new(uri) request["Accept"] = "application/vnd.github+json" request["X-GitHub-Api-Version"] = "2022-11-28" request["Authorization"] = "Bearer #{@config.token}" if @config.token response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(request) end handle_response(response, path) end |