views:

19

answers:

1

Hi, guys.

This is a general question, so I won't name which site's API I am refering to.

OK, lets say the API gives me access to some objects (books/other products). I want to give my users the ability to "store" some of these objects in my app's db so that later they could "review" them again.

My question is about the "store" and "review" verbs. (Of course, caching will be used when possible instead of pulling data from the remote db)

1) What should I really store

a) just an API-specific key, that is enough to pull the other object data from the API when reviewing

b) API key + other unique id (like ISBN for books, or name if no other "natural" id exists). My idea behind this is that later it will let me change the used API if I have to.

c) All the object's data (like author,manufacturer,etc.). That is, use the API only for displaying search results

2) If yes to 1 a) or b), how should I organize the Item model? Should I

a) seperate the interface for the API to a seperate class (like RemoteItem) or should I

b) just define methods inside Item, that communicate transparently with the remote site?

c) or a module to include?

A: 

1). First a technical thought: If you were in control of the API then you could determine the degree of trust you have in the logenvity of the API-specific key. In this case you don't actually control it, so I'd prefer a "belt and braces" approach, stash the ISBN too (I don't know whether other media offer similar unique ids). That's purely an attempt to deal with potential changes in an API you don't control.

But then consider usability. IF you stash some other data you can not only accommodate shifts in the API you can perhaps more easily offer other function, for example search for similar items, or search a different site for the purposes of price comparison.

So my inclination is to stash a bit more information - like for books author and title say.

2). I'm not sure that I understand exactly the alternatives.Is the question whether Item itself has the "persistence" logic to call the API, or whether you have a Library object that fetches Items? My instinct is that you will need a Library to manage the searches, it can encapsualte the details of accessing one or more remote sites.

djna