zettajs / ZettaKit

The Zetta iOS Client Library.
MIT License
3 stars 2 forks source link

Connecting to http://demo.zettaapi.org/servers/detroit via ZettaKit #22

Open benpackard opened 8 years ago

benpackard commented 8 years ago

I'm not sure if there is an issue in the API content that ZettaKit is stumbling over or some other cause, but I can't receive any devices from http://demo.zettaapi.org/servers/detroit. @landlessness added a new property, but otherwise I don't see any significant differences.

landlessness commented 8 years ago

hmm. I ran the response data thru a JSON validator and sirenlint. Both passed with no problems.

benpackard commented 8 years ago

Just to check it's nothing on my end, what happens when you plug the URI into the app?

mdobson commented 8 years ago

I ran my sample and the zettaios/zetta app and both had devices appear. Network level thing?

-Matt

-- Matthew Dobson | apigee https://apigee.com/ | m: +1.734.634.5472 | twitter @mdobs http://twitter.com/mdobs @apigee https://twitter.com/apigee | Apigee Community http://community.apigee.com/ for answers, ideas and support!

On Thu, Mar 3, 2016 at 10:27 AM, brian mulloy notifications@github.com wrote:

hmm. I ran the response data thru a JSON validator and sirenlint. Both passed with no problems.

— Reply to this email directly or view it on GitHub https://github.com/zettajs/ZettaKit/issues/22#issuecomment-191814276.

benpackard commented 8 years ago

@landlessness You're seeing the same in the app? Devices are listed for http://demo.zettaapi.org/servers/detroit?

I'm able to read the response in Postman so pretty sure it's not an access thing. And am accessing it via the app using the same WiFi network. Other API is loading just fine. Weird.

landlessness commented 8 years ago

@benpackard

this fails: http://demo.zettaapi.org/servers/detroit

this works: http://demo.zettaapi.org

perhaps we need an enhancement request so that on the iOS side, Zetta still works even if the user 'over specifies' the URL? @mdobson thoughts?

kevinswiber commented 8 years ago

We handle this in the Zetta browser by using the Siren class values to route to the correct view. On Thu, Mar 3, 2016 at 7:49 AM brian mulloy notifications@github.com wrote:

@benpackard https://github.com/benpackard

this fails: http://demo.zettaapi.org/servers/detroit

this works: http://demo.zettaapi.org

perhaps we need an enhancement request so that on the iOS side, Zetta still works even if the user 'over specifies' the URL? @mdobson https://github.com/mdobson thoughts?

— Reply to this email directly or view it on GitHub https://github.com/zettajs/ZettaKit/issues/22#issuecomment-191822225.

benpackard commented 8 years ago

@kevinswiber can you elaborate on this a little? Which class values do you intercept and how do you handle them? Do you and/or @mdobson think it's something I can do client-side, or should be added to ZettaKit? Thanks.

mdobson commented 8 years ago

Time for a quick google hangout Ben? Easier to talk through.

-- Matthew Dobson | apigee https://apigee.com/ | m: +1.734.634.5472 | twitter @mdobs http://twitter.com/mdobs @apigee https://twitter.com/apigee | Apigee Community http://community.apigee.com/ for answers, ideas and support!

On Thu, Mar 3, 2016 at 11:42 AM, Ben Packard notifications@github.com wrote:

@kevinswiber https://github.com/kevinswiber can you elaborate on this a little? Which class values do you intercept and how do you handle them? Do you and/or @mdobson https://github.com/mdobson think it's something I can do client-side, or should be added to ZettaKit? Thanks.

— Reply to this email directly or view it on GitHub https://github.com/zettajs/ZettaKit/issues/22#issuecomment-191846332.

mdobson commented 8 years ago

Nvm. Have other things coming up.

Class is apart of the Siren spec. It essentially dictates the context of an entity over the api. In the case of zetta some classes are root,* server, and device*. I'll throw together a code sample that you can use to interpret the class of an entity and make proper adjustments.

-Matt

-- Matthew Dobson | apigee https://apigee.com/ | m: +1.734.634.5472 | twitter @mdobs http://twitter.com/mdobs @apigee https://twitter.com/apigee | Apigee Community http://community.apigee.com/ for answers, ideas and support!

On Thu, Mar 3, 2016 at 11:43 AM, Matthew Dobson mdobson@apigee.com wrote:

Time for a quick google hangout Ben? Easier to talk through.

-- Matthew Dobson | apigee https://apigee.com/ | m: +1.734.634.5472 | twitter @mdobs http://twitter.com/mdobs @apigee https://twitter.com/apigee | Apigee Community http://community.apigee.com/ for answers, ideas and support!

On Thu, Mar 3, 2016 at 11:42 AM, Ben Packard notifications@github.com wrote:

@kevinswiber https://github.com/kevinswiber can you elaborate on this a little? Which class values do you intercept and how do you handle them? Do you and/or @mdobson https://github.com/mdobson think it's something I can do client-side, or should be added to ZettaKit? Thanks.

— Reply to this email directly or view it on GitHub https://github.com/zettajs/ZettaKit/issues/22#issuecomment-191846332.

benpackard commented 8 years ago

Thanks, I have that part down, but I think I'm limited to simply sending the user-entered URL into the sharedSession and monitoring its signal for devices and servers. I'm not sure how I can use the class to tweak the original URL since I'll never get anything back from the signal.

kevinswiber commented 8 years ago

@benpackard Don't change the URL. The way I've built UI-based hypermedia clients in the past is to change the view based on the contents of the API response.

  1. Make the HTTP request.
  2. Inspect the response. If it's Siren, look at the top-level class array.
  3. Match the contents of the class array to a view. In Zetta's case, you'd be looking for root, server, or device.
  4. Populate and display the view.

Does that make sense?

mdobson commented 8 years ago

This is one way you could inspect the response with ZettaKit.

    NSURL *url = [NSURL URLWithString:@"http://zetta-cloud-2.herokuapp.com/"];
    ZIKSession *session = [ZIKSession sharedSession];
    RACSignal *request = [session load:url];

    RACSignal *remapped = [request map:^id(NSDictionary *value) {
        NSLog(@"value %@", value);
        if ([value[@"class"] indexOfObject:@"root"] != NSNotFound) {
            return [ZIKRoot initWithDictionary:value];
        } else if([value[@"class"] indexOfObject:@"server"] != NSNotFound) {
            return [ZIKServer initWithDictionary:value];
        } else if([value[@"class"] indexOfObject:@"device"] != NSNotFound) {
            return [ZIKDevice initWithDictionary:value];
        } else {
            return value;
        }
    }];

    [remapped subscribeNext:^(id x) {
        NSLog(@"Entity: %@", x);
    }];

@benpackard

benpackard commented 8 years ago

@kevinswiber It does, but I don't have any access to the HTTP response. That's all abstracted nicely by ZettaKit.

mdobson commented 8 years ago

@benpackard

You can also use subscribe to get the entity as well.

    NSURL *url = [NSURL URLWithString:self.apiEndpoint];
    ZIKSession *session = [ZIKSession sharedSession];

    RACSignal *request = [session load:url];

    [request subscribeNext:^(id x) {
        NSDictionary *value = (NSDictionary *)x;
        if ([value[@"class"] indexOfObject:@"root"] != NSNotFound) {
            NSLog(@"Is root");
        } else if([value[@"class"] indexOfObject:@"server"] != NSNotFound) {
            NSLog(@"Is server");
        } else if([value[@"class"] indexOfObject:@"device"] != NSNotFound) {
            NSLog(@"Is device");
        } else {
            NSLog(@"Is %@", value[@"class"][0]);
        }
    }];