data_importer/lib/github_api/user.rb
2022-04-18 15:14:54 -05:00

31 lines
No EOL
806 B
Ruby

require '/data_importer/lib/github_api/github_api.rb'
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.new(response.errors[:data].join(", "))
else
response.data.user
end
#end
end
end
end
class QueryExecutionError < StandardError; end