33 lines
825 B
Ruby
33 lines
825 B
Ruby
# frozen_string_literal: true
|
|
|
|
require '/data_importer/lib/github_api/github_api'
|
|
module GithubApi
|
|
class User
|
|
UserProfileQuery = GithubApi::Client.parse <<-'GRAPHQL'
|
|
query($username: String!) {
|
|
user(login: $username) {
|
|
id
|
|
login
|
|
name
|
|
avatarUrl
|
|
bio
|
|
bioHTML
|
|
location
|
|
}
|
|
}
|
|
GRAPHQL
|
|
|
|
def self.find(username)
|
|
# Retryable.retryable(tries: 3, on: QueryExecutionError, sleep: lambda { |n| 4**n } ) do
|
|
response = GithubApi::Client.query(UserProfileQuery, variables: { username: username })
|
|
if response.errors.any?
|
|
raise QueryExecutionError, response.errors[:data].join(', ')
|
|
else
|
|
response.data.user
|
|
end
|
|
# end
|
|
end
|
|
end
|
|
end
|
|
|
|
class QueryExecutionError < StandardError; end
|