UA-17470720-3

Jump to content


Photo
- - - - -

updateObjectAPI and updateObjectParameters

data-definitions web-services

  • Please log in to reply
6 replies to this topic

#1 rolfenstein

rolfenstein

    Jr. Member

  • STV 4.0 Pro
  • PipPip
  • 16 posts
Reputation: 1
Good

Posted 22 May 2014 - 10:20 AM

How do I correctly configure STV to post to my web service. I set the updateObjectAPI property of my SCWebServiceDefinition to a string of my post api. It looks like it is adding an extra "/(null)" to the end of the extension and is returning a 404 not found error.

What updateObjectParameters are available? The documentation only says that updateObjectParameters is an NSDictionary property of SCWebServiceDefinition.



#2 rolfenstein

rolfenstein

    Jr. Member

  • STV 4.0 Pro
  • PipPip
  • 16 posts
Reputation: 1
Good

Posted 23 May 2014 - 11:31 AM

Some more detail

My original code was:

    SCWebServiceDefinition *userDef = [SCWebServiceDefinition

                                           definitionWithBaseURL:@"http://www.xxxxx.com/iphone/"

                                           fetchObjectsAPI:[NSString stringWithFormat:@"Service1.svc/getUserData/%@",sampleUser] resultsKeyName:@"GetUserDataResult"

                                           resultsDictionaryKeyNamesString:@"UserName;Country;Currency"];

    userDef.updateObjectAPI = @"Service1.svc/updateUser";

 

This results in the following error when I try to update. App does not crash

 

**STV** Web Service Error: Error Domain=com.alamofire.networking.error Code=-1011 "Expected status code in (200-299), got 404" UserInfo=0x16e4a210 {NSErrorFailingURLKey=http://www.xxxxx.com...svc/updateUser/(null), NSLocalizedDescription=Expected status code in (200-299), got 404}

 

Today I found this forum post and added the following code.

http://sensiblecocoa...sides-parsecom/

 

    SCWebServiceStore *stringSendStore = (SCWebServiceStore *)[userDef generateCompatibleDataStore];

    [stringSendStore asynchronousUpdateObject:myUser success: ^()

     {

         NSLog(@"Success");

     }

                                      failure: ^(NSError *error)

     {

         NSLog(@"%@",error);

     }];

 

This crashes at start with this error

 

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<User 0x17dbfdd0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key (null).'

 

 

How to configure correctly?

 

 



#3 Everett

Everett

    Ev

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 191 posts
  • LocationMichigan
Reputation: 60
Outstanding

Posted 23 May 2014 - 04:51 PM

Hi rolfenstein,

 

A couple of tips that may help you out.  The SCWebService and it's associated classes are designed to provide a REST Service type integration. The way that STV does that is like this mapping:

 

fetch ~ "http get"

insert ~ "http post'

update ~ "http put"

delete ~ "http delete"

 

so in your example, it looks like you have it setup correctly in terms of parameters, however does your web service expect a  "http put" on update.  

 

In your question you ask how to correctly "post" to a web service, so I assume you need to "post" for an update.  Using the STV WebService, http post only occurs on insert, so to "post" you have to set your insertObjectApi parameters correctly.

 

If your web service supports this approach, then things should work nicely, but if it does not, then you have to either do a bunch of work subclassing and overriding methods in SCWebServiceStore or you roll your own network calls and populate STV from them.

 

Something else that may help you in this process is to look at a tool called Charles.  It's like a network proxy and allows you to inspect network traffic.  Its very helpful in debugging issues like you reported.

 

best wishes,

Everett


  • rolfenstein likes this

#4 rolfenstein

rolfenstein

    Jr. Member

  • STV 4.0 Pro
  • PipPip
  • 16 posts
Reputation: 1
Good

Posted 27 May 2014 - 09:54 AM

Thanks Everett. Yes my service is http post, so I want to use insert. How to set up? I tried to change "userDef.updateObjectAPI" to "userDef.insertObjectAPI" but get an error that no updateObjectAPI was specified. So when the web service definition is used to create a tableview model, the default "done" button in the Navigation bar is an update? Can it be changed to an insert?

 

I actually don't want to go through the Navigation bar. I want either the user setting to change automatically in the database, or to use a button to call my already working update object from JSON function. Is a web service definition the best way?

 

Also the default table view model defaults to a cell for each user (in my case one cell). Clicking on the cell goes to view with cells for each property. Since it is a single user, I only want the table view showing the object properties. How can I set up the web definition for a single object? Or would it be better to use another model and my own custom load and update functions?



#5 Everett

Everett

    Ev

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 191 posts
  • LocationMichigan
Reputation: 60
Outstanding

Posted 27 May 2014 - 04:56 PM

I really enjoy using the power of the STV framework, but there are times when I find myself trying to fit my project into the framework rather then fitting the framework to my project.  If you find that to be the case, then you may be over thinking it.  Remember, try and build a proper solution for the task.

 

The basic framework is very well abstracted, so if you want to work with just a single cell, you can do that (SCTableViewCell).  Don't like the detail views, just make your own (override with a cellActions.didSelect or cellActions.detailViewController block).  Want to control your own updates use cellActions.valueChanged blocks to update.  Using class definitions is very easy and still allows some great productivity helpers.  If you can use core data, you get even more.  In fact, in one project I have, STV only deals with core data, nothing else and its great.  I handle the backend fetches and updates with pure network code.  In another project with Parse as the backend (a more compliant REST interface), I have quite a few modules strictly based on SCParseDefinition and its great as well.

 

If your backend was really "rest" compliant, I'd suggest keeping at it and try to make it work, but it seems more like you have a backend service that is more traditional and uses JSON.  If that is the case, I'd recommend avoiding the web service definition and use SCClass definitions or SCEntity definitions.

 

Sorry, no code here, but most of the code you need is in the ebook.  

best wishes,

Everett


  • rolfenstein likes this

#6 rolfenstein

rolfenstein

    Jr. Member

  • STV 4.0 Pro
  • PipPip
  • 16 posts
Reputation: 1
Good

Posted 27 May 2014 - 10:57 PM

My service should be RESTful, it is the Windows WCF one from here http://mikesknowledg...ices-Page3.htm.

 

From the error it looks like the "done" nav bar button. expects to use a "put" instead of a "post". There must be a way to call insertObjectAPI instead of updateObjectAPI. Or does adding a new record always use insertObjectAPI and updating a record use updateObjectAPI? The problem with the ebook is it only covers receiving data from web service, nothing on posting (or putting....).

 

I guess I will try with core data and my own post routine.

 

If I wanted it to update automatically, I would use "valueChangedForRowAtIndexPath"? The online documentation says to only use this when subclassing SCTableViewModel, but this is what I would use if not using STV so I don't know another way, I don't think I need to subclass.



#7 Everett

Everett

    Ev

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 191 posts
  • LocationMichigan
Reputation: 60
Outstanding

Posted 30 May 2014 - 03:48 AM

If you want to control the updates at a cell level, you should use the cellActions.valueChanged block.  This is handled for you automatically if you are using core data.  If your using your own class, your class object is updated automatically and you can use this block to persist data, like to SQLite for example - I use it this way for my SQLite projects. Or just use this block to filp a flag to mark your record dirty, then override the "done" button action when the use taps it either persist data or make a network call based on that flag.

 

In this case the done action is opposed to the cancel action that is very common in the framework. 

 

I've never had to subclass SCTableViewModel so I'm not sure about implementation details, but don't know why it would necessary for your current needs.


  • rolfenstein likes this





Also tagged with one or more of these keywords: data-definitions, web-services

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users