If you're looking for a model of a Java API client, that I've used in our
Android app around Congress, I can mostly recommend the approach I've taken
here:
https://github.com/sunlightlabs/congress/tree/master/src/com/sunlight...
It's separated into three kinds of files -
A model, which defines the fields and any helpful utility methods on that
model, but has nothing to do with the remote API:
https://github.com/sunlightlabs/congress/blob/master/src/com/sunlight...
A service for the model, that defines how to parse each field from JSON:
https://github.com/sunlightlabs/congress/blob/master/src/com/sunlight...
And a class that helps with all the particulars across that API - URL
construction, date formats, user agent, api key, etc.:
https://github.com/sunlightlabs/congress/blob/master/src/com/sunlight...
I separated the model from the service because in some cases, like
legislators, it may be populated from one of two different APIs. But even
without that requirement, it ends up being a pretty clean approach.
The main thing I might do differently if I did it over again might be to
use GSON <http://code.google.com/p/google-gson/> or some other library that
maps Java objects to JSON objects automatically, without the manual field
parsing. But I might not - JSON isn't the same as Java, and for complicated
nested objects it may be more trouble than it's worth.
-- Eric
On Sat, Mar 17, 2012 at 12:32 AM, Brandon Gresham
<bran...@thegreshams.net>wrote:
> James, that's a great idea. I'll take a look at the existing API and see
> if I can make it out well enough to put something together. Since I'm
> brand-new to the project and haven't played with any of it at all yet,
> probably take a bit to familiarize myself with it. I'll run my thoughts
> past you guys here before I go putting too much actual code down.
> On Friday, March 16, 2012 8:52:13 PM UTC-6, James Turk wrote:
>> Hi Brandon,
>> We haven't started one yet, but it is something we are eager to do. I
>> agree that having you start one if you haven't done droid stuff might
>> not yield the most usable product and I'd hate to see any wasted
>> effort so perhaps we can work to redirect your Java experience in a
>> different direction.
>> One idea might be to write some lightweight bindings to our API,
>> that'd be beneficial for lots of people and might eventually be
>> incorporated into the Android app as well.
>> We'll hopefully be figuring out a path forward on the Android app in
>> the future, and when we do it'll be open source and your contributions
>> would be more than welcome.
>> -James
>> On Fri, Mar 16, 2012 at 6:53 PM, Brandon Gresham
>> <bran...@thegreshams.net> wrote:
>> > Has anyone started a droid app for this project yet?
>> > I'm a Java guy... so I could help out on that project; but I might not
>> be
>> > the most appropriate guy to START the app, never actually done droid
>> stuff.
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Open State Project" group.
>> > To view this discussion on the web visit
>> > https://groups.google.com/d/**msg/fifty-state-project/-/**Y2oOjYePpDUJ<https://groups.google.com/d/msg/fifty-state-project/-/Y2oOjYePpDUJ>
>> .
>> > To post to this group, send email to fifty-state-project@**
>> googlegroups.com <fifty-state-project@googlegroups.com>.
>> > To unsubscribe from this group, send email to
>> > fifty-state-project+**unsubscribe@googlegroups.com<fifty-state-project%2Bun subscribe@googlegroups.com>
>> .
>> > For more options, visit this group at
>> > http://groups.google.com/**group/fifty-state-project?hl=**en<http://groups.google.com/group/fifty-state-project?hl=en>
>> .
>> --
> You received this message because you are subscribed to the Google Groups
> "Open State Project" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/fifty-state-project/-/RC0KiuNGVtEJ.
> To post to this group, send email to fifty-state-project@googlegroups.com.
> To unsubscribe from this group, send email to
> fifty-state-project+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/fifty-state-project?hl=en.
--
Developer | sunlightfoundation.com