data_importer/lib/github_api/user.rb
2022-04-19 02:37:27 -05:00

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