data_importer/lib/github_api/user.rb

31 lines
806 B
Ruby
Raw Normal View History

2022-04-11 18:45:02 -05:00
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)
2022-04-18 15:14:54 -05:00
#Retryable.retryable(tries: 3, on: QueryExecutionError, sleep: lambda { |n| 4**n } ) do
2022-04-11 18:45:02 -05:00
response = GithubApi::Client.query(UserProfileQuery, variables: { username: username })
if response.errors.any?
raise QueryExecutionError.new(response.errors[:data].join(", "))
else
response.data.user
end
2022-04-18 15:14:54 -05:00
#end
2022-04-11 18:45:02 -05:00
end
end
end
class QueryExecutionError < StandardError; end