Skip to content

Commit 3304422

Browse files
committed
initial dump
0 parents  commit 3304422

19 files changed

+3610
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.class
2+
~*
3+
*~
4+
.zip
5+
.rar
6+
/bin

SifterProj.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//package com.SifterReader;
2+
3+
public class SifterProj {
4+
String api_url;
5+
String archived;
6+
String api_issues_url;
7+
String milestones_url;
8+
String api_milestones_url;
9+
String api_categories_url;
10+
String issues_url;
11+
String name;
12+
String url;
13+
String api_people_url;
14+
String primary_company_name;
15+
16+
public SifterProj(String api_url, String archived, String api_issues_url, String milestones_url,
17+
String api_milestones_url, String api_categories_url, String issues_url, String name,
18+
String url, String api_people_url, String primary_company_name) {
19+
this.api_url = api_url;
20+
this.archived = archived;
21+
this.api_issues_url = api_issues_url;
22+
this.milestones_url = milestones_url;
23+
this.api_milestones_url = api_milestones_url;
24+
this.api_categories_url = api_categories_url;
25+
this.issues_url = issues_url;
26+
this.name = name;
27+
this.url = url;
28+
this.api_people_url = api_people_url;
29+
this.primary_company_name = primary_company_name;
30+
}
31+
}

SifterReader.java

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
//package com.SifterReader;
2+
3+
/*
4+
* SifterReader.java
5+
*
6+
* Copyright 2012 Mark Mikofski <marko@linuxBox>
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation; either version 2 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program; if not, write to the Free Software
20+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21+
* MA 02110-1301, USA.
22+
*
23+
*
24+
*/
25+
26+
import java.net.*;
27+
import java.io.*;
28+
import org.json.*;
29+
30+
/** SifterAPI Reader using org.json library **/
31+
32+
public class SifterReader {
33+
34+
public static void main (String[] args) throws Exception {
35+
/** Enter your sifter account and access key in the
36+
** string fields below */
37+
38+
// create URL object to SifterAPI
39+
String yourAccount = "your-account-name"; // enter your account name
40+
String yourDomain = "yourAccount" + ".sifterapp.com";
41+
URL sifter = new URL("https",yourDomain,"/api/projects");
42+
43+
// open connectino to SifterAPI
44+
URLConnection sifterConnection = sifter.openConnection();
45+
46+
// add Access Key to header request
47+
String yourAccessKey = "your-sifterapi-32char-access-key"; // enter your access key
48+
sifterConnection.setRequestProperty("X-Sifter-Token",
49+
yourAccessKey);
50+
51+
// add Accept: application/json to header - also not necessary
52+
sifterConnection.addRequestProperty("Accept","application/json");
53+
54+
// URLconnection.connect() not necessary
55+
// getInputStream will connect
56+
57+
// don't make a content handler, org.json reads a stream!
58+
59+
// create buffer and open input stream
60+
BufferedReader in = new BufferedReader(
61+
new InputStreamReader(
62+
sifterConnection.getInputStream()));
63+
// don't readline, create stringbuilder, append, create string
64+
65+
// construct json tokener from input stream or buffered reader
66+
JSONTokener x = new JSONTokener(in);
67+
68+
// initialize "projects" JSONObject from string
69+
JSONObject projects = new JSONObject(x);
70+
71+
// prettyprint "projects"
72+
System.out.println("************ projects ************");
73+
System.out.println(projects.toString(2));
74+
75+
// array of projects
76+
JSONArray array = projects.getJSONArray("projects");
77+
int arrayLength = array.length();
78+
JSONObject[] p = new JSONObject[arrayLength];
79+
80+
// projects
81+
for (int i=0;i<arrayLength;i++) {
82+
p[i] = array.getJSONObject(i);
83+
System.out.println("************ project: " + (i+1) + " ************");
84+
System.out.println(p[i].toString(2));
85+
}
86+
87+
// check field names
88+
String[] checkNames = {
89+
"api_url",
90+
"archived",
91+
"api_issues_url",
92+
"milestones_url",
93+
"api_milestones_url",
94+
"api_categories_url",
95+
"issues_url",
96+
"name",
97+
"url",
98+
"api_people_url",
99+
"primary_company_name"};
100+
101+
// project field names
102+
String[] fieldNames = JSONObject.getNames(p[0]);
103+
int numKeys = p[0].length();
104+
SifterProj[] proj = new SifterProj[arrayLength];
105+
106+
for (int j=0;j<arrayLength;j++) {
107+
proj[j] = new SifterProj(p[j].get("api_url").toString(),
108+
p[j].get("archived").toString(),
109+
p[j].get("api_issues_url").toString(),
110+
p[j].get("milestones_url").toString(),
111+
p[j].get("api_milestones_url").toString(),
112+
p[j].get("api_categories_url").toString(),
113+
p[j].get("issues_url").toString(),
114+
p[j].get("name").toString(),
115+
p[j].get("url").toString(),
116+
p[j].get("api_people_url").toString(),
117+
p[j].get("primary_company_name").toString());
118+
System.out.println("************ project: " + (j+1) + " ************");
119+
for (int i=0;i<numKeys;i++) {
120+
System.out.print(fieldNames[i]);
121+
System.out.print(" : ");
122+
System.out.println(p[j].get(fieldNames[i]));
123+
}
124+
}
125+
}
126+
}

org/json/JSONArray.class

9.03 KB
Binary file not shown.

0 commit comments

Comments
 (0)