Skip to content

Commit

Permalink
insert github user #17
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Dec 14, 2024
1 parent b375ac9 commit ff28e1a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 5 deletions.
28 changes: 24 additions & 4 deletions lib/app/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,45 @@ defmodule App.User do

client = Tentacat.Client.new(%{access_token: token})
{200, data, _res} = Tentacat.Organizations.Members.list(client, org_name)
dbg(data)
# dbg(data)
Useful.atomize_map_keys(data)
end

def get_user_from_api(username) do
token = Envar.get("GH_PERSONAL_ACCESS_TOKEN")
client = Tentacat.Client.new(%{access_token: token})
{200, data, _res} = Tentacat.Users.find(client, username)
Useful.atomize_map_keys(data)
{:ok, entry} = Useful.atomize_map_keys(data)
|> dbg
|> map_github_user_fields_to_table()
|> create()

entry
end

# Next: get list of org members
# get user for each in the list
# map data to our table
# insert data

def map_github_user_fieldsre(entry) do
def map_github_user_fields_to_table(u) do
%{

id: u.id,
avatar_url: String.split(u.avatar_url, "?") |> List.first,
bio: u.bio,
blog: u.blog,
company: String.replace(u.company, "@", ""),
created_at: u.created_at,
email: u.email,
followers: u.followers,
following: u.following,
hireable: u.hireable,
location: u.location,
login: u.login,
name: u.name,
public_repos: u.public_repos,
two_factor_authentication: false,
updated_at: u.updated_at
}
end

Expand Down
38 changes: 37 additions & 1 deletion test/app/user_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule App.UserTest do
end

test "get_org_members_from_api/1" do
App.User.get_org_members_from_api("dwyl") |> dbg
App.User.get_org_members_from_api("dwyl") # |> dbg
assert true == true
end

Expand All @@ -36,3 +36,39 @@ defmodule App.UserTest do
assert data.public_repos > 30
end
end

%{
organizations_url: "https://api.github.com/users/iteles/orgs",
following: 80,
login: "iteles",
public_repos: 31,
received_events_url: "https://api.github.com/users/iteles/received_events",
bio: "Co-founder @dwyl \r\n",
user_view_type: "public",
company: "@dwyl",
gravatar_id: "",
twitter_username: nil,
following_url: "https://api.github.com/users/iteles/following{/other_user}",
created_at: "2013-04-17T21:10:06Z",
followers: 400,
site_admin: false,
blog: "http://www.twitter.com/iteles",
starred_url: "https://api.github.com/users/iteles/starred{/owner}{/repo}",
public_gists: 0,
hireable: true,
gists_url: "https://api.github.com/users/iteles/gists{/gist_id}",
events_url: "https://api.github.com/users/iteles/events{/privacy}",
followers_url: "https://api.github.com/users/iteles/followers",
node_id: "MDQ6VXNlcjQxODUzMjg=",
url: "https://api.github.com/users/iteles",
id: 4185328,
name: "Ines Teles Correia",
subscriptions_url: "https://api.github.com/users/iteles/subscriptions",
html_url: "https://github.com/iteles",
location: "London, UK",
type: "User",
avatar_url: "https://avatars.githubusercontent.com/u/4185328?v=4",
email: nil,
repos_url: "https://api.github.com/users/iteles/repos",
updated_at: "2024-08-05T22:59:09Z"
}

0 comments on commit ff28e1a

Please sign in to comment.