Get user events with Github API and Octokit
Asked Answered
M

2

0

I'm trying to make a simple call to retrieve user events on github through octokit.

According to the docs I create new client and visit the user events endpoint.

client = Octokit::Client.new(access_token: my_token)
user = client.user

Up to here it works fine, now I continue with

events = user.events
=> nil

Alternatively, when I do

client = Octokit::Client.new(access_token: my_token, api_endpoint: 'users/:user/events')

I get

#<Octokit::Client:0x007f9a78ac04f8...

but how to get list of events from there? Here is the official doc https://developer.github.com/v3/activity/events/#list-events-performed-by-a-user

Molten answered 8/9, 2014 at 5:5 Comment(0)
D
1

I think what you want is

client = Octokit::Client.new(access_token: my_token)
user = client.user
events = client.user_events user.login

It isn't exactly intuitive and I had to read the source. I haven't had a chance to test this yet but there doesn't appear to be a better way.

Dorise answered 9/9, 2014 at 0:15 Comment(3)
Thanks a lot, you were close. Here is how to retrieve events events = client.user_events(user.login)Molten
@olivier feel free to edit my answer then :D That aside, I feel like that might be a bug. I thought octokit accepted objects as well as strings but I'm probably wrong.Dorise
@olivier sorry that they rejected your edit. Had I been online and seen it, I would havea ccepted it.Dorise
I
0

You have a typo:

client = Octokit::Client::new(access_token: my_token)
                        ^^

Should be:

client = Octokit::Client.new(access_token: my_token)
                        ^
Islamize answered 8/9, 2014 at 6:40 Comment(1)
correct but it's a typo. I'm able to connect but not retrieve the data I'm looking for. any idea?Molten

© 2022 - 2024 — McMap. All rights reserved.