lib/hacker_news/api_connector.rb
# generate article with page id's, return "count" articles
generate article with page id's, return "count" articles
generate article with page id ' s return " count " articles
def generate_article(page_data, count = 1)
      print "Loading articles."
      stories = [ ]
      i = 0
      while i < count
        print "."
        story_url = "https://hacker-news.firebaseio.com/v0/item/" + "#{page_data[i]}.json"
        story_uri = URI(story_url)
        story_response = Net::HTTP.get(story_uri)
        story = JSON.parse(story_response)
        new_story = {:title => story["title"] ||= nil,
                    :id => story["id"] ||= nil,
                    :type => story["type"] ||= nil,
                    :author => story["by"] ||= nil,
                    :time => story["time"] ||= nil,
                    :text => story["text"] ||= nil,
                    :url => story["url"] ||= nil,
                    :parent => story["parent"] ||= nil,
                    :descendants => story["descendants"] ||= nil,
                    :kids => story["kids"] ||= nil}
        stories << new_story
        i += 1
      end
      print "\n"
      stories
    end
def generate_article ( page_data , count = 1 ) print "Loading articles." stories = [ ] i = 0 while i < count print "." story_url = "https://hacker-news.firebaseio.com/v0/item/" + "#{page_data[i]}.json" story_uri = URI ( story_url ) story_response = Net :: HTTP . get ( story_uri ) story = JSON . parse ( story_response ) new_story = { :title => story [ "title" ] ||= nil , :id => story [ "id" ] ||= nil , :type => story [ "type" ] ||= nil , :author => story [ "by" ] ||= nil , :time => story [ "time" ] ||= nil , :text => story [ "text" ] ||= nil , :url => story [ "url" ] ||= nil , :parent => story [ "parent" ] ||= nil , :descendants => story [ "descendants" ] ||= nil , :kids => story [ "kids" ] ||= nil } stories << new_story i += 1 end print "\n" stories end
generate article with page id's, return "count" articles
generate article with page id ' s return " count " articles
# print current status to user # return variable # request each article via it's post id # set URL #get page data # article hash builder # return array with articles as hash
page_data
count