I am new to Ruby on Rails and need some advice on this! I trying to build a webscraper and have a JSON file here at Kimono Labs, where you can turn website data into API's:
https://www.kimonolabs.com/api/3obhv4p0?apikey=WWHHbKEkOmAPXsObOccPBXTb5NgRyCNO that I want to save to the database of my Ruby on Rails application.
Specifically it's the "results" key that I want to save to the database. It contains data from Google Finance with the company, URL to quote page, P/E and latest price. Which has the following format:
"results": {
    "collection1": [
      {
        "property1": {
          "href": "https://www.google.com/finance?catid=TRBC:57&sort=a&ei=Tx2WVonTG9uhe7Hpv_AN",
          "text": "Company"
        },
        "property2": "P/E (ttm)",
        "property3": "Quote",
        "index": 1,
        "url": "https://www.google.com/finance?catid=TRBC%3A57&sort=PE_RATIO&ei=6tyMVrqxIdaP0ASF0pbACQ"
      },
      {
        "property1": {
          "href": "https://www.google.com/finance?q=NASDAQ:NANO&ei=Tx2WVonTG9uhe7Hpv_AN",
          "text": "Nanometrics Incorporated"
        },
        "property2": "10,100.72",
        "property3": "14.04",
        "index": 2,
        "url": "https://www.google.com/finance?catid=TRBC%3A57&sort=PE_RATIO&ei=6tyMVrqxIdaP0ASF0pbACQ"
      },
This is the migration I have:
ActiveRecord::Schema.define(version: 20160108073353) do
  create_table "stocks", force: :cascade do |t|
    t.string   "company"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string   "url"
    t.float    "pe"
    t.float    "quote"
  end
The question is how do I load this JSON file into my application? I think it has the following steps and therefore my question can be broken up into:
- I need to open/load it with RestClient or OpenURI > how do I do this?
- Parse the data and make it a Ruby hash > how do I do this?
- Then loop through the hash and save data to database? > how do I do this?
Thanks for the help!
 
    