Skip to content
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

Provide data in json via very simple API, suitable for further analysis by the users #87

Open
nealmcb opened this issue Jul 12, 2017 · 5 comments

Comments

@nealmcb
Copy link

nealmcb commented Jul 12, 2017

As noted in #5, #6, #83, #86, etc, users are often interested in further analysis of the results of their searches.

One simple way to help some of them would be to provide a very simple API to opensourcecontributors to provide the search results data in json format. It would ideally be structured so as to make it easy for users, via the github api, and their own language of choice, to do further queries and analysis. A few examples would go a long way.

This would probably also result in code that was useful for implementing the feature requests listed above.

@nealmcb nealmcb changed the title Provide data via very simple json API, suitable for further analysis by the users Provide data in json via very simple API, suitable for further analysis by the users Jul 12, 2017
@hut8
Copy link
Member

hut8 commented Jul 13, 2017

There already is a simple API, actually. The front end uses it directly. No authentication is necessary. Would you be interested in documenting it?

These are the only endpoints: https://github.com/tenex/opensourcecontributors/blob/master/ghc-app/controller.go#L34

@nealmcb
Copy link
Author

nealmcb commented Jul 13, 2017

Hmm. I tried all those endpoints, and the /user... ones return html, not json. E.g. https://opensourcecontributo.rs/user/nealmcb

The others were just 404 for me. Am I missing something?

@joshjordan
Copy link
Member

Yeah, the missing piece of the puzzle is that nginx routes to the API only under the /api/ path. Check it out:

https://opensourcecontributo.rs/api/user/nealmcb
https://opensourcecontributo.rs/api/user/nealmcb/events
etc

@nealmcb
Copy link
Author

nealmcb commented Jul 13, 2017

Indeed - thank you!

I hope to find time to come back to provide proper documentation, but here is an API usage example, in Python, for how to retrieve all events for a user, and hints on sorting them out:

import json
import urllib.request
import codecs

def getevents(userid):
    "Retrieve and return all event pages for given userid"

    reader = codecs.getreader("utf-8")

    events = []
    pagenum = 1
    while True:
        url = "https://opensourcecontributo.rs/api/user/{}/events/{}".format(userid, pagenum)
        page = json.load(reader(urllib.request.urlopen(url)))
        if page["size"] == 0:
            break
        events += page["events"]
        pagenum += 1

    return events

events = getevents("myuserid")  # put userid you want in here

events is now a dict, and the type field indicates whether it is an IssueCommentEvent, PushEvent, IssuesEvent, GollumEvent, CommitCommentEvent, etc.

@nealmcb
Copy link
Author

nealmcb commented Jul 13, 2017

See also:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants