Code4HR / local-art-api

Public Art Installations in Norfolk, VA
https://localartapi-code4hr.rhcloud.com/
GNU Affero General Public License v3.0
4 stars 4 forks source link

REST API #2

Closed ghost closed 10 years ago

ghost commented 10 years ago

Question: how much difficulty would creating a REST API akin to this one here present with this service?

It would only really need find and find all methods, really, so /exhibits and /exhibits/999 routes that have all of the attributes present in the exhibit model.

qwo commented 10 years ago

cake. ill tackle this tonight and should be good by tomorrow

ghost commented 10 years ago

:smiley: Nice, man, that would make everything the simplest. If you need the full image urls for now, I have them all for the existing exhibits in the JSON file under "fullimage".

ghost commented 10 years ago

Ultimately, I think this would solve the asynchronous loading issue, since using the DS.RESTAdapter would make more sense for this sort of thing anyway.

qwo commented 10 years ago

Unrelated but not sure if you've seem this.

http://norfolkpublicart.org/ the old art app is featured there! I'm stoked for this one replacing that one

On Friday, June 20, 2014, Ryan Y. notifications@github.com wrote:

Ultimately, I think this would solve the asynchronous loading issue, since using the DS.RESTAdapter would make more sense for this sort of thing anyway.

— Reply to this email directly or view it on GitHub https://github.com/c4hrva/proxy-art/issues/2#issuecomment-46692514.


Spam https://www.spamtrap.odu.edu/canit/b.php?i=02MgDB3g4&m=f95069008331&t=20140620&c=s Not spam https://www.spamtrap.odu.edu/canit/b.php?i=02MgDB3g4&m=f95069008331&t=20140620&c=n Forget previous vote https://www.spamtrap.odu.edu/canit/b.php?i=02MgDB3g4&m=f95069008331&t=20140620&c=f

Stanley Zheng @stanzheng http://twitter.com/stanzheng

ghost commented 10 years ago

Whoa, cool! I had no idea! :smiley: ! Same here, dude, I think this will work nicely. The current map link on that site seems to have broken, too, which I find weird, since the cultural affairs site still exists.

qwo commented 10 years ago

i was exhausted last night but after i took a nap im all good now. So you would like a REST implementation that gives you an exhibits route.

So a type of request would be

/exhibits/ would return a similar object to you json file?

and each /exhibits accept query strings for each field?

example

/exhibits?id=1

returns

{
    "id": 1,
    "title": "Torch Bearers",
    "longitude": -76.29367858171463,
    "latitude": 36.85602296216651,
    "location": "Chrysler Museum",
    "artists": "Anna Hyatt Huntington",
    "url": "http://www.norfolkva.gov/cultural_affairs/chrysler_museum_art_torch_bearers.asp",
    "imageurl": "http://www.norfolkva.gov/cultural_affairs/images/Chrysler_Museum/Torch_Bearers_Map.jpg",
    "fullimage": "http://www.norfolkva.gov/cultural_affairs/images/Chrysler_Museum/Torch_Bearers_LightBox.jpg"
qwo commented 10 years ago

i updated the route to at least be more friendly to look at.

http://norfolkart.herokuapp.com/exhibits

**edit lmao ignore the link i posted previously

qwo commented 10 years ago

hi @ryayak1460 i modeled it after how the app works and the routes it asks for.

http://norfolkart.herokuapp.com/exhibits/2 for #2 http://norfolkart.herokuapp.com/exhibits for all

should be working now

ghost commented 10 years ago

Sorry for the lack of response, having a rough time in general.

Checking it now, though, should this function? I have HTTP GET issues.

EDIT: The response I get:

Cannot GET /exhibits/2
Cannot GET /exhibits
qwo commented 10 years ago

hmm oh yeah might be because i changed it from exhibits to EXHIBIT to reflect your current scheme.

On Mon, Jun 23, 2014 at 10:18 AM, Ryan Y. notifications@github.com wrote:

Sorry for the lack of response, having a rough time in general.

Checking it now, though, should this function? I have HTTP GET issues.

— Reply to this email directly or view it on GitHub https://github.com/c4hrva/proxy-art/issues/2#issuecomment-46850713.


Spam https://www.spamtrap.odu.edu/canit/b.php?i=02MhOjqTk&m=720af770e1f2&t=20140623&c=s Not spam https://www.spamtrap.odu.edu/canit/b.php?i=02MhOjqTk&m=720af770e1f2&t=20140623&c=n Forget previous vote https://www.spamtrap.odu.edu/canit/b.php?i=02MhOjqTk&m=720af770e1f2&t=20140623&c=f

Stanley Zheng @stanzheng http://twitter.com/stanzheng

ghost commented 10 years ago

I just tried accessing the site via the address bar in Firefox, not actually consuming the REST API using the application just yet.

qwo commented 10 years ago

sorry oops. my bad

try

http://norfolkart.herokuapp.com/exhibit http://norfolkart.herokuapp.com/exhibit/2

qwo commented 10 years ago

i just hot patched in #7

ghost commented 10 years ago

Oh, okay. The DS.RESTAdapter would actually want /exhibits and /exhibits/2 instead, at least according to the Ember guide and the DS.RESTAdapter documentation.

qwo commented 10 years ago

ha ok i can relabel the routes no problem one sec..

ghost commented 10 years ago

You work quick as Hell, dude. :smiley:

ghost commented 10 years ago

I'll do some work in the middle of testing today on getting the client to respond to the REST API for this. Thanks, man.

qwo commented 10 years ago

well i had to hotpatch my carelessness in #7 let me know if it conforms to the standard, if not ill update the spec.

I'm also working to cache the results on a mongo instance and pull that instead of reparsing the xml feed each time

Its on there, i just haven't adjusted the code to query that instead of the current reparsing. should be half a hour of work tops when i get the chance.

ghost commented 10 years ago

Okay, either way works, honestly. I'd prefer a storeless application, but this keeps seeming to require more than originally anticipated.

Regarding the REST API, the exhibit model has the following attribute set:

EDIT: I used the latest Exhibit model for this attribute set.

EDIT EDIT: Created #8 to refer to this.

qwo commented 10 years ago

oops ok. i just based it off the current passed XML doc. I will adjust and fix that.

On Mon, Jun 23, 2014 at 11:09 AM, Ryan Y. notifications@github.com wrote:

Okay, either way works, honestly. I'd prefer a storeless application, but this keeps seeming to require more than originally anticipated.

Regarding the REST API, the exhibit model has the following attribute set:

  • id : String
  • title: String ( = title)
  • latitude : Number ( = lat)
  • longitude : Number ( = lng)
  • location : String ( = loc)
  • artists : String ( = artist)
  • url : String (= link =~ s/^a href='//g =~ s/'$//g, using PERL regex replacement syntax)
  • imageurl : String (= img =~ s/^img src='//g =~ s/' alt=.*$//g)
  • fullimage : String (not in the original XML, have to use the JSON file for reference)

— Reply to this email directly or view it on GitHub https://github.com/c4hrva/proxy-art/issues/2#issuecomment-46857668.


Spam https://www.spamtrap.odu.edu/canit/b.php?i=01MhP9Pwq&m=507180b3385f&t=20140623&c=s Not spam https://www.spamtrap.odu.edu/canit/b.php?i=01MhP9Pwq&m=507180b3385f&t=20140623&c=n Forget previous vote https://www.spamtrap.odu.edu/canit/b.php?i=01MhP9Pwq&m=507180b3385f&t=20140623&c=f

Stanley Zheng @stanzheng http://twitter.com/stanzheng

ghost commented 10 years ago

No problems, man, the asynchronous loading code made a lot of those transformations in the process of everything, I never specified that part. Here's where having unit tests would prove really helpful. :laughing:

Also, have you included the Botanical Gardens art data as well?

EDIT: Created #9 to refer to this.

jalbertbowden commented 10 years ago

not sure where to say this but any way you can just return the img src? the added alt attribute is highly desired but the rest of the gobbledy gook imo you should ditch. maybe return as separate options, but all of that is unnecessary in the markup

ghost commented 10 years ago

Yeah, that all came from the original XMLs (here and here), which we have no direct control over, unfortunately, the City of Norfolk does.

jalbertbowden commented 10 years ago

you cant filter it while parsing? huh. i did this last year and got pretty much up to this part.

ghost commented 10 years ago

If we load the XML files directly, yes, we can parse the XML, substitute and change existing fields to what they should appear as.

However, as I've noticed recently, loading all the data initially into the store has the added issue of forced refresh issues where you may lose all of your cached data because the initial load never happens after closing the application initially, so using a REST adapter instead to load the data momentarily in an online fashion for display makes more sense, and therefore it would make more sense to make those transformations happen in the service instead of after loading said data from the service.

ghost commented 10 years ago

Okay, so after #11, the model matches (#2), but the API still needs to return the data in a format similar to the post record displayed here, i.e., with the name of the model (exhibit, in our case) as the root element of the JSON, at least for single records returned from /exhibits/2 and the like.

I actually don't know how the DS.RESTAdapter expects multiple records... I guess try:

{
    "exhibit": [
        {
            "id": 1,
            ...
        },
        {
            "id": 2,
            ...
        }
    ]
}

I can attempt to use the DS.RESTAdapter again once we make these changes.

qwo commented 10 years ago

let me know if you're still having difficulty with the rest adapter. the solution i added is embarassingly dead simple

ghost commented 10 years ago

Sure. The comment above actually relates. Have to have an exhibit root key which refers to the object or array returned for either /exhibits or /exhibits/2, like this:

Single record:

{
    "exhibit": {
        "id": 1,
        ...
    }
}

Multiple records:

{
    "exhibit": [
        {
            "id": 1,
            ...
        },
        {
            "id": 2,
            ...
        }
    ]
}

Past that, looks awesome, man.

ghost commented 10 years ago

Also, the email from the http://norfolkva.gov webmaster leads me to believe that we can actually manage the data ourselves, so the Node.js/Mongo instance makes a lot of sense now. Good call!

ghost commented 10 years ago

Functions as of 0c68856279d665a08f54229b7e33c00a9cc4ab5d.