Module: ActAsApiClient::Clients::GithubClient
- Includes:
- HttpClient
- Defined in:
- lib/act_as_api_client/clients/github_client.rb
Instance Method Summary collapse
-
#find(repository_name) ⇒ Hash
Searches Github for one repository by it’s owner and repository names.
-
#find_by(options = {}) ⇒ Array
Use this method if you need to get list of repositories selected by one of this conditions: user, authenticated_user, organization.
-
#where(query_string, parameters = {}) ⇒ Array
Search through Github repositories using query string and additional parameters explained on the Github Docs page.
Instance Method Details
#find(repository_name) ⇒ Hash
Searches Github for one repository by it’s owner and repository names. More details look at the corresponding Github Docs page
16 17 18 19 20 21 22 23 24 |
# File 'lib/act_as_api_client/clients/github_client.rb', line 16 def find(repository_name) unless repository_name.match?(%r{[a-zA-Z]/[a-zA-Z]}) raise StandardError, "repository_name parameter is not valid" end get("https://api.github.com/repos/#{repository_name}", headers: { "Accept" => "application/vnd.github.v3+json", "Authorization" => ([:token] ? "token #{[:token]}" : nil) }) end |
#find_by(options = {}) ⇒ Array
Use this method if you need to get list of repositories selected by one of this conditions: user, authenticated_user, organization
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/act_as_api_client/clients/github_client.rb', line 59 def find_by( = {}) unless .is_a?(Hash) raise StandardError, "provide a hash as an argument not #{.class.to_s.downcase}" end raise StandardError, "provide at least one parameter" if .keys.length.zero? raise StandardError, "method 'find_by' supports only one parameter" if .keys.length > 1 url = case .keys.first when :organization "https://api.github.com/orgs/#{[:organization]}/repos" when :user "https://api.github.com/users/#{[:user]}/repos" when :authenticated_user "https://api.github.com/repositories" end get(url, headers: { "Accept" => "application/vnd.github.v3+json", "Authorization" => ([:token] ? "token #{[:token]}" : nil) }) end |
#where(query_string, parameters = {}) ⇒ Array
Search through Github repositories using query string and additional parameters explained on the Github Docs page
40 41 42 43 44 45 |
# File 'lib/act_as_api_client/clients/github_client.rb', line 40 def where(query_string, parameters = {}) get("https://api.github.com/search/repositories", headers: { "Accept" => "application/vnd.github.v3+json", "Authorization" => ([:token] ? "token #{[:token]}" : nil) }, params: { q: query_string }.merge(parameters)) end |