Coder Social home page Coder Social logo

Comments (3)

sachin-handiekar avatar sachin-handiekar commented on June 15, 2024

Ok. I'll make the method protected.

Which other methods do you think will be helpful for the extension ?

from jinstagram.

pbvahlst avatar pbvahlst commented on June 15, 2024

Great, thanks

I have made some modifications through inheritance which could go into Instagram.java

generic way to create new objects, makes it easy to create your own model. This method don't need reflection when it can access the createInstagramObject method.

@SuppressWarnings("unchecked")
public <T extends InstagramObject> T fetchObject(String path, Class<T> type, Parameter... params) throws InstagramException {
    Map<String, String> paramMap = new HashMap<String, String>();
    for (Parameter p : params) {
        paramMap.put(p.getKey(), p.getValue().toString());
    }

    T result = null;
    try {
        result = (T)createInstagramObjectMethod.invoke(this, Verbs.GET, type, path, paramMap);
    } catch (InvocationTargetException e) {
        if (e.getCause() != null && e.getCause() instanceof InstagramException) {
            throw (InstagramException)e.getCause();
        } else {
            throw new RuntimeException(e);
        }
    } catch (IllegalAccessException | IllegalArgumentException e) {
        throw new RuntimeException(e);
    }

    return result;
}

A generic getNextPage method

@SuppressWarnings("unchecked")
public <T extends InstagramObject> T getNextPage(Pagination pagination, Class<T> type) throws InstagramException {
    T result = null;
    try {
        result = (T)createInstagramObjectMethod.invoke(this, Verbs.GET, type, StringUtils.removeStart(pagination.getNextUrl(), getInstagramConfig().getApiURL()), null);
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        throw new RuntimeException(e);
    }
    return result;
}

Finally it would be nice if the generics in the model objects such as List<MediaFeedData> data was parameterized with a wildcard so we get List<? extends MediaFeedData> data. This will make the extension of the existing model possible. (the getters and setters should also have ? extends XXX)

from jinstagram.

sachin-handiekar avatar sachin-handiekar commented on June 15, 2024

Closing the ticket... Re-open if needed

from jinstagram.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.