UA-17470720-3

Jump to content


Photo
- - - - -

WebService Parameters


  • Please log in to reply
10 replies to this topic

#1 Vince

Vince

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 23 posts
Reputation: 0
Neutral

Posted 18 April 2014 - 04:44 PM

Hi 

 

I'm not sure to fully understand the WebServiceDefinition Parameters with regards to the Resultkey. My Webservice returns the following JSON:

 

{
  "6222606": {
    "id": 6222606,
    "name": "EXJADE® Global Dosing Calculator",
    "developer": "Novartis Pharmaceutical Corporation",
    "icon": "http://a5.mzstatic.com/us/r1000/056/Purple/c6/55/20/mzi.tenlumxp.100x100-75.jpg",
    "vendor_identifier": "377043440",
    "ref_no": 377043440,
    "sku": "GCT8095",
    "package_name": null,
    "store_id": 1,
    "store": "apple",
    "release_date": "2010-08-16T04:00:00-04:00",
    "added_date": "2011-11-28T19:05:57-05:00",
    "updated_date": "2013-08-21T09:01:08-04:00",
    "version": "1.01",
    "source": {
      "external_account_id": 73209,
      "added_timestamp": "2010-01-01T00:00:00",
      "active": true,
      "hidden": false,
      "type": "own"
    },
    "type": "app",
    "devices": [
      "Handheld",
      "Tablet"
    ],
    "children": [],
    "features": [],
    "parent_id": null,
    "price": {
      "currency": "USD",
      "price": "0.00"
    }
  },
  "6222615": {
    "id": 6222615,
    "name": "Dosing Calculator",
    "developer": "Novartis Pharmaceutical Corporation",
    "icon": "http://a3.mzstatic.com/us/r1000/074/Purple/v4/66/b1/62/66b162e9-8653-01db-291b-f697250a165a/mzl.rhofzoyc.75x75-65.png",
    "vendor_identifier": "377046352",
    "ref_no": 377046352,
    "sku": "EXJ900999",
    "package_name": null,
    "store_id": 1,
    "store": "apple",
    "release_date": "2010-01-15T05:06:00-05:00",
    "added_date": "2011-12-17T15:23:19-05:00",
    "updated_date": "2012-06-05T09:00:00-04:00",
    "version": "1.3",
    "source": {
      "external_account_id": 73209,
      "added_timestamp": "2010-01-01T00:00:00",
      "active": true,
      "hidden": false,
      "type": "own"
    },
    "type": "app",
    "devices": [
      "Handheld",
      "Tablet"
    ],
    "children": [],
    "features": [],
    "parent_id": null,
    "price": {
      "currency": "USD",
      "price": "0.00"
    }
  },
  "6222624": {
    "id": 6222624,
    "name": "IPSS Calculator",
    "developer": "Novartis Pharmaceutical Corporation",
    "icon": "http://a782.phobos.apple.com/us/r1000/053/Purple/8f/f9/da/mzl.gjdgztfu.png",
    "vendor_identifier": "377048773",
    "ref_no": 377048773,
    "sku": "EXJ800433",
    "package_name": null,
    "store_id": 1,
    "store": "apple",
    "release_date": "2010-01-15T05:06:00-05:00",
    "added_date": "2011-11-22T23:46:31-05:00",
    "updated_date": "2011-11-02T13:00:02-04:00",
    "version": "1.0",
    "source": {
      "external_account_id": 73209,
      "added_timestamp": "2010-01-01T00:00:00",
      "active": true,
      "hidden": false,
      "type": "own"
    },
    "type": "app",
    "devices": [
      "Handheld",
      "Tablet"
    ],
    "children": [],
    "features": [],
    "parent_id": null,
    "price": {
      "currency": "USD",
      "price": "0.00"
    }
  },
  "6222635": {
    "id": 6222635,
    "name": "IPSS Calculator International",
    "developer": "Novartis Pharmaceutical Corporation",
    "icon": "http://a5.mzstatic.com/us/r30/Purple/9b/88/f5/mzl.tnilssvf.100x100-75.jpg",
    "vendor_identifier": "377050586",
    "ref_no": 377050586,
    "sku": "GCT8095-INT",
    "package_name": null,
    "store_id": 1,
    "store": "apple",
    "release_date": "2010-06-15T04:00:00-04:00",
    "added_date": "2011-11-28T19:15:32-05:00",
    "updated_date": "2014-04-11T09:00:03-04:00",
    "version": "1.0",
    "source": {
      "external_account_id": 73209,
      "added_timestamp": "2010-01-01T00:00:00",
      "active": true,
      "hidden": false,
      "type": "own"
    },
    "type": "app",
    "devices": [
      "Handheld",
      "Tablet"
    ],
    "children": [],
    "features": [],
    "parent_id": null,
    "price": {
      "currency": "USD",
      "price": "0.00"
    }
  },
  "6244672": {
    "id": 6244672,
    "name": "Sickle Cell Iron Invaders",
    "developer": "Novartis Pharmaceutical Corporation",
    "icon": "http://a1.mzstatic.com/us/r30/Purple6/v4/27/68/27/27682782-81d4-c317-f63b-31e7122b5896/mzl.kdvgbtcz.100x100-75.jpg",
    "vendor_identifier": "380101118",
    "ref_no": 380101118,
    "sku": "EXJ-800439-A",
    "package_name": null,
    "store_id": 1,
    "store": "apple",
    "release_date": "2010-07-07T04:00:00-04:00",
    "added_date": "2011-11-22T23:48:34-05:00",
    "updated_date": "2014-04-11T09:00:03-04:00",
    "version": "1.1",
    "source": {
      "external_account_id": 73209,
      "added_timestamp": "2010-01-01T00:00:00",
      "active": true,
      "hidden": false,
      "type": "own"
    },
    "type": "app",
    "devices": [
      "Handheld",
      "Tablet"
    ],
    "children": [],
    "features": [],
    "parent_id": null,
    "price": {
      "currency": "USD",
      "price": "0.00"
    }
  }
}

Now how would my ResultKeyname or resultsDictionaryKeyNamesString / resultsDictionaryKeyNames have to look like? The json sends back a variable which I cannot hardcode?

 

any help is much appreciated

 

vince



#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 19 April 2014 - 06:15 AM

Hi Vince,

 

A typical web service request should return all results in a JSON array under a specific key (typically called "results"/"result"). For example, this is a sample of a Yahoo! search request output:

 

{"Result":[
    {
      "Title":"madonna 116",
      "Summary":"Picture 116 of 184",
      "Url":"http:\/\/www.celebritypicturesarchive.com\/pictures\/m\/madonna\/madonna-116.jpg",
      "ClickUrl":"http:\/\/www.celebritypicturesarchive.com\/pictures\/m\/madonna\/madonna-116.jpg",
      "RefererUrl":"http:\/\/www.celebritypicturesarchive.com\/pgs\/m\/Madonna\/Madonna%20picture_116.htm",
      "FileSize":"36990",
      "FileFormat":"jpeg",
      "Height":"530",
      "Width":"425",
      "Thumbnail":{
        "Url":"http:\/\/scd.mm-b1.yimg.com\/image\/481989943",
        "Height":"125",
        "Width":"100"
       }
    },
    {
      "Title":"madonna 118",
      "Summary":"Picture 118 of 184",
      "Url":"http:\/\/www.celebritypicturesarchive.com\/pictures\/m\/madonna\/madonna-118.jpg",
      "ClickUrl":"http:\/\/www.celebritypicturesarchive.com\/pictures\/m\/madonna\/madonna-118.jpg",
      "RefererUrl":"http:\/\/www.celebritypicturesarchive.com\/pgs\/m\/Madonna\/Madonna%20picture_118.htm",
      "FileSize":"40209",
      "FileFormat":"jpeg",
      "Height":"700",
      "Width":"473",
      "Thumbnail":{
        "Url":"http:\/\/scd.mm-b1.yimg.com\/image\/500892420",
        "Height":"130",
        "Width":"87"
      }
    }
  ]
}

 

In the above output, the SCWebServiceDefinition resultsKeyName should be set to @"Result". You'll see the same pattern in almost all other popular web services. It doesn't seem however that your web service adheres to this convention. Do you have any access to how the output is formatted?



#3 Vince

Vince

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 23 posts
Reputation: 0
Neutral

Posted 20 April 2014 - 11:04 AM

Hello

 

thank you for your answer, unfortunately i don't have any influence on how the webservice outputs the json... is there any workaround I can implement with SC or must i contact the webservice owner and ask him to amend to standards?



#4 Vince

Vince

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 23 posts
Reputation: 0
Neutral

Posted 20 April 2014 - 05:52 PM

Hello

 

thank you for your answer, unfortunately i don't have any influence on how the webservice outputs the json... is there any workaround I can implement with SC or must i contact the webservice owner and ask him to amend to standards?

 

For example, I could fetch and process the json result the conventional way but then how do I pass it to SC for representation?



#5 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 22 April 2014 - 07:48 AM

Hi Vince,

 

You can always subclass SCWebServiceStore and override the method called asynchronousFetchObjectsWithOptions:success:failure:, which will enable you to parse the JSON in any way you wish. It would probably be much easier of course if you ask your web service owner to return the data in the aforementioned format.

 

PS: Let me know if you need help with subclassing.



#6 Everett

Everett

    Ev

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

Posted 22 April 2014 - 02:46 PM

Hi @ibesuf,

 

just my .02

 

Please consider how you are going to use the data.  The SCWebService will help create a whole wrapper around that endpoint.  If you need to add,edit and delete, it may be worthwhile going down the path of subclassing, however based upon your example JSON, I'm guessing the other endpoints are not really RESTFUL and thus you may have to adjust SCWebService for each endpoint and each service (get,post,etc), making things somewhat more complicated. If its a compliant REST service things work well, if it's just a web service that provides JSON (instead of say SOAP/XML) then you have more manual work to do.

 

If you only need to get the data into a tableview for display or for other drill down needs its still very easy to use with Sensible.  You will need to fetch the data with NSURLConnection or NSURLSession and then convert the JSON into a MutableArray of NSDictionaries.  Once you get the data in that format, you can use an SCArrayOfObjectsSection initialized with the array to create your tableview experience.  Using action blocks you can respond as needed.

 

And if you are changing the data,  STV has a dictionary definition use can use to define your fields, so you can drive an edit detail view.  After the saved change you can again use the action blocks to respond to the changed data with your own network call to the api of your service.  It's not as compact as the SCWebService approach, but it's still a pretty tried and true approach.

 

best wishes


  • Tarek and wizgod like this

#7 Vince

Vince

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 23 posts
Reputation: 0
Neutral

Posted 02 May 2014 - 06:56 AM

Dear both

 

 

Hi @ibesuf,

 

just my .02

 

Please consider how you are going to use the data.  The SCWebService will help create a whole wrapper around that endpoint.  If you need to add,edit and delete, it may be worthwhile going down the path of subclassing, however based upon your example JSON, I'm guessing the other endpoints are not really RESTFUL and thus you may have to adjust SCWebService for each endpoint and each service (get,post,etc), making things somewhat more complicated. If its a compliant REST service things work well, if it's just a web service that provides JSON (instead of say SOAP/XML) then you have more manual work to do.

 

If you only need to get the data into a tableview for display or for other drill down needs its still very easy to use with Sensible.  You will need to fetch the data with NSURLConnection or NSURLSession and then convert the JSON into a MutableArray of NSDictionaries.  Once you get the data in that format, you can use an SCArrayOfObjectsSection initialized with the array to create your tableview experience.  Using action blocks you can respond as needed.

 

And if you are changing the data,  STV has a dictionary definition use can use to define your fields, so you can drive an edit detail view.  After the saved change you can again use the action blocks to respond to the changed data with your own network call to the api of your service.  It's not as compact as the SCWebService approach, but it's still a pretty tried and true approach.

 

best wishes

 

@Everett : I followed your advice and still struggle with a few things, but generally spoken it seems to work quite well. I indeed did get the results separately and initialise the SCArrayOfObjectsSection with that new array, this works like a charm. The point am still struggling with a bit, is to get familiarised with the actions, but I should be able to handle that (learning curve). In any case thank you very much for the hint, it's a great help! 

 

Hi Vince,

 

You can always subclass SCWebServiceStore and override the method called asynchronousFetchObjectsWithOptions:success:failure:, which will enable you to parse the JSON in any way you wish. It would probably be much easier of course if you ask your web service owner to return the data in the aforementioned format.

 

PS: Let me know if you need help with subclassing.

 

@Tarek: I haven't been subclassing at the moment because as Everett mentioned, it would probably entail that I need to change many more things. Since I do not have to alter the data but only need them to display, Everett proposal serves me perfectly.

 

@Both, thank you much for your help, once I figured the whole code, I will post it here for the community. I can imagine I ain't the only one which it could help 



#8 Everett

Everett

    Ev

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

Posted 03 May 2014 - 01:08 PM

Hi Vince,

 

I'm glad your making progress.  If you are new to STV or new to IOS, the action blocks utilized are very powerful, but can take a bit to wrap your head around them.

 

If you are familiar with UITableView delegates, then it will make sense much faster as the action blocks are block based alternative's to using the delegates.  You just have to get over the syntax issues.

 

So they go something like this:

 

section.cellActions.[Action] = [Block Definition] [Your Code] [Block Closure];

 

Example:

 

        articleList.cellActions.didSelect = ^(SCTableViewCell *cell, NSIndexPath *indexPath) {

            

             Article *article = [self.parsedItems objectAtIndex:indexPath.row];

            article.feedTitle = self.blogChoice.site;

            [weakSelf performSegueWithIdentifier:@"ArticleWebViewer" sender:article];

            [cell.ownerTableViewModel.tableView deselectRowAtIndexPath:indexPath animated:YES];

        };

 

 

The didSelect action is the same as the UITableView didSelect delegate call back. There are quite a few other useful actions as well.  In this example, I'm performing a segue, but really anything that needs to be done after selection would go here. Note: for sections with detail views you would want to use sectionActions.detailViewControllerForRowAtIndexPath to avoid the detail view and transition to your own controller.

 

For more info on the actions available, check the online documentation or review SCCellActions.h, where there is code examples.

 

The biggest hurdle I had with actions as I recall was getting the block completion syntax correct because it does not auto complete.  What I mean is the block identifier on the right of the equal sign.  This was frustrating to me because block syntax was confusing enough and I couldn't recall the specific definitions for different actions (they are not all the same).  In the cell actions file you will find example code that provides the block definition and its very helpful.

 

One more tip.  I do better understand block syntax now, but this issue really went away when I figured out how to use the Xcode snippet library to solve this problem.  If you haven't used it for either apple snippets or to create your own snippets, you should look into it.  

 

What I did was create a snippet for each block definition, make it a shortcut (in the snippet editor) and give it a name.  I named them all starting with 'stv', like 'stv-cell actions block' or 'stv-detail model configured'.  Once they were saved, I had access to them all via code completion.  I created snippets for the most common ones I used (5 or 6)  and then just refer to the documentation for others.

 

best wishes

Everett


  • Vince likes this

#9 Vince

Vince

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 23 posts
Reputation: 0
Neutral

Posted 05 May 2014 - 02:21 PM

Hi Everett

 

first and foremost thank you so much for your posts in this thread, you have led me into the right directions and provided some very valuable insights. I'm not new to iOS but as correctly mentioned, to STV. 

 

Your example with the actions is very helpful as I'm coming to that part actually right now. I'm working at multiple projects and the one for which I use STV is the one with the longest timeline, so it gives me more time to learn how to use STV. I have started reading about the actions in the documentation and agree, it seems like it will take some time to wrap my head around them ;)

 

Just one question, while the UITableView delegates are separate methods to implement within your controller, I'm not quite sure where I should implement your above example snippet?

 

Re snippets, great advice, will look into it and most probably use it... never had time to consider it, but in the past I used such functions constantly in Eclipse...

 

best wishes

 

Vince 



#10 Everett

Everett

    Ev

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

Posted 06 May 2014 - 01:35 PM

Hey Vince,

 

In the example above called articleList - article list is the pointer to SCArrayOfObjectsSection.  You really need to read up in the ebook, it will do a much better job explaining things than I will, but here is a quick example based on using an SCArrayOfObjectsSection.

 

a) create a section control:  SCArrayOfObjectsSection *section = [SCArrayOfObjectsSection sectionWith....];

B) add actions to the section:

     sections.cellActions.didSelect = ^(SCTableViewCell *cell, NSIndexPath *indexPath) { ); //equiv to tableView did Select delegate

  sections.cellActions.willSelect  //equiv to tableView will select delegate

 sections.cellActions.willStyle  ...

 sections.cellActions.didStyle ...

etc...

 

then once the section is setup and actions defined, you add it to the tableview (assuming SCViewController or SCTableViewController)

[self.tableViewModel addSection:section];

 

then reload if needed: 

[self.tableView reloadData];

 

STV has a very rich DSL that allows you to control the view controllers, sections and cells.  Its quite amazing really, but also quite challenging, especially at first.

 

best wishes,

Everett


  • Vince likes this

#11 Vince

Vince

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 23 posts
Reputation: 0
Neutral

Posted 08 May 2014 - 04:55 AM

Hi Everett

 

I get it now, based on your explanation and the ebook, I managed to make it work!!! great help, very much appreciated! Can you be hired ;-)

 

best wishes Vince






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users