/*package*/ static ResponseList<Relationship> createRelationshipList(HttpResponse res, Configuration conf) throws TwitterException { try { if (conf.isJSONStoreEnabled()) { DataObjectFactoryUtil.clearThreadLocalMap(); } JSONArray list = res.asJSONArray(); int size = list.length(); ResponseList<Relationship> relationships = new ResponseListImpl<Relationship>(size, res); for (int i = 0; i < size; i++) { JSONObject json = list.getJSONObject(i); Relationship relationship = new RelationshipJSONImpl(json); if (conf.isJSONStoreEnabled()) { DataObjectFactoryUtil.registerJSONObject(relationship, json); } relationships.add(relationship); } if (conf.isJSONStoreEnabled()) { DataObjectFactoryUtil.registerJSONObject(relationships, list); } return relationships; } catch (JSONException jsone) { throw new TwitterException(jsone); } catch (TwitterException te) { throw te; } }
@Override public void nextTuple() { // emit tweets Status status = statuses.poll(); if (status == null) Utils.sleep(1000); else { ResponseList<User> followers; ResponseList<User> friends; try { Thread.sleep(6000); followers = twitter.getFollowersList(status.getUser().getScreenName(), -1); Thread.sleep(6000); friends = twitter.getFriendsList(status.getUser().getScreenName(), -1); if (!followers.isEmpty() && !friends.isEmpty()) { spoutOutputCollector.emit(new Values(status, followers, friends)); } // followers.clear(); // friends.clear(); } catch (TwitterException ex) { ex.printStackTrace(); } catch (InterruptedException ex) { ex.printStackTrace(); } } }
/*package*/ static ResponseList<UserList> createUserListList(HttpResponse res, Configuration conf) throws TwitterException { try { if (conf.isJSONStoreEnabled()) { TwitterObjectFactory.clearThreadLocalMap(); } JSONArray list = res.asJSONArray(); int size = list.length(); ResponseList<UserList> users = new ResponseListImpl<UserList>(size, res); for (int i = 0; i < size; i++) { JSONObject userListJson = list.getJSONObject(i); UserList userList = new UserListJSONImpl(userListJson); users.add(userList); if (conf.isJSONStoreEnabled()) { TwitterObjectFactory.registerJSONObject(userList, userListJson); } } if (conf.isJSONStoreEnabled()) { TwitterObjectFactory.registerJSONObject(users, list); } return users; } catch (JSONException jsone) { throw new TwitterException(jsone); } }
public void testSearchUser() throws TwitterException { ResponseList<User> users = twitter1.searchUsers("Doug Williams", 1); assertTrue(4 < users.size()); assertNotNull(DataObjectFactory.getRawJSON(users.get(0))); assertEquals( users.get(0), DataObjectFactory.createUser(DataObjectFactory.getRawJSON(users.get(0)))); assertNotNull(DataObjectFactory.getRawJSON(users)); }
public void testLocation() throws Exception { JSONArray array = getJSONArrayFromClassPath("/dao/trends-available.json"); ResponseList<Location> locations = LocationJSONImpl.createLocationList(array, conf.isJSONStoreEnabled()); Assert.assertEquals(23, locations.size()); Location location = locations.get(0); Assert.assertEquals("GB", location.getCountryCode()); Assert.assertEquals("United Kingdom", location.getCountryName()); Assert.assertEquals("United Kingdom", location.getName()); Assert.assertEquals(12, location.getPlaceCode()); Assert.assertEquals("Country", location.getPlaceName()); Assert.assertEquals("http://where.yahooapis.com/v1/place/23424975", location.getURL()); Assert.assertEquals(23424975, location.getWoeid()); }
public static ResponseList<ContributorFact> createContributorFactList(HttpResponse res) { if (null == res) { return null; } XMLParser parser = new XMLParser(res.asString()); NodeList nodelist = parser.getNodeList("response/result/contributor_fact"); ResponseList<ContributorFact> list = new ResponseListImpl<ContributorFact>(nodelist.getLength(), res); for (int i = 0; i < nodelist.getLength(); i++) { Node node = nodelist.item(i); try { XMLParser childParser = new XMLParser(XMLParser.getXmlStringFromNode(node)); ContributorFact contributorFact = new ContributorFactImpl(childParser, true); list.add(contributorFact); } catch (TransformerFactoryConfigurationError e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } } return list; }
public void testLookupUsers() throws TwitterException { ResponseList<User> users = twitter1.lookupUsers(new String[] {id1.screenName, id2.screenName}); assertEquals(2, users.size()); assertContains(users, id1); assertContains(users, id2); users = twitter1.lookupUsers(new long[] {id1.id, id2.id}); assertEquals(2, users.size()); assertContains(users, id1); assertContains(users, id2); assertNotNull(DataObjectFactory.getRawJSON(users.get(0))); assertEquals( users.get(0), DataObjectFactory.createUser(DataObjectFactory.getRawJSON(users.get(0)))); assertNotNull(DataObjectFactory.getRawJSON(users)); }
public void testContributors() throws Exception { ResponseList<User> users = twitter1.getContributors("twitter"); assertTrue(users.size() > 0); users = twitter1.getContributees(users.get(0).getId()); assertTrue(users.size() > 0); }
@Test public void getQuestionOption() throws Exception { ResponseList<Option> page1 = real.getQuestionOptions("381779171905254", new Reading().limit(1)); Option option1 = page1.get(0); System.out.println(option1); Paging<Option> paging = page1.getPaging(); ResponseList<Option> page2 = real.fetchNext(paging); Option option2 = page2.get(0); System.out.println(option2); ResponseList<Option> page3 = real.fetchNext(page2.getPaging()); Option option3 = page3.get(0); System.out.println(option3); ResponseList<Option> _page2 = real.fetchPrevious(page3.getPaging()); assertThat(_page2, is(page2)); ResponseList<Option> _page1 = real.fetchPrevious(_page2.getPaging()); assertThat(_page1, is(page1)); }
public void testGeoMethods() throws Exception { GeoQuery query; ResponseList<Place> places; query = new GeoQuery(new GeoLocation(0, 0)); places = twitter1.reverseGeoCode(query); assertEquals(0, places.size()); query = new GeoQuery(new GeoLocation(37.78215, -122.40060)); places = twitter1.reverseGeoCode(query); assertNotNull(TwitterObjectFactory.getRawJSON(places)); assertEquals( places.get(0), TwitterObjectFactory.createPlace(TwitterObjectFactory.getRawJSON(places.get(0)))); assertTrue(places.size() > 0); places = twitter1.searchPlaces(query); assertNotNull(TwitterObjectFactory.getRawJSON(places)); assertEquals( places.get(0), TwitterObjectFactory.createPlace(TwitterObjectFactory.getRawJSON(places.get(0)))); assertTrue(places.size() > 0); places = twitter1.getSimilarPlaces(new GeoLocation(37.78215, -122.40060), "SoMa", null, null); assertNotNull(TwitterObjectFactory.getRawJSON(places)); assertEquals( places.get(0), TwitterObjectFactory.createPlace(TwitterObjectFactory.getRawJSON(places.get(0)))); assertTrue(places.size() > 0); try { Place place = twitter1.getGeoDetails("5a110d312052166f"); assertNotNull(TwitterObjectFactory.getRawJSON(place)); assertEquals(place, TwitterObjectFactory.createPlace(TwitterObjectFactory.getRawJSON(place))); assertEquals("San Francisco, CA", place.getFullName()); assertEquals("California, US", place.getContainedWithIn()[0].getFullName()); } catch (TwitterException te) { // is being rate limited assertEquals(400, te.getStatusCode()); } String sanFrancisco = "5a110d312052166f"; Status status = twitter1.updateStatus( new StatusUpdate(new java.util.Date() + " status with place").placeId(sanFrancisco)); assertNotNull(TwitterObjectFactory.getRawJSON(status)); assertEquals( status, TwitterObjectFactory.createStatus(TwitterObjectFactory.getRawJSON(status))); assertEquals(sanFrancisco, status.getPlace().getId()); }