-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Step 1: Setup GitHub REST API Requests 🤙 #17
Comments
Decided to use https://github.com/edgurgel/tentacat for the GitHub API requests as it appears to be maintained. 👍 |
Used
We definitely need to paginate the request:
@doc """
List members of a `organization`.
The response will differ if the authenticated user is also owner of the
organization.
## Example
Tentacat.Organizations.Members.list "github"
Tentacat.Organizations.Members.list client, "github"
More info at: http://developer.github.com/v3/orgs/members/#members-list
"""
@spec list(Client.t(), binary) :: Tentacat.response()
def list(client \\ %Client{}, organization) do
get("orgs/#{organization}/members", client)
end Opened issue to confirm my understanding: edgurgel/tentacat#210 🤞 |
Might be able to use @doc """
Underlying utility retrieval function. The options passed affect both the
return value and, ultimately, the number of requests made to GitHub.
## Options
* `:pagination` - Can be `:none`, `:manual`, `:stream`, or `:auto`. Defaults to :auto.
- `:none` will only return the first page. You won't have access to the
headers to manually paginate.
- `:auto` will block until all the pages have been retrieved and
concatenated together. Most of the time, this is what you want. For
example, `Tentacat.Repositories.list_users("chrismccord")` and
`Tentacat.Repositories.list_users("octocat")` have the same interface
though one call will page many times and the other not at all.
- `:stream` will return a `Stream`, prepopulated with the first page.
- `:manual` will return a 3 element tuple of `{page_body,
url_for_next_page, auth_credentials}`, which will allow you to control
the paging yourself.
"""
@spec get(binary, Client.t()) :: response
@spec get(binary, Client.t(), keyword) :: response
@spec get(binary, Client.t(), keyword, keyword) ::
response | Enumerable.t() | pagination_response
def get(path, client, params \\ [], options \\ []) do
url =
client
|> url(path)
|> add_params_to_url(params)
case pagination(options) do
nil -> request_stream(:get, url, client.auth)
:none -> request_stream(:get, url, client.auth, "", :one_page)
:auto -> request_stream(:get, url, client.auth)
:stream -> request_stream(:get, url, client.auth, "", :stream)
:manual -> request_with_pagination(:get, url, client.auth)
end
end Thanks to edgurgel/tentacat#190 (comment) (comment on super-stale PR) 👀 Going to take a look at this on the Weekend. 🤞 |
Going to try and
Again, one for Saturday. ⏳ |
Response: [
{
"login": "alanshaw",
"id": 152863,
"node_id": "MDQ6VXNlcjE1Mjg2Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/152863?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/alanshaw",
"html_url": "https://github.com/alanshaw",
"followers_url": "https://api.github.com/users/alanshaw/followers",
"following_url": "https://api.github.com/users/alanshaw/following{/other_user}",
"gists_url": "https://api.github.com/users/alanshaw/gists{/gist_id}",
"starred_url": "https://api.github.com/users/alanshaw/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/alanshaw/subscriptions",
"organizations_url": "https://api.github.com/users/alanshaw/orgs",
"repos_url": "https://api.github.com/users/alanshaw/repos",
"events_url": "https://api.github.com/users/alanshaw/events{/privacy}",
"received_events_url": "https://api.github.com/users/alanshaw/received_events",
"type": "User",
"user_view_type": "public",
"site_admin": false
}
] |
Writing some |
{
blog: "http://gurgel.me",
location: "New Zealand",
email: nil,
avatar_url: "https://avatars.githubusercontent.com/u/30873?v=4",
events_url: "https://api.github.com/users/edgurgel/events{/privacy}",
public_repos: 32,
updated_at: "2024-12-08T08:00:45Z",
starred_url: "https://api.github.com/users/edgurgel/starred{/owner}{/repo}",
company: nil,
hireable: nil,
repos_url: "https://api.github.com/users/edgurgel/repos",
node_id: "MDQ6VXNlcjMwODcz",
bio: "INSUFFICIENT DATA FOR MEANINGFUL ANSWER",
organizations_url: "https://api.github.com/users/edgurgel/orgs",
twitter_username: nil,
user_view_type: "public",
html_url: "https://github.com/edgurgel",
followers_url: "https://api.github.com/users/edgurgel/followers",
following_url: "https://api.github.com/users/edgurgel/following{/other_user}",
received_events_url: "https://api.github.com/users/edgurgel/received_events",
public_gists: 13,
followers: 345,
gists_url: "https://api.github.com/users/edgurgel/gists{/gist_id}",
following: 67,
gravatar_id: "",
site_admin: false,
login: "edgurgel",
url: "https://api.github.com/users/edgurgel",
id: 30873,
name: "Eduardo Gurgel",
created_at: "2008-10-24T17:05:04Z",
type: "User",
subscriptions_url: "https://api.github.com/users/edgurgel/subscriptions"
} |
@spec list(Client.t(), binary) :: Tentacat.response()
def list(client \\ %Client{}, organization) do
get("orgs/#{organization}/members", client)
end Issue opened offering to add it: edgurgel/tentacat#219 |
Don't have to wait for the PR to be merged. ⏳ |
Need to handle the
https://github.com/kittenking has made their profile https://github.com/orgs/dwyl/people?query=kittenking dunno if this is a mistake on his part ... but since it might happen again, need to add a condition for it. ⏳ |
PR edgurgel/tentacat#220 merged. ✅ |
In order to get data from GitHub we need to setup the API.
According to the docs: https://docs.github.com/en/rest/overview/resources-in-the-rest-api 👀
the rate limiting for authenticated requests is
5,000/hour
. 5️⃣ 🦘That should be more than "enough" for what I have in mind. 📈
But if we need more we can easily add more API users. 💭
We've made HTTP Requests to the GitHub API before in previous projects:
So I think I can piece this together from previous code. 🤞
Todo
@dwyl
Org Members from the GitHub APIThe text was updated successfully, but these errors were encountered: