Skip to content

Instantly share code, notes, and snippets.

View HopperMCS's full-sized avatar

G. F. Hopper HopperMCS

View GitHub Profile
require 'pry'
class AuthenticationsController < ApplicationController
get '/signup' do
@user = User.new
already_authenticated
erb :'./authentication/signup'
end
post "/signup" do
# Create a new ActiveRecord object using params submitted by Sinatra
class User < ActiveRecord::Base
has_secure_password
has_many :books
has_many :book_reports
validates :username, presence: true, uniqueness: true
end
def article_navigator
while @input != "exit" && @input != "query"
puts "Choose a number"
@input = gets.chomp
index = @input.to_i - 1
if index > 9
puts "Wrong input, try again"
else
break if index < 0
selected_article = Article.all[index]
def article_search
@input = gets.chomp
Article.search(@input) unless @input == "exit"
Article.all.each.with_index(1) do |art, index|
puts "#{index}. #{art.title}"
end
end
def start
API.api_public_key
puts "Welcome to the News CLI!"
menu
@input = "query"
while @input != "exit" && @input != "quit" && @input != "q"
Article.clear
article_search
article_navigator
class Article
attr_accessor :title, :description, :url
@@all = []
def initialize(attributes)
@title = attributes["title"]
@description = attributes["description"]
@url = attributes["url"]
end
def self.search_by_query(query)
query_f = ERB::Util.url_encode("#{query}")
url = "https://newsapi.org/v2/everything?qInTitle=#{query_f}&pageSize=10&page=1&apiKey=#{self.api_public_key}"
req = URI.open(url)
response_body = req.read
json = JSON.parse(response_body)
end
def self.api_public_key
begin
@@public = File.open(File.expand_path("~/.newsfeed_key")).read.strip
rescue
puts "No public key found. Please follow the instructions at https://newsapi.org to get your keys."
# create public key
puts "Please enter your public key:"
@@public = gets.strip
return if @@public == "exit"
def self.get_headlines(query)
data = self.search_by_query(query)
data["articles"]
end
#------------------------------------------------------------------------------#
# OFFICIAL UBUNTU REPOS #
#------------------------------------------------------------------------------#
###### Ubuntu Main Repos
deb http://....archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://....archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse