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

Create meta endpoints #199

Closed
benediktvaldez opened this issue Mar 3, 2015 · 12 comments
Closed

Create meta endpoints #199

benediktvaldez opened this issue Mar 3, 2015 · 12 comments
Milestone

Comments

@benediktvaldez
Copy link
Member

So we want to create meta endpoints, partially mapped from the official github API, but to some extent manually entered info.

/meta/maintainers > list of official maintainers
from /orgs/apis-is/public_members (only maintainers should be public members of the org)

/meta/contributors > list of all contributors
from /repos/apis-is/apis/contributors

/meta/sponsors > list of sponsors
if sponsors have a github user/org than it would be hardcoded into the endpoint

/meta/about > content that goes into the about section on the documentation page (hardcoded into endpoint)

@benediktvaldez benediktvaldez self-assigned this Mar 3, 2015
@benediktvaldez benediktvaldez added this to the APIs 2.0 milestone Mar 3, 2015
@koddsson
Copy link
Member

koddsson commented Mar 3, 2015

Maybe we could host all that under a /meta route? So /sponsors would be /meta/sponsors.

@kristjanmik
Copy link
Member

@koddsson genius. Please come back to the same continent so I can give you a big hug

@benediktvaldez
Copy link
Member Author

@koddsson agree completely - first we ruled it out, but we were thinking apis.is/apis/sponsors which looked weird, /meta is much better

@benediktvaldez
Copy link
Member Author

So I updated the initial comment to reflect this meta decision, but also added an /about subendpoint

@benediktvaldez benediktvaldez changed the title Create apis-related endpoints Create meta endpoints Mar 3, 2015
@koddsson
Copy link
Member

koddsson commented Mar 4, 2015

I started something in the v2-meta branch.

benediktvaldez added a commit that referenced this issue Mar 4, 2015
benediktvaldez added a commit that referenced this issue Mar 4, 2015
@benediktvaldez
Copy link
Member Author

@koddsson expanded on that - experimenting with the maintainers endpoint though, was thinking instead of just returning this

[
  {
    "login": "benediktvaldez",
    "avatar_url": "https://avatars.githubusercontent.com/u/1928103?v=3",
    "url": "https://api.github.com/users/benediktvaldez"
  },
  {
    "login": "koddsson",
    "avatar_url": "https://avatars.githubusercontent.com/u/318208?v=3",
    "url": "https://api.github.com/users/koddsson"
  }
]

I'd like to get something like this (getting the data from the url above)

[
  {
    "user": "benediktvaldez",
    "avatar": "https://avatars.githubusercontent.com/u/1928103?v=3",
    "name": "",
    "email": "",
    "bio": ""
  },
  {
    "user": "koddsson",
    "avatar": "https://avatars.githubusercontent.com/u/318208?v=3",
    "name": "",
    "email": "",
    "bio": ""
  }
]

But not sure how best to do that - was trying something like this ...

endpoint.get('/maintainers/', function(req, res, fail) {
  var options = {
    url: 'https://api.github.com/orgs/apis-is/public_members',
    headers: {
      'User-Agent': 'apis-is'
    }
  };

  request.get(options, function(err, response, body) {
    if (err) return res.json({error: err});

    var maintainers = _.map(JSON.parse(body), function(n) {
      var user = {};
      request.get({ url: n.url, headers: { 'user-agent': 'apis-is' } }, function(error, res, data) {
        if (err) return;
        user = JSON.parse(data);
      });
      var maintainer = {
        'user': n.login,
        'avatar': n.avatar_url
      };
      maintainer.name = user.name;
      maintainer.email = user.email;
      maintainer.hireable = user.hireable;
      maintainer.bio = user.bio;
      return maintainer;
    });

    return res.json(maintainers);
  });
});

... but the second request hasn't finished at return res.json(maintainers) leaving me with nothing but user and avatar

I think my approach is wrong - thoughts?

Also @MiniGod - you're clever, thoughts? 😄

@MiniGod
Copy link
Member

MiniGod commented Mar 4, 2015

Use async.map instead, and move all the logic into the inner request.get callback, then res.json in the result callback of async.map.

@koddsson
Copy link
Member

koddsson commented Mar 5, 2015

I've got something working but got hit by the github api rate limit. Will pick it up tomorrow.

@koddsson
Copy link
Member

koddsson commented Mar 5, 2015

screen shot 2015-03-04 at 22 03 12

Something like this? It's missing bio and I might have drunk to much of the async kool-aid so I'm gonna sober up and I'll push it tomorrow once I've had a change to refactor and clean it up a bit.

@benediktvaldez
Copy link
Member Author

Looks great @koddsson - looking forward to it 😺

@koddsson
Copy link
Member

koddsson commented Mar 7, 2015

Added bio and removed hirable. I just pushed the async madness, I think it's a correct approach to this but I'm new to async so I'm not 100%. Check it out and tell me what you think :)

@kristjanmik
Copy link
Member

Meta has been merged so I'm closing this. Create a new thread to work on updates

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

No branches or pull requests

4 participants