Created
November 5, 2011 19:14
-
-
Save chrismetcalf/1341894 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.saxon.demo; | |
import java.io.File; | |
import com.socrata.api.Connection; | |
import com.socrata.api.HttpConnection; | |
import com.socrata.api.RequestException; | |
import com.socrata.data.View; | |
public class Creator { | |
/** | |
* @param args | |
* @throws RequestException | |
*/ | |
public static void main(String[] args) throws RequestException { | |
// Connect to the API | |
String domain = "saxon.socrata.com"; | |
String username = "<youremail>"; | |
String password = "<yourpass>"; | |
String appToken = "<yourapptoken>"; | |
Connection connection = new HttpConnection(domain, username, password, | |
appToken); | |
// Import a new dataset | |
View view = new View(); | |
// Create the Name column | |
View.Column name = new View.Column(); | |
name.setName("Name"); | |
name.setDataTypeName("text"); | |
view.addColumn(name); | |
// Create the Age Column | |
View.Column age = new View.Column(); | |
age.setName("Age"); | |
age.setDataTypeName("number"); | |
view.addColumn(age); | |
// Create the Allowance Column | |
View.Column allowance = new View.Column(); | |
allowance.setName("Allowance"); | |
allowance.setDataTypeName("money"); | |
view.addColumn(allowance); | |
// Perform the import | |
view = view.create(new File("./data/example.csv"), connection); | |
// Publish the dataset | |
view = view.publish(connection); | |
System.out.println("View Created: http://saxon.socrata.com/d/" + view.getId()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment