@OnKeyword("help") public void Login(TeamchatAPI api) { Servlet.api = api; String intro = "Hey this is Runscope Bot. You can use me to view the results of API tests currently assigned to any of your buckets.<table style=width:100%><tr><th>Keywords</th><th>Function</th></tr><tr><td>select</td><td>Select from a list of buckets</td></tr><tr><td>help</td><td>Log in to Runscope</td></tr>You have to log in first to select your buckets.<br>"; String msg = "<a href=https://www.runscope.com/signin/oauth/authorize?response_type=code&client_id=" + client_id + "&redirect_uri=" + callback_url + "&scope=api:read%20account:email%20message:write%20bucket:auth_token%20bucket:write&state=PLACEHOLDER target=_blank>Click here to Login</a>"; api.performPostInCurrentRoom(new PrimaryChatlet().setQuestionHtml(intro + msg)); }
@OnAlias("onSelect") public void Display(TeamchatAPI api) { String bucket = api.context().currentReply().getField("bucket"); int i; for (i = 0; i < name.length; i++) if (name.equals(bucket)) break; String id = key[i - 1]; JSONArray j = RunscopeFetch.getTest(id); desc = new String[j.length()]; rslt = new String[j.length()]; for (int k = 0; k < j.length(); k++) { JSONObject j1 = j.getJSONObject(k); desc[k] = j1.getString("name"); rslt[k] = j1.getString("result"); api.performPostInCurrentRoom( new PrimaryChatlet() .setQuestionHtml("<b>" + desc[k] + ":</b><br>" + RunscopeFetch.getResutls(rslt[k]))); } }
@OnKeyword("select") public static void selectBucket(TeamchatAPI api) { JSONArray j = RunscopeFetch.getBuckets(); name = new String[j.length()]; key = new String[j.length()]; for (int i = 0; i < j.length(); i++) { JSONObject j1 = j.getJSONObject(i); name[i] = j1.getString("name"); key[i] = j1.getString("key"); } Form f = api.objects().form(); f.addField(getOptions(api, name)); api.performPostInCurrentRoom( new PrimaryChatlet() .setQuestionHtml("Select the bucket for which you want results.") .setReplyScreen(f) .setReplyLabel("Select") .alias("onSelect")); }
@OnKeyword("Createproject") public void createProject(TeamchatAPI api) throws IOException { Database_Handler db = new Database_Handler(); pb = db.GetBasicStuff(api.context().currentSender().getEmail()); GetAccount ga = new GetAccount(); Field f = null; f = ga.getAccount(pb.getAccess_token(), api); PrimaryChatlet chtlet = new PrimaryChatlet() .setQuestion("Fill in details of the project") .setReplyScreen( api.objects() .form() .addField(api.objects().input().label("Project Name").name("project_name")) .addField(f)); chtlet.alias("createproject"); api.performPostInCurrentRoom(chtlet); }
public static void displayResult(String param, TeamchatAPI api) { initDB(); // cleanDB(); HTML5Chatlet list = new HTML5Chatlet(); list.alias("ResultList"); boolean flagAll = true; String parts[] = param.split("@@"); if (parts[1].equals("All")) { flagAll = true; } else { flagAll = false; } Connection Conn = null; PreparedStatement Stmt = null; PreparedStatement Stmt2 = null; String g_id = api.context().currentRoom().getId(); String p_id = parts[0]; try { Class.forName(JDBC_DRIVER); Conn = DriverManager.getConnection(DB_URL + DB_NAME, USER, PASS); Stmt = Conn.prepareStatement( "select count(TIndex) as numOfPeople, TIndex, Time, Date from timedata where GroupId = ? AND PlanId = ? AND Day = ?" + " group by TIndex order by numOfPeople desc, TIndex LIMIT 10"); Stmt2 = Conn.prepareStatement( "select count(TIndex) as numOfPeople, TIndex, Time, Date from timedata where GroupId = ? AND PlanId = ?" + " group by TIndex order by numOfPeople desc, TIndex LIMIT 10"); ResultSet rs; if (!flagAll) { Stmt.setString(1, g_id); Stmt.setString(2, p_id); Stmt.setString(3, parts[1]); rs = Stmt.executeQuery(); } else { Stmt2.setString(1, g_id); Stmt2.setString(2, p_id); rs = Stmt2.executeQuery(); } if (!rs.last()) { api.performPostInCurrentRoom(new TextChatlet("Your query gave an empty result.")); return; } Integer length = rs.getRow(); String[][] arr = new String[3][length]; String[] arr2 = new String[length]; Integer i = 0; rs.first(); while (i < length) { Integer count = rs.getInt("numOfPeople"); Integer index = rs.getInt("TIndex"); String y = rs.getString("Time"); String x = rs.getString("Date"); arr[0][i] = String.valueOf(count); arr[1][i] = x.substring(0, 7) + x.substring(8, 11); arr[2][i] = y.substring(0, 8) + y.charAt(9) + y.substring(11); arr2[i] = vector2HTML(tableOfUsers(index, g_id, p_id)); rs.next(); i++; } String str = array2HTML(arr, arr2); list.setQuestionHtml(str); } catch (SQLException se) { se.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (Stmt != null) { Conn.close(); } } catch (SQLException se) { } try { if (Conn != null) { Conn.close(); } } catch (SQLException se) { se.printStackTrace(); } } api.performPostInCurrentRoom(list); }