Class: NetworkProfile::GithubProfile
- Inherits:
-
DefaultProfile
- Object
- DefaultProfile
- NetworkProfile::GithubProfile
- Includes:
- GithubGraphql
- Defined in:
- lib/network_profile/extractors/github_profile.rb
Class Method Summary collapse
Instance Method Summary collapse
- #extra_data ⇒ Object
- #image ⇒ Object
- #profile_data ⇒ Object
- #query ⇒ Object
- #text ⇒ Object
- #title ⇒ Object
Methods included from GithubGraphql
Methods inherited from DefaultProfile
all_types, auto_extractor_link_types, #data, #initialize, parse
Constructor Details
This class inherits a constructor from NetworkProfile::DefaultProfile
Class Method Details
.handle?(link) ⇒ Boolean
8 9 10 |
# 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 |
Instance Method Details
#extra_data ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# 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 ⇒ Object
74 75 76 |
# File 'lib/network_profile/extractors/github_profile.rb', line 74 def image profile_data['avatarUrl'] end |
#profile_data ⇒ Object
62 63 64 |
# File 'lib/network_profile/extractors/github_profile.rb', line 62 def profile_data json.dig('data', 'organization') || json.dig('data', 'user') end |
#query ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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 ⇒ Object
70 71 72 |
# File 'lib/network_profile/extractors/github_profile.rb', line 70 def text profile_data['bio'] end |
#title ⇒ Object
66 67 68 |
# File 'lib/network_profile/extractors/github_profile.rb', line 66 def title profile_data['name'] end |