Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Commit

Permalink
added some api stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
FultonBrowne committed Sep 17, 2019
1 parent 3943845 commit dc89c3a
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 35 deletions.
16 changes: 16 additions & 0 deletions .idea/artifacts/Ara_Server_jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/dictionaries/pholtor.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified bin/jar/Ara-Server.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/java/com/andromeda/araserver/Hello.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ String hello(){
GsonBuilder gsonBuilder = new GsonBuilder();
ArrayList<OutputModel> test = new ArrayList<>();
Gson output = gsonBuilder.create();
test.add(new OutputModel("hi","hi","hi","hi", "Hello Human"));
test.add(new OutputModel("hi","hi","hi","hi", "Hello Human", ""));
return output.toJson(test);
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/andromeda/araserver/OutputModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ class OutputModel {
private String link;
private String description;
private String OutputTxt;
private String exes;

OutputModel(String title, String description, String link, String image, String OutputTxt) {
OutputModel(String title, String description, String link, String image, String OutputTxt, String exes) {
this.title = title;
this.link = link;
this.description = description;
this.OutputTxt = OutputTxt;
this.exes = exes;
}
}
66 changes: 35 additions & 31 deletions src/main/java/com/andromeda/araserver/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,39 +42,43 @@ public NanoHTTPD.Response serve(NanoHTTPD.IHTTPSession session) {
String sessionUri = session.getUri();
SyndFeed main1 = null;
String main2 = "err";

switch (sessionUri) {
case "/world":
tag = 1;
break;
case "/us":
tag = 2;
break;
case "/tech":
tag = 3;
break;
case "/money":
tag = 4;
break;

default:
tag = 0;
break;
if (sessionUri.startsWith("/api")) main2 = new apiStart().apiMain(sessionUri);
else if (sessionUri.startsWith("/hi")) main2 = new Hello().hello();
else {

switch (sessionUri) {
case "/world":
tag = 1;
break;
case "/us":
tag = 2;
break;
case "/tech":
tag = 3;
break;
case "/money":
tag = 4;
break;

default:
tag = 0;
break;
}

try {
main1 = RssMain.rss_main1(tag);

} catch (IOException | FeedException e) {
e.printStackTrace();
}
try {
assert main1 != null;
main2 = new SyndFeedOutput().outputString(main1);
} catch (FeedException e) {
e.printStackTrace();
}
}

try {
main1 = RssMain.rss_main1(tag);

} catch (IOException | FeedException e) {
e.printStackTrace();
}
try {
assert main1 != null;
main2 = new SyndFeedOutput().outputString(main1);
} catch (FeedException e) {
e.printStackTrace();
}
if (sessionUri.startsWith("/api")) main2 = new apiStart().apiMain(sessionUri);


System.out.println(sessionUri);
Expand Down
48 changes: 46 additions & 2 deletions src/main/java/com/andromeda/araserver/apiStart.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.net.URI;
import java.net.URISyntaxException;
import java.io.*;
import java.net.*;
import java.sql.*;
import java.util.ArrayList;
import java.util.Scanner;



class apiStart {
private GsonBuilder gsonBuilder = new GsonBuilder();
Expand Down Expand Up @@ -63,10 +66,51 @@ else if (search.startsWith(sqlmodel.get(i).description)){

}
}

if (linkval == null){
linkval = "error";
}
System.out.println(linkval + "/" + search);
String url = linkval;
if (!linkval.endsWith("/")) url = url +"/";

URL obj = null;
try {
obj = new URL(url);

HttpURLConnection con = (HttpURLConnection) obj.openConnection();

// optional default is GET
con.setRequestMethod("GET");

//add request header
//con.setRequestProperty("User-Agent", USER_AGENT);

int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);

BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
response.append(inputLine);

}
Scanner s = new Scanner(in).useDelimiter("\\A");
String result = s.hasNext() ? s.next() : "";
System.out.println(result);

in.close();


//print result
System.out.println(response.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
public void sqladd(Statement stmt, Connection c) throws SQLException {
// String sql = "CREATE TABLE skills(start varchar(80) ,endtxt varchar(225), link varchar(225)); ";
Expand Down

0 comments on commit dc89c3a

Please sign in to comment.