Created
October 2, 2019 17:00
-
-
Save shaunfink/fa6ee390d66e209c87be1f1e684c19fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'net/http' | |
require 'json' | |
class GetGitRelease | |
# Set the Gut API URL | |
@@git_api_url = "https://api.github.com" | |
# Initialize the object | |
def initialize(owner, repo, vtag, osarch) | |
@owner = owner | |
@repo = repo | |
@vtag = vtag | |
@osarch = osarch | |
end | |
# Get the download URL | |
def download_urls() | |
if(@vtag == "latest") | |
uri = URI("#{@@git_api_url}/repos/#{@owner}/#{@repo}/releases/latest") | |
else | |
uri = URI("#{@@git_api_url}/repos/#{@owner}/#{@repo}/releases/tags/#{@vtag}") | |
end | |
response = Net::HTTP.get(uri) | |
release = JSON.parse(response) | |
release['assets'].each do |assets| | |
if (assets['browser_download_url'].include? @osarch) | |
puts assets['browser_download_url'] | |
end | |
end | |
end | |
end | |
# Create Objects | |
om = GetGitRelease.new("pivotal-cf", "om", "latest", "linux") | |
jq = GetGitRelease.new("stedolan", "jq", "latest", "linux") | |
# Call Methods | |
om.download_urls() | |
jq.download_urls() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment