You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@streams.apache.org by steveblackmon <gi...@git.apache.org> on 2015/03/27 02:40:35 UTC

[GitHub] incubator-streams pull request: STREAMS-235

GitHub user steveblackmon opened a pull request:

    https://github.com/apache/incubator-streams/pull/202

    STREAMS-235

    Provider for pulling follow relationships for a user list and creating activitystreams representations

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/steveblackmon/incubator-streams STREAMS-235

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-streams/pull/202.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #202
    
----
commit 43a3818f59c6d0ca3c37e11b92160b52327cd903
Author: sblackmon <sb...@apache.org>
Date:   2014-11-25T20:14:14Z

    STREAMS-235

commit e5d50866be407e9a25ecf9936c0a16631d01ee2b
Author: Steve Blackmon (@steveblackmon) <sb...@apache.org>
Date:   2015-03-26T18:04:23Z

    cleanup post-277

commit cd6d7c1a11ff5a29a474b13fa8e8a0968d01c006
Author: sblackmon <sb...@apache.org>
Date:   2014-11-25T21:39:01Z

    loop logic

commit 3dceeb5efdb260e1b3c4f7cf15b4e38ccb23df8c
Author: sblackmon <sb...@apache.org>
Date:   2014-11-27T18:32:13Z

    screen name support

commit c14e335ede2d05c1265af609fbbfea196001802f
Author: Steve Blackmon (@steveblackmon) <sb...@apache.org>
Date:   2015-03-27T01:14:28Z

    follow Json detection

commit 4bfbfc400e94c27c847cb2efb670831c80d0a9d9
Author: Steve Blackmon (@steveblackmon) <sb...@apache.org>
Date:   2015-03-27T01:29:11Z

    follow detection test

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-streams pull request: STREAMS-235

Posted by jfrazee <gi...@git.apache.org>.
Github user jfrazee commented on a diff in the pull request:

    https://github.com/apache/incubator-streams/pull/202#discussion_r27687475
  
    --- Diff: streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterFollowersProviderTask.java ---
    @@ -0,0 +1,181 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.streams.twitter.provider;
    +
    +import com.fasterxml.jackson.core.JsonParseException;
    +import com.fasterxml.jackson.databind.JsonMappingException;
    +import com.fasterxml.jackson.databind.ObjectMapper;
    +import com.google.common.collect.Lists;
    +import org.apache.streams.core.StreamsDatum;
    +import org.apache.streams.jackson.StreamsJacksonMapper;
    +import org.apache.streams.twitter.pojo.Follow;
    +import org.apache.streams.twitter.pojo.User;
    +import org.apache.streams.util.ComponentUtils;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import twitter4j.PagableResponseList;
    +import twitter4j.Twitter;
    +import twitter4j.TwitterException;
    +import twitter4j.TwitterObjectFactory;
    +
    +import java.io.IOException;
    +
    +/**
    + *  Retrieve recent posts for a single user id.
    + */
    +public class TwitterFollowersProviderTask implements Runnable {
    +
    +    private final static Logger LOGGER = LoggerFactory.getLogger(TwitterFollowersProviderTask.class);
    +
    +    private final static ObjectMapper mapper = StreamsJacksonMapper.getInstance();
    +
    +    protected TwitterFollowingProvider provider;
    +    protected Twitter client;
    +    protected Long id;
    +    protected String screenName;
    +
    +    public TwitterFollowersProviderTask(TwitterFollowingProvider provider, Twitter twitter, Long id) {
    +        this.provider = provider;
    +        this.client = twitter;
    +        this.id = id;
    +    }
    +
    +    public TwitterFollowersProviderTask(TwitterFollowingProvider provider, Twitter twitter, String screenName) {
    +        this.provider = provider;
    +        this.client = twitter;
    +        this.screenName = screenName;
    +    }
    +
    +
    +    @Override
    +    public void run() {
    +
    +        if( id != null )
    +            getFollowers(id);
    +        if( screenName != null)
    +            getFollowers(screenName);
    +
    +        LOGGER.info(id != null ? id.toString() : screenName + " Thread Finished");
    +
    +    }
    +
    +    protected void getFollowers(Long id) {
    +
    +        int keepTrying = 0;
    +
    +        long curser = -1;
    +
    +        do
    +        {
    +            try
    +            {
    +                twitter4j.User followee4j;
    +                String followeeJson;
    +                try {
    +                    followee4j = client.users().showUser(id);
    +                    followeeJson = TwitterObjectFactory.getRawJSON(followee4j);
    +                } catch (TwitterException e) {
    +                    LOGGER.error("Failure looking up " + id);
    +                    break;
    +                }
    +
    +                PagableResponseList<twitter4j.User> followerList = client.friendsFollowers().getFollowersList(id.longValue(), curser);
    +
    +                for (twitter4j.User follower4j : followerList) {
    +
    +                    String followerJson = TwitterObjectFactory.getRawJSON(follower4j);
    +
    +                    try {
    +                        Follow follow = new Follow()
    +                                .withFollowee(mapper.readValue(followeeJson, User.class))
    +                                .withFollower(mapper.readValue(followerJson, User.class));
    +
    +                        ComponentUtils.offerUntilSuccess(new StreamsDatum(follow), provider.providerQueue);
    +                    } catch (JsonParseException e) {
    +                        LOGGER.warn(e.getMessage());
    +                    } catch (JsonMappingException e) {
    +                        LOGGER.warn(e.getMessage());
    +                    } catch (IOException e) {
    +                        LOGGER.warn(e.getMessage());
    +                    }
    +                }
    +                curser = followerList.getNextCursor();
    +            }
    +            catch(TwitterException twitterException) {
    +                keepTrying += TwitterErrorHandler.handleTwitterError(client, twitterException);
    +            }
    +            catch(Exception e) {
    +                keepTrying += TwitterErrorHandler.handleTwitterError(client, e);
    +            }
    +        } while (curser != 0 && keepTrying < 10);
    +    }
    +
    +    protected void getFollowers(String screenName) {
    --- End diff --
    
    Since showUser() is called, getFollowers(Long id) could be the primary implementation with getFollowers(String screenName) calling it after the id is available from the user lookup. This would cut out a bit of code.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-streams pull request: STREAMS-235

Posted by steveblackmon <gi...@git.apache.org>.
Github user steveblackmon commented on a diff in the pull request:

    https://github.com/apache/incubator-streams/pull/202#discussion_r27691213
  
    --- Diff: streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/converter/TwitterFollowActivityConverter.java ---
    @@ -0,0 +1,84 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.streams.twitter.converter;
    +
    +import com.google.common.collect.Lists;
    +import org.apache.commons.lang.NotImplementedException;
    +import org.apache.streams.data.ActivityConverter;
    +import org.apache.streams.exceptions.ActivityConversionException;
    +import org.apache.streams.pojo.json.Activity;
    +import org.apache.streams.pojo.json.ActivityObject;
    +import org.apache.streams.pojo.json.Provider;
    +import org.apache.streams.twitter.pojo.Follow;
    +import org.apache.streams.twitter.converter.util.TwitterActivityUtil;
    +
    +import java.io.Serializable;
    +import java.util.List;
    +
    +public class TwitterFollowActivityConverter implements ActivityConverter<Follow>, Serializable {
    +
    +    public TwitterFollowActivityConverter() {
    +    }
    +
    +    private static TwitterFollowActivityConverter instance = new TwitterFollowActivityConverter();
    +
    +    public static TwitterFollowActivityConverter getInstance() {
    +        return instance;
    +    }
    +
    +    public static Class requiredClass = Follow.class;
    +
    +    @Override
    +    public Class requiredClass() {
    +        return requiredClass;
    +    }
    +
    +    @Override
    +    public String serializationFormat() {
    +        return null;
    +    }
    +
    +    @Override
    +    public Follow fromActivity(Activity deserialized) throws ActivityConversionException {
    --- End diff --
    
    https://issues.apache.org/jira/browse/STREAMS-303


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-streams pull request: STREAMS-235

Posted by jfrazee <gi...@git.apache.org>.
Github user jfrazee commented on a diff in the pull request:

    https://github.com/apache/incubator-streams/pull/202#discussion_r27686336
  
    --- Diff: streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterFollowersProviderTask.java ---
    @@ -0,0 +1,181 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.streams.twitter.provider;
    +
    +import com.fasterxml.jackson.core.JsonParseException;
    +import com.fasterxml.jackson.databind.JsonMappingException;
    +import com.fasterxml.jackson.databind.ObjectMapper;
    +import com.google.common.collect.Lists;
    +import org.apache.streams.core.StreamsDatum;
    +import org.apache.streams.jackson.StreamsJacksonMapper;
    +import org.apache.streams.twitter.pojo.Follow;
    +import org.apache.streams.twitter.pojo.User;
    +import org.apache.streams.util.ComponentUtils;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import twitter4j.PagableResponseList;
    +import twitter4j.Twitter;
    +import twitter4j.TwitterException;
    +import twitter4j.TwitterObjectFactory;
    +
    +import java.io.IOException;
    +
    +/**
    + *  Retrieve recent posts for a single user id.
    + */
    +public class TwitterFollowersProviderTask implements Runnable {
    +
    +    private final static Logger LOGGER = LoggerFactory.getLogger(TwitterFollowersProviderTask.class);
    +
    +    private final static ObjectMapper mapper = StreamsJacksonMapper.getInstance();
    +
    +    protected TwitterFollowingProvider provider;
    +    protected Twitter client;
    +    protected Long id;
    +    protected String screenName;
    +
    +    public TwitterFollowersProviderTask(TwitterFollowingProvider provider, Twitter twitter, Long id) {
    +        this.provider = provider;
    +        this.client = twitter;
    +        this.id = id;
    +    }
    +
    +    public TwitterFollowersProviderTask(TwitterFollowingProvider provider, Twitter twitter, String screenName) {
    +        this.provider = provider;
    +        this.client = twitter;
    +        this.screenName = screenName;
    +    }
    +
    +
    +    @Override
    +    public void run() {
    +
    +        if( id != null )
    +            getFollowers(id);
    +        if( screenName != null)
    +            getFollowers(screenName);
    +
    +        LOGGER.info(id != null ? id.toString() : screenName + " Thread Finished");
    +
    +    }
    +
    +    protected void getFollowers(Long id) {
    +
    +        int keepTrying = 0;
    +
    +        long curser = -1;
    +
    +        do
    +        {
    +            try
    +            {
    +                twitter4j.User followee4j;
    +                String followeeJson;
    +                try {
    +                    followee4j = client.users().showUser(id);
    +                    followeeJson = TwitterObjectFactory.getRawJSON(followee4j);
    +                } catch (TwitterException e) {
    +                    LOGGER.error("Failure looking up " + id);
    +                    break;
    +                }
    +
    +                PagableResponseList<twitter4j.User> followerList = client.friendsFollowers().getFollowersList(id.longValue(), curser);
    --- End diff --
    
    I think this would use the people's rate limits more efficiently if you call getFollowersList() with the count parameter.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-streams pull request: STREAMS-235

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-streams/pull/202


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-streams pull request: STREAMS-235

Posted by steveblackmon <gi...@git.apache.org>.
Github user steveblackmon commented on a diff in the pull request:

    https://github.com/apache/incubator-streams/pull/202#discussion_r27690509
  
    --- Diff: streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterFollowersProviderTask.java ---
    @@ -0,0 +1,181 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.streams.twitter.provider;
    +
    +import com.fasterxml.jackson.core.JsonParseException;
    +import com.fasterxml.jackson.databind.JsonMappingException;
    +import com.fasterxml.jackson.databind.ObjectMapper;
    +import com.google.common.collect.Lists;
    +import org.apache.streams.core.StreamsDatum;
    +import org.apache.streams.jackson.StreamsJacksonMapper;
    +import org.apache.streams.twitter.pojo.Follow;
    +import org.apache.streams.twitter.pojo.User;
    +import org.apache.streams.util.ComponentUtils;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import twitter4j.PagableResponseList;
    +import twitter4j.Twitter;
    +import twitter4j.TwitterException;
    +import twitter4j.TwitterObjectFactory;
    +
    +import java.io.IOException;
    +
    +/**
    + *  Retrieve recent posts for a single user id.
    + */
    +public class TwitterFollowersProviderTask implements Runnable {
    +
    +    private final static Logger LOGGER = LoggerFactory.getLogger(TwitterFollowersProviderTask.class);
    +
    +    private final static ObjectMapper mapper = StreamsJacksonMapper.getInstance();
    +
    +    protected TwitterFollowingProvider provider;
    +    protected Twitter client;
    +    protected Long id;
    +    protected String screenName;
    +
    +    public TwitterFollowersProviderTask(TwitterFollowingProvider provider, Twitter twitter, Long id) {
    +        this.provider = provider;
    +        this.client = twitter;
    +        this.id = id;
    +    }
    +
    +    public TwitterFollowersProviderTask(TwitterFollowingProvider provider, Twitter twitter, String screenName) {
    +        this.provider = provider;
    +        this.client = twitter;
    +        this.screenName = screenName;
    +    }
    +
    +
    +    @Override
    +    public void run() {
    +
    +        if( id != null )
    +            getFollowers(id);
    +        if( screenName != null)
    +            getFollowers(screenName);
    +
    +        LOGGER.info(id != null ? id.toString() : screenName + " Thread Finished");
    +
    +    }
    +
    +    protected void getFollowers(Long id) {
    +
    +        int keepTrying = 0;
    +
    +        long curser = -1;
    +
    +        do
    +        {
    +            try
    +            {
    +                twitter4j.User followee4j;
    +                String followeeJson;
    +                try {
    +                    followee4j = client.users().showUser(id);
    +                    followeeJson = TwitterObjectFactory.getRawJSON(followee4j);
    +                } catch (TwitterException e) {
    +                    LOGGER.error("Failure looking up " + id);
    +                    break;
    +                }
    +
    +                PagableResponseList<twitter4j.User> followerList = client.friendsFollowers().getFollowersList(id.longValue(), curser);
    --- End diff --
    
    good call.  changing. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-streams pull request: STREAMS-235

Posted by jfrazee <gi...@git.apache.org>.
Github user jfrazee commented on a diff in the pull request:

    https://github.com/apache/incubator-streams/pull/202#discussion_r27685931
  
    --- Diff: streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/converter/TwitterFollowActivityConverter.java ---
    @@ -0,0 +1,84 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.streams.twitter.converter;
    +
    +import com.google.common.collect.Lists;
    +import org.apache.commons.lang.NotImplementedException;
    +import org.apache.streams.data.ActivityConverter;
    +import org.apache.streams.exceptions.ActivityConversionException;
    +import org.apache.streams.pojo.json.Activity;
    +import org.apache.streams.pojo.json.ActivityObject;
    +import org.apache.streams.pojo.json.Provider;
    +import org.apache.streams.twitter.pojo.Follow;
    +import org.apache.streams.twitter.converter.util.TwitterActivityUtil;
    +
    +import java.io.Serializable;
    +import java.util.List;
    +
    +public class TwitterFollowActivityConverter implements ActivityConverter<Follow>, Serializable {
    +
    +    public TwitterFollowActivityConverter() {
    +    }
    +
    +    private static TwitterFollowActivityConverter instance = new TwitterFollowActivityConverter();
    +
    +    public static TwitterFollowActivityConverter getInstance() {
    +        return instance;
    +    }
    +
    +    public static Class requiredClass = Follow.class;
    +
    +    @Override
    +    public Class requiredClass() {
    +        return requiredClass;
    +    }
    +
    +    @Override
    +    public String serializationFormat() {
    +        return null;
    +    }
    +
    +    @Override
    +    public Follow fromActivity(Activity deserialized) throws ActivityConversionException {
    --- End diff --
    
    Is there a reason this isn't implemented? Seems like it'd be straight forward if the verb is a follow and actor and object are populated.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-streams pull request: STREAMS-235

Posted by jfrazee <gi...@git.apache.org>.
Github user jfrazee commented on the pull request:

    https://github.com/apache/incubator-streams/pull/202#issuecomment-89023633
  
    :+1:


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-streams pull request: STREAMS-235

Posted by steveblackmon <gi...@git.apache.org>.
Github user steveblackmon commented on a diff in the pull request:

    https://github.com/apache/incubator-streams/pull/202#discussion_r27690525
  
    --- Diff: streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterFollowersProviderTask.java ---
    @@ -0,0 +1,181 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.streams.twitter.provider;
    +
    +import com.fasterxml.jackson.core.JsonParseException;
    +import com.fasterxml.jackson.databind.JsonMappingException;
    +import com.fasterxml.jackson.databind.ObjectMapper;
    +import com.google.common.collect.Lists;
    +import org.apache.streams.core.StreamsDatum;
    +import org.apache.streams.jackson.StreamsJacksonMapper;
    +import org.apache.streams.twitter.pojo.Follow;
    +import org.apache.streams.twitter.pojo.User;
    +import org.apache.streams.util.ComponentUtils;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import twitter4j.PagableResponseList;
    +import twitter4j.Twitter;
    +import twitter4j.TwitterException;
    +import twitter4j.TwitterObjectFactory;
    +
    +import java.io.IOException;
    +
    +/**
    + *  Retrieve recent posts for a single user id.
    + */
    +public class TwitterFollowersProviderTask implements Runnable {
    +
    +    private final static Logger LOGGER = LoggerFactory.getLogger(TwitterFollowersProviderTask.class);
    +
    +    private final static ObjectMapper mapper = StreamsJacksonMapper.getInstance();
    +
    +    protected TwitterFollowingProvider provider;
    +    protected Twitter client;
    +    protected Long id;
    +    protected String screenName;
    +
    +    public TwitterFollowersProviderTask(TwitterFollowingProvider provider, Twitter twitter, Long id) {
    +        this.provider = provider;
    +        this.client = twitter;
    +        this.id = id;
    +    }
    +
    +    public TwitterFollowersProviderTask(TwitterFollowingProvider provider, Twitter twitter, String screenName) {
    +        this.provider = provider;
    +        this.client = twitter;
    +        this.screenName = screenName;
    +    }
    +
    +
    +    @Override
    +    public void run() {
    +
    +        if( id != null )
    +            getFollowers(id);
    +        if( screenName != null)
    +            getFollowers(screenName);
    +
    +        LOGGER.info(id != null ? id.toString() : screenName + " Thread Finished");
    +
    +    }
    +
    +    protected void getFollowers(Long id) {
    +
    +        int keepTrying = 0;
    +
    +        long curser = -1;
    +
    +        do
    +        {
    +            try
    +            {
    +                twitter4j.User followee4j;
    +                String followeeJson;
    +                try {
    +                    followee4j = client.users().showUser(id);
    +                    followeeJson = TwitterObjectFactory.getRawJSON(followee4j);
    +                } catch (TwitterException e) {
    +                    LOGGER.error("Failure looking up " + id);
    +                    break;
    +                }
    +
    +                PagableResponseList<twitter4j.User> followerList = client.friendsFollowers().getFollowersList(id.longValue(), curser);
    +
    +                for (twitter4j.User follower4j : followerList) {
    +
    +                    String followerJson = TwitterObjectFactory.getRawJSON(follower4j);
    +
    +                    try {
    +                        Follow follow = new Follow()
    +                                .withFollowee(mapper.readValue(followeeJson, User.class))
    +                                .withFollower(mapper.readValue(followerJson, User.class));
    +
    +                        ComponentUtils.offerUntilSuccess(new StreamsDatum(follow), provider.providerQueue);
    +                    } catch (JsonParseException e) {
    +                        LOGGER.warn(e.getMessage());
    +                    } catch (JsonMappingException e) {
    +                        LOGGER.warn(e.getMessage());
    +                    } catch (IOException e) {
    +                        LOGGER.warn(e.getMessage());
    +                    }
    +                }
    +                curser = followerList.getNextCursor();
    +            }
    +            catch(TwitterException twitterException) {
    +                keepTrying += TwitterErrorHandler.handleTwitterError(client, twitterException);
    +            }
    +            catch(Exception e) {
    +                keepTrying += TwitterErrorHandler.handleTwitterError(client, e);
    +            }
    +        } while (curser != 0 && keepTrying < 10);
    +    }
    +
    +    protected void getFollowers(String screenName) {
    --- End diff --
    
    good call. refactoring.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-streams pull request: STREAMS-235

Posted by steveblackmon <gi...@git.apache.org>.
Github user steveblackmon commented on a diff in the pull request:

    https://github.com/apache/incubator-streams/pull/202#discussion_r27688659
  
    --- Diff: streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/converter/TwitterFollowActivityConverter.java ---
    @@ -0,0 +1,84 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.streams.twitter.converter;
    +
    +import com.google.common.collect.Lists;
    +import org.apache.commons.lang.NotImplementedException;
    +import org.apache.streams.data.ActivityConverter;
    +import org.apache.streams.exceptions.ActivityConversionException;
    +import org.apache.streams.pojo.json.Activity;
    +import org.apache.streams.pojo.json.ActivityObject;
    +import org.apache.streams.pojo.json.Provider;
    +import org.apache.streams.twitter.pojo.Follow;
    +import org.apache.streams.twitter.converter.util.TwitterActivityUtil;
    +
    +import java.io.Serializable;
    +import java.util.List;
    +
    +public class TwitterFollowActivityConverter implements ActivityConverter<Follow>, Serializable {
    +
    +    public TwitterFollowActivityConverter() {
    +    }
    +
    +    private static TwitterFollowActivityConverter instance = new TwitterFollowActivityConverter();
    +
    +    public static TwitterFollowActivityConverter getInstance() {
    +        return instance;
    +    }
    +
    +    public static Class requiredClass = Follow.class;
    +
    +    @Override
    +    public Class requiredClass() {
    +        return requiredClass;
    +    }
    +
    +    @Override
    +    public String serializationFormat() {
    +        return null;
    +    }
    +
    +    @Override
    +    public Follow fromActivity(Activity deserialized) throws ActivityConversionException {
    --- End diff --
    
    I don't know of any converters which have implementations to go from Activity/ActivityObject to external network format - not because of difficulty it just hasn't been a priority yet.  
    
    However, there are many fromActivity implementations that would be more important that this one, since org.apache.streams.twitter.pojo.Follow is a POJO internal to streams-provider-twitter (there is no twitter API that uses that bean).
    
    I will create a ticket to implement fromActivity throughout this module and make an effort to roll that into the next release.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---