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

Iterating through a gist's :files #506

Closed
jakelodwick opened this issue Sep 7, 2014 · 3 comments
Closed

Iterating through a gist's :files #506

jakelodwick opened this issue Sep 7, 2014 · 3 comments

Comments

@jakelodwick
Copy link

Let me preface this by saying I'm a r00b and might be missing something obvious, and apologize for wasting your time if that's the case.

I'm building a stream of gists from people I follow, and want to show each gist on this site's homepage.

When I run this...

octokit.gists.first.files

I get what looks like a hash of hashes:

{:"1-before.rb"=>
  {:filename=>"1-before.rb",
   :type=>"application/x-ruby",
   :language=>"Ruby",
   :raw_url=>
    "https://gist.githubusercontent.com/jakelodwick/7be5ac854ec9b0ed6494/raw/7de9d3539485db2859167b8f16bdefcdf60df3b2/1-before.rb",
   :size=>915},
 :"2-after.rb"=>
  {:filename=>"2-after.rb",
   :type=>"application/x-ruby",
   :language=>"Ruby",
   :raw_url=>
    "https://gist.githubusercontent.com/jakelodwick/7be5ac854ec9b0ed6494/raw/997e2f0efa1d0ce1e2269151f87bd471bee17448/2-after.rb",
   :size=>1587}}

I'd expect to be able to do something like this:

octokit.gists.first.files.each {|file| puts file}

...but the response is nil. I'm guessing this is because

>> octokit.gists.first.files.class #=> Sawyer::Resource

...instead of a hash.

Now, appending to_h to files allows me to iterate as expected, but it seems like an inelegant solution, creating a dependency on knowledge of Sawyer. What do you think? What's the right way to do this?

@Casao
Copy link

Casao commented Dec 1, 2014

Good point, I've opened lostisland/sawyer#33 which adds this directly to Sawyer's Resource object.

@jakelodwick
Copy link
Author

Awesome, thanks!

@pengwynn
Copy link
Collaborator

pengwynn commented Dec 2, 2014

Now available in v3.6.0. ✨

@pengwynn pengwynn closed this as completed Dec 2, 2014
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