class NetworkProfile::GithubProfile

Public Class Methods

handle?(link) click to toggle source
# File lib/network_profile/extractors/github_profile.rb, line 8
def self.handle?(link)
  link.to_s[%r{github.com/[^/]+/?$}] && NetworkProfile.github_api_key
end

Public Instance Methods

extra_data() click to toggle source
# File lib/network_profile/extractors/github_profile.rb, line 78
def extra_data
  {
    company: profile_data['company'],
    location: profile_data['location'],
    profile_type: json.dig('data', 'organization') ? "organization" : "user",
    followers: profile_data.dig('followers', 'totalCount'),
    website: profile_data.dig('websiteUrl'),
    pinned: profile_data.dig('pinnedItems', 'edges').map { |i|
      n = i['node']
      { name: n['nameWithOwner'],
        url: n['url'],
        created: Time.parse(n['createdAt']).to_date,
        updated: Time.parse(n['updatedAt']).to_date,
        language: n.dig('primaryLanguage', 'name'),
        stars: n['stargazers']['totalCount'],
        watchers: n['watchers']['totalCount'] }
    }
  }
end
image() click to toggle source
# File lib/network_profile/extractors/github_profile.rb, line 74
def image
  profile_data['avatarUrl']
end
profile_data() click to toggle source
# File lib/network_profile/extractors/github_profile.rb, line 62
def profile_data
  json.dig('data', 'organization') || json.dig('data', 'user')
end
query() click to toggle source
# File lib/network_profile/extractors/github_profile.rb, line 12
    def query
      username = @link[%r{github.com/([^/]+)}, 1]
      <<~DOC
        query {
          organization(login:"#{username}") {
            avatarUrl
            name
            bio: description
            location
            websiteUrl
            ...RepoFragment
          }

          user(login:"#{username}") {
            avatarUrl
            name
            bio
            company
            location
            websiteUrl
            followers {
              totalCount
            }
            ...RepoFragment
          }
        }
        fragment RepoFragment on ProfileOwner {
          pinnedItems(first: 9, types: [REPOSITORY]) {
            edges {
              node {
                ... on Repository {
                  nameWithOwner,
                  url,
                  createdAt,
                  updatedAt
                  stargazers { totalCount }
                  watchers {
                    totalCount
                  },
                  primaryLanguage {
                    name
                  }
                }
              }
            }
          }
        }
      DOC
    end
text() click to toggle source
# File lib/network_profile/extractors/github_profile.rb, line 70
def text
  profile_data['bio']
end
title() click to toggle source
# File lib/network_profile/extractors/github_profile.rb, line 66
def title
  profile_data['name']
end