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

Assignment stuff #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions example.config.rb

This file was deleted.

20 changes: 19 additions & 1 deletion github_info.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
require 'github_api'
require "#{Dir.pwd}/config"

github = Github.new basic_auth: "#{USERNAME}:#{PASSWORD}"
github = Github.new basic_auth: "#{USERNAME}:#{PASSWORD}"

github_gen = Github.new

repos = github_gen.repos.list 'AJLeonardi' #THIS DOES NOT DO WHAT I EXPECT, no idea where it's getting those repos from
repos.each do |repo|
puts repo['name']
end

repos = github.repos.list 'AJLeonardi' #This returns my repos!
repos.each do |repo|
puts repo['name']
end

repos = github.repos.list 'chrisvans' #this STILL returns my repos -- wtf??
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a logic branch in the api code which is the culprit...in repos.rb:

elsif authenticated?
  # For authenticated user
  get_request("/user/repos", params)
else

so when you're authenticated, aka have your parameters specified in the Github object, it will default to grabbing your own repos, regardless of what params you give it (I think). To see the other list, you'd have to use the github_gen object you create.

repos.each do |repo|
puts repo['name']
end

4 changes: 3 additions & 1 deletion lolcat_viewer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ def self.run(count=1)
end
nil
end
end
end

LolcatViewer.run(2)
25 changes: 25 additions & 0 deletions my_lolcatz.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'nokogiri'
require 'open-uri'

class LolcatViewer
def self.run(n = 1)
return_catz = Hash.new
url = 'http://www.lolcats.com'
links = []
Nokogiri::HTML(open(url + "/gallery/new.html")).css('.gallery-item a').each do |link|
links << link
end
n.times do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I like it! Cool way to not have to iterate through a bunch of urls to grab the direct link to the image, you only do it for the ones you select. I wish I had thought of this :)

arr_length = links.length
rand_index = rand(arr_length -1)
url_ext = links[rand_index]['href']
image_obj = Nokogiri::HTML(open(url + url_ext)).css('.picture-container>a>img')[0]
title = image_obj['alt']
img_url = url + image_obj['src']
return_catz[title] = img_url
end
return_catz.each do |title, link|
puts "title: " + title +" Link: " + link
end
end
end
19 changes: 19 additions & 0 deletions news_site.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'nokogiri'
require 'open-uri'

class NewOnionArticles
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, you might imagine doing this if you wanted to have on your blog or app a list of 'trending news articles'...you'd need some kind of model to back it up, but this would be an example of a model you wouldn't need to persist.

def self.run()
return_news = Hash.new
url = 'http://www.theonion.com'
Nokogiri::HTML(open(url)).css('section.recent-news a').each do |link|
title = link.content
link_url = link['href']
return_news[title] = url + link_url
end
return_news.each do |title, address|
puts 'Title: ' + title + ' Link: ' + address
end
end
end

NewOnionArticles.run()