This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class User < ActiveRecord::Base | |
| has_secure_password | |
| has_many :books | |
| has_many :book_reports | |
| validates :username, presence: true, uniqueness: true | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Article | |
| attr_accessor :title, :description, :url | |
| @@all = [] | |
| def initialize(attributes) | |
| @title = attributes["title"] | |
| @description = attributes["description"] | |
| @url = attributes["url"] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def self.get_headlines(query) | |
| data = self.search_by_query(query) | |
| data["articles"] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #------------------------------------------------------------------------------# | |
| # 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 |
NewerOlder