Permalink
Browse files

added license, readme, buildfile, (json, junit, testng) libs, httputi…

…ls. updated api to return string
  • Loading branch information...
1 parent 6c0a998 commit d833b241b0d068a22af4c5163c86c91b466e9eb7 @nitindhar7 committed Jan 22, 2012
View
@@ -3,5 +3,8 @@
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib" path="lib/java-json.jar"/>
+ <classpathentry kind="lib" path="lib/junit-4.9.jar"/>
+ <classpathentry kind="lib" path="lib/testng-5.9.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
View
@@ -0,0 +1,19 @@
+Copyright (c) 2012 Nitin Dhar
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
View
@@ -0,0 +1,51 @@
+Gilt-Java
+=========
+A simple Java client library for the Gilt API(v1). Currently this library is in development and will provide basic support for fetching current and upcoming
+sales. gilt-java has minimal dependencies and is aimed to be easy to use.
+
+Android
+-------
+Android platform to be tested soon!
+
+Build & Use
+-----------
+Please check [Gilt API documentation](http://api.gilt.com) for the official API definitions and descriptions.
+To build:
+
+ $ ant
+
+Examples:
+
+ GiltAPI gilt = new GiltAPI();
+
+ // Get active sales for all Gilt stores
+ gilt.getSales(null, Sale.ACTIVE, null);
+
+ // Get active sales for the Kids store
+ gilt.getSales(Store.KIDS, Sale.ACTIVE, null);
+
+ // Building a map option parameters
+ Map<String,String> options = new HashMap<String,String>();
+ options.put("product_detail", "true");
+
+ // Get active sales for the Kids store with full product details (requires options)
+ gilt.getSales(Store.KIDS, Sale.ACTIVE, options);
+
+Currently each API endpoint returns a String object representing the json response. gilt-java also includes software from [json.org/java](http://json.org/java/).
+
+Contribute
+------------
+Submit well documented code with unit tests and I will merge your changes in as long as your code does not break the build
+
+Gilt API Endpoints
+--------------------
+Currently there is 1 API endpoint available with the base url being `https://api.gilt.com/v1/`.
+
+- ** sales **
+ - Retrieve Gilt sales
+ - `https://api.gilt.com/v1/sales`
+ - `String getSales(String store, String action, Map<String,String> params)`
+
+Copyright
+---------
+Copyright (c) 2012 Nitin Dhar. See LICENSE for details.
View
@@ -0,0 +1,72 @@
+<?xml version='1.0'?>
+<project name="gilt-java" default="dist" basedir=".">
+ <property name="targetdir" value="target" />
+ <property name="srcdir" value="src/main/java" />
+ <property name="classdir" value="${targetdir}/classes" />
+ <property name="test_srcdir" value="src/test/java" />
+ <property name="test_resdir" value="src/test/resources" />
+ <property name="test_outdir" value="test-output" />
+ <property name="test_classdir" value="${targetdir}/tests" />
+ <property name="distdir" value="dist" />
+ <property name="docdir" value="javadocs" />
+
+ <path id="classpath">
+ <fileset dir="lib">
+ <include name="**/*.jar" />
+ </fileset>
+ <pathelement path="${classdir}" />
+ </path>
+
+ <path id="test_classpath">
+ <path refid="classpath" />
+ <pathelement path="${test_classdir}" />
+ <pathelement path="${test_resdir}" />
+ </path>
+
+ <target name="init">
+ <mkdir dir="${classdir}" />
+ <mkdir dir="${test_classdir}" />
+ </target>
+
+ <target name="clean">
+ <delete dir="${classdir}" />
+ <delete dir="${test_classdir}" />
+ <delete dir="${targetdir}" />
+ <delete dir="${distdir}" />
+ </target>
+
+ <target name="compile" depends="clean, init">
+ <javac debug="on" srcdir="${srcdir}" destdir="${classdir}" classpathref="classpath" includeantruntime="false" />
+ </target>
+
+ <target name="compile_tests" depends="compile">
+ <javac debug="on" srcdir="${test_srcdir}" destdir="${test_classdir}" classpathref="test_classpath" includeantruntime="false" />
+ </target>
+
+ <taskdef resource="testngtasks" classpath="lib/testng-5.9.jar" />
+ <target name="tests" depends="compile_tests" description="runs unit/functional tests">
+ <testng classpathref="test_classpath" outputDir="${targetdir}/testng" haltOnFailure="true" verbose="5">
+ <xmlfileset dir="${test_resdir}" includes="testng.xml" />
+ </testng>
+ </target>
+
+ <target name="javadocs" description="Generates javadoc into target/api">
+ <delete dir="${docdir}" />
+ <javadoc destdir="${docdir}" author="true" version="true" use="true" classpathref="classpath" windowtitle="gilt-java">
+ <packageset dir="${srcdir}" defaultexcludes="yes">
+ <include name="com/giltjava/**" />
+ </packageset>
+ </javadoc>
+ </target>
+
+ <target name="dist" depends="compile" description="Builds a complete gilt-java jar.">
+ <exec executable="git" outputproperty="git-desc" failonerror="true">
+ <arg value="describe" />
+ </exec>
+ <mkdir dir="${distdir}" />
+ <delete>
+ <fileset dir="." includes="${distdir}/gilt-java-${git-desc}.jar" />
+ </delete>
+ <jar destfile="${distdir}/gilt-java-${git-desc}.jar" basedir="${classdir}" />
+ </target>
+</project>
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
@@ -1,10 +1,10 @@
package com.giltjava;
-import java.util.List;
import java.util.Map;
import com.giltjava.model.Resource;
import com.giltjava.model.Sale;
+import com.giltjava.util.HttpUtil;
import com.giltjava.util.URIBuilder;
public class GiltAPI {
@@ -15,23 +15,19 @@ public GiltAPI(String apiKey) {
this.apiKey = apiKey;
}
- public List<Sale> getSales(String action, Map<String,String> params) {
- return null;
- }
-
- public List<Sale> getSales(String store, String action, Map<String,String> params) {
+ public String getSales(String store, String action, Map<String,String> params) {
if(action == null || action.length() == 0)
action = Sale.ACTIVE;
- URIBuilder builder = new URIBuilder();
- builder.resource(Resource.SALES);
- builder.store(store);
- builder.action(action);
- builder.apikey(apiKey);
- builder.params(URIBuilder.parametrizeMap(params));
- builder.build();
-
- return null;
+ String uri = new URIBuilder()
+ .resource(Resource.SALES)
+ .store(store)
+ .action(action)
+ .apikey(apiKey)
+ .params(URIBuilder.parametrizeMap(params))
+ .build();
+
+ return HttpUtil.get(uri);
}
}
@@ -0,0 +1,40 @@
+package com.giltjava.util;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.net.ssl.HttpsURLConnection;
+
+public class HttpUtil {
+
+ public static String get(String url) {
+ String response = null;
+ HttpsURLConnection conn = null;
+
+ try {
+ conn = (HttpsURLConnection) (new URL(url)).openConnection();
+ conn.connect();
+
+ BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+ StringBuilder sb = new StringBuilder();
+
+ for (String line = in.readLine(); line != null; line = in.readLine()) {
+ sb.append(line);
+ }
+
+ response = sb.toString();
+ } catch (MalformedURLException e) {
+ throw new RuntimeException("Error connecting to url", e);
+ } catch (IOException e) {
+ throw new RuntimeException("Error reading from url", e);
+ } finally {
+ conn.disconnect();
+ }
+
+ return response;
+ }
+
+}
@@ -0,0 +1,16 @@
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
+
+<suite name="gilt-java" verbose="5">
+ <test name="gilt-java tests">
+ <groups>
+ <run>
+ <include name="ready"/>
+ <exclude name="skip"/>
+ <exclude name="toBeFixed"/>
+ </run>
+ </groups>
+ <packages>
+ <package name="com.giltjava"/>
+ </packages>
+ </test>
+ </suite>

0 comments on commit d833b24

Please sign in to comment.