Skip to content

Instantly share code, notes, and snippets.

@tyre
Created May 16, 2012 15:17
Show Gist options
  • Save tyre/2711142 to your computer and use it in GitHub Desktop.
Save tyre/2711142 to your computer and use it in GitHub Desktop.
Haters Gonna Hate
require 'json'
require 'faraday'
require 'awesome_print'
require 'hashie'
class Gister
attr_accessor :connection
attr_reader :gists
GIT_API_URL= "https://api.github.com/"
def initialize
self.connection = Faraday.new url: GIT_API_URL
get_public_gists
end
def get_public_gists
response = self.connection.get "/gists/public"
self.gists = response_to_hashie(response)
self.gists = filter_for_ruby_gists
end
def response_to_hashie(response)
array_of_json_hashes = JSON.parse(response.body)
array_of_json_hashes.inject([]) do |array, json_hash|
array << Hashie::Mash.new(json_hash)
end
end
def filter_for_ruby_gists
ruby_gists = self.gists.inject([]) do |array, gist|
gist_to_ruby = gist.ruby!
array << gist unless gist.files.empty?
array
end
end
private
def gists=(value)
@gists = value
end
end
class Hashie::Mash
RUBY_REGX = /ruby/i
def ruby!
self.files = ruby_gists
end
def ruby_gists
self.files.select do |file, info|
info.language =~ RUBY_REGX
end
end
end
x = Gister.new
ap x.gists
@HateBot
Copy link

HateBot commented May 16, 2012

Hater

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