Skip to content

Commit

Permalink
TFJ-417 createPlace() now returns SimilarPlaces object which contains…
Browse files Browse the repository at this point in the history
… token

TFJ-439 adding Geo Resources examples
  • Loading branch information
yusuke authored and Mocel committed Nov 24, 2010
1 parent 7a98130 commit c7c0da8
Show file tree
Hide file tree
Showing 17 changed files with 510 additions and 0 deletions.
34 changes: 34 additions & 0 deletions twitter4j-core/src/main/java/twitter4j/SimilarPlaces.java
@@ -0,0 +1,34 @@
/*
Copyright (c) 2007-2010, Yusuke Yamamoto
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Yusuke Yamamoto nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package twitter4j;

/**
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.1.7
*/
public class SimilarPlaces {
}
34 changes: 34 additions & 0 deletions twitter4j-core/src/main/java/twitter4j/SimilarPlacesImpl.java
@@ -0,0 +1,34 @@
/*
Copyright (c) 2007-2010, Yusuke Yamamoto
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Yusuke Yamamoto nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package twitter4j;

/**
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.1.7
*/
public class SimilarPlacesImpl {
}
9 changes: 9 additions & 0 deletions twitter4j-examples/bin/geo/createPlace.cmd
@@ -0,0 +1,9 @@
echo off
SETLOCAL enabledelayedexpansion
cd ..
call setEnv.cmd

echo on
"%JAVA%" %MEM_ARGS% -classpath "%CLASSPATH%" twitter4j.examples.geo.CreatePlace %*

ENDLOCAL
7 changes: 7 additions & 0 deletions twitter4j-examples/bin/geo/createPlace.sh
@@ -0,0 +1,7 @@
#/bin/sh
cd ..
. ./setEnv.sh

RUN_CMD="$JAVA_HOME/bin/java $MEM_ARGS -cp $CLASSPATH twitter4j.examples.geo.CreatePlace $@"
echo $RUN_CMD
exec $RUN_CMD
9 changes: 9 additions & 0 deletions twitter4j-examples/bin/geo/getGeoDetails.cmd
@@ -0,0 +1,9 @@
echo off
SETLOCAL enabledelayedexpansion
cd ..
call setEnv.cmd

echo on
"%JAVA%" %MEM_ARGS% -classpath "%CLASSPATH%" twitter4j.examples.geo.GetGeoDetails %*

ENDLOCAL
7 changes: 7 additions & 0 deletions twitter4j-examples/bin/geo/getGeoDetails.sh
@@ -0,0 +1,7 @@
#/bin/sh
cd ..
. ./setEnv.sh

RUN_CMD="$JAVA_HOME/bin/java $MEM_ARGS -cp $CLASSPATH twitter4j.examples.geo.GetGeoDetails $@"
echo $RUN_CMD
exec $RUN_CMD
9 changes: 9 additions & 0 deletions twitter4j-examples/bin/geo/getSimilarPlaces.cmd
@@ -0,0 +1,9 @@
echo off
SETLOCAL enabledelayedexpansion
cd ..
call setEnv.cmd

echo on
"%JAVA%" %MEM_ARGS% -classpath "%CLASSPATH%" twitter4j.examples.geo.GetSimilarPlaces %*

ENDLOCAL
7 changes: 7 additions & 0 deletions twitter4j-examples/bin/geo/getSimilarPlaces.sh
@@ -0,0 +1,7 @@
#/bin/sh
cd ..
. ./setEnv.sh

RUN_CMD="$JAVA_HOME/bin/java $MEM_ARGS -cp $CLASSPATH twitter4j.examples.geo.GetSimilarPlaces $@"
echo $RUN_CMD
exec $RUN_CMD
9 changes: 9 additions & 0 deletions twitter4j-examples/bin/geo/reverseGeoCode.cmd
@@ -0,0 +1,9 @@
echo off
SETLOCAL enabledelayedexpansion
cd ..
call setEnv.cmd

echo on
"%JAVA%" %MEM_ARGS% -classpath "%CLASSPATH%" twitter4j.examples.geo.ReverseGeoCode %*

ENDLOCAL
7 changes: 7 additions & 0 deletions twitter4j-examples/bin/geo/reverseGeoCode.sh
@@ -0,0 +1,7 @@
#/bin/sh
cd ..
. ./setEnv.sh

RUN_CMD="$JAVA_HOME/bin/java $MEM_ARGS -cp $CLASSPATH twitter4j.examples.geo.ReverseGeoCode $@"
echo $RUN_CMD
exec $RUN_CMD
9 changes: 9 additions & 0 deletions twitter4j-examples/bin/geo/searchPlaces.cmd
@@ -0,0 +1,9 @@
echo off
SETLOCAL enabledelayedexpansion
cd ..
call setEnv.cmd

echo on
"%JAVA%" %MEM_ARGS% -classpath "%CLASSPATH%" twitter4j.examples.geo.SearchPlaces %*

ENDLOCAL
7 changes: 7 additions & 0 deletions twitter4j-examples/bin/geo/searchPlaces.sh
@@ -0,0 +1,7 @@
#/bin/sh
cd ..
. ./setEnv.sh

RUN_CMD="$JAVA_HOME/bin/java $MEM_ARGS -cp $CLASSPATH twitter4j.examples.geo.SearchPlaces $@"
echo $RUN_CMD
exec $RUN_CMD
@@ -0,0 +1,70 @@
/*
Copyright (c) 2007-2010, Yusuke Yamamoto
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Yusuke Yamamoto nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package twitter4j.examples.geo;

import twitter4j.GeoLocation;
import twitter4j.Place;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;

/**
* Creates a place.
*
* @author Yusuke Yamamoto - yusuke at mac.com
*/
public final class CreatePlace {
/**
* Usage: java twitter4j.examples.geo.CreatePlace [name] [contained within] [token] [lat] [long] [street address]
*
* @param args message
*/
public static void main(String[] args) {
if (args.length < 5) {
System.out.println("Usage: java twitter4j.examples.geo.CreatePlace [name] [contained within] [token] [lat] [long] [street address]");
System.exit(-1);
}
try {
Twitter twitter = new TwitterFactory().getInstance();
String name = args[0];
String containedWithin = args[1];
String token = args[2];
GeoLocation location = new GeoLocation(Double.parseDouble(args[3]), Double.parseDouble(args[4]));
String streetAddress = null;
if (args.length >= 5) {
streetAddress = args[5];
}
Place place = twitter.createPlace(name, containedWithin, token, location, streetAddress);
System.out.println("Successfully created a place [" + place.toString() + "].");
System.exit(0);
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to create a place: " + te.getMessage());
System.exit(-1);
}
}
}
@@ -0,0 +1,68 @@
/*
Copyright (c) 2007-2010, Yusuke Yamamoto
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Yusuke Yamamoto nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package twitter4j.examples.geo;

import twitter4j.Place;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;

/**
* Shows specified place's detailed information
* Destroys specified status.
*
* @author Yusuke Yamamoto - yusuke at mac.com
*/
public final class GetGeoDetails {
/**
* Usage: java twitter4j.examples.geo.GetGeoDetails [place id]
*
* @param args message
*/
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Usage: java twitter4j.examples.geo.GetGeoDetails [place id]");
System.exit(-1);
}
try {
Twitter twitter = new TwitterFactory().getInstance();
Place place = twitter.getGeoDetails(args[0]);
System.out.println("name: " + place.getName());
System.out.println("country: " + place.getCountry());
System.out.println("country code: " + place.getCountryCode());
System.out.println("full name: " + place.getFullName());
System.out.println("id: " + place.getId());
System.out.println("place type: " + place.getPlaceType());
System.out.println("street address: " + place.getStreetAddress());
System.exit(0);
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to retrieve geo details: " + te.getMessage());
System.exit(-1);
}
}
}
@@ -0,0 +1,77 @@
/*
Copyright (c) 2007-2010, Yusuke Yamamoto
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Yusuke Yamamoto nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package twitter4j.examples.geo;

import twitter4j.GeoLocation;
import twitter4j.Place;
import twitter4j.ResponseList;
import twitter4j.SimilarPlaces;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;

/**
* Locates places near the given coordinates which are similar in name.
*
* @author Yusuke Yamamoto - yusuke at mac.com
*/
public final class GetSimilarPlaces {
/**
* Usage: java twitter4j.examples.geo.GetSimilarPlaces [latitude] [longitude] [place id]
*
* @param args message
*/
public static void main(String[] args) {
if (args.length < 3) {
System.out.println("Usage: java twitter4j.examples.geo.GetSimilarPlaces [latitude] [longitude] [name] [place id]");
System.exit(-1);
}
try {
Twitter twitter = new TwitterFactory().getInstance();
GeoLocation location = new GeoLocation(Double.parseDouble(args[0]), Double.parseDouble(args[1]));
String name = args[2];
String containedWithin = null;
if (args.length >= 4) {
containedWithin = args[3];
}
SimilarPlaces places = twitter.getSimilarPlaces(location, name, containedWithin, null);
System.out.println("token: "+ places.getToken());
if (places.size() == 0) {
System.out.println("No location associated with the specified condition");
} else {
for (Place place : places) {
System.out.println("id: " + place.getId() + " name: " + place.getFullName() + " name: " + place.getFullName());
}
}
System.exit(0);
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to find similar places: " + te.getMessage());
System.exit(-1);
}
}
}

0 comments on commit c7c0da8

Please sign in to comment.