/*
 * Copyright 2016 LINE Corporation
 *
 * LINE Corporation licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.example.bot.spring.echo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import com.linecorp.bot.model.event.Event;
import com.linecorp.bot.model.event.MessageEvent;
import com.linecorp.bot.model.event.message.TextMessageContent;
import com.linecorp.bot.model.message.TextMessage;
import com.linecorp.bot.spring.boot.annotation.EventMapping;
import com.linecorp.bot.spring.boot.annotation.LineMessageHandler;


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.List;
import com.google.gson.Gson;


@SpringBootApplication
@LineMessageHandler
public class EchoApplication {
    public static void main(String[] args) {
        SpringApplication.run(EchoApplication.class, args);
    }
        
    @EventMapping
    public TextMessage handleTextMessageEvent(MessageEvent<TextMessageContent> event) {
        System.out.println("event: " + event);
        //return new TextMessage("TEST: "+event.getMessage().getText());

           Gson gson = new Gson();

        String json = readUrl("http://api.wunderground.com/api/57dd9039b81a9c21/conditions/q/CA/San_Francisco.json");

        Page page = gson.fromJson(json, Page.class);

        System.out.println(page.description);
        System.out.println(page.language);
        System.out.println(page.link);
        System.out.println(page.title);
        
        return new TextMessage("TEST: "+text);
        //URL website = new URL("http://cdn.crunchify.com/wp-content/uploads/code/json.sample.txt");
        
//        return new TextMessage(response.toString());
    }

    @EventMapping
    public void handleDefaultMessageEvent(Event event) {
        System.out.println("event: " + event);
    }
       private static String readUrl(String urlString) throws Exception {
        BufferedReader reader = null;
        try {
            URL url = new URL(urlString);
            reader = new BufferedReader(new InputStreamReader(url.openStream()));
            StringBuffer buffer = new StringBuffer();
            int read;
            char[] chars = new char[1024];
            while ((read = reader.read(chars)) != -1)
                buffer.append(chars, 0, read); 

            return buffer.toString();
        } finally {
            if (reader != null)
                reader.close();
        }

    }

    static class Page {
        String title;
        String link;
        String description;
        String language;
        List<Item> items;
    }

    static class Item {
        String title;
        String link;
        String description;
    }
}

@@ -1140,225 +1140,31 @@
 ava.
-io.BufferedReader;%0Aimport java.io.FileNotFoundException;%0Aimport java.io.FileReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader;%0Aimport java.net.URL;%0Aimport java.util.List;%0Aimport com.google.gson.Gson
+net.*;%0Aimport java.io.*
 ;%0A%0A%0A
@@ -1456,24 +1456,41 @@
 tent%3E event)
+ throws Exception
  %7B%0A        S
@@ -1613,44 +1613,64 @@
     
-   Gson gson = new Gson(
+URL oracle = new URL(%22http://www.oracle.com/%22
 );%0A
-%0A
         
 Stri
@@ -1669,261 +1669,179 @@
     
-String json = readUrl(%22http://api.wunderground.com/api/57dd9039b81a9c21/conditions/q/CA/San_Francisco.json%22);%0A%0A        Page page = gson.fromJson(json, Page.class);%0A%0A        System.out.println(page.description);%0A        System.out.println(page.language);
+BufferedReader in = new BufferedReader(%0A        new InputStreamReader(oracle.openStream()));%0A%0A        String inputLine;%0A        while ((inputLine = in.readLine()) != null)
 %0A   
@@ -1837,32 +1837,36 @@
 = null)%0A        
+    
 System.out.print
@@ -1872,17 +1872,17 @@
 tln(
-page.link
+inputLine
 );%0A 
@@ -1892,37 +1892,17 @@
     
-System.out.println(page.title
+in.close(
 );%0A 

Update EchoApplication.java