CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • API v3 compliance Case API
Pages: [1]

Author Topic: API v3 compliance Case API  (Read 1288 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
API v3 compliance Case API
February 28, 2011, 01:56:02 pm
Hi all,

One part of the code that hasn't been fully converted to APIv3 is the Case api. I didn't add the civicrm_verify_mandatory - & this is being picked up in the new APIStandardsTest. However, the Case api tests the value as well as the presence of the value

      if( !is_numeric( $caseId ) ) {

Where are we at on this sort of thing? It's done in a few API but not many. I think we should either have a helper function that manages it or eliminate it & rely on our try-catches.

Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API v3 compliance Case API
March 09, 2011, 04:07:27 am
like civicrm_api3_verify_numeric, civicrm_api3_verify_currency ?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: API v3 compliance Case API
March 09, 2011, 04:10:26 am
That sounds clever - do they exist already?

So how does it look?

Do we call
civicrm_api3_verify_mandatory($params);

& then

civicrm_api3_verify_numeric ($params,array('caseID'));
civicrm_api3_verify_currency  ($params,array('money_field'));
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: API v3 compliance Case API
March 09, 2011, 04:11:43 am
NB on verify_mandatory I changed the api v2 behaviour that told you one missing field at a time to tell you all the missing fields on your first go. Drip feeding error messages is a little cruel
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API v3 compliance Case API
March 09, 2011, 04:21:31 am
Make sense.

reminds me we still need a proper way of returning a computer readable field instead of having to string parse the error message.

eg

is_error:1,
missing_mandatory : {'id_case', 'id_contact'...}

or something along that line. Probably not need to be super smart and handling mandatory this one OR that one, just returning the list of fields is already a great help, no ?
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: API v3 compliance Case API
March 09, 2011, 04:27:24 am
Hmm. If we are going to look @ verifying fields a bit more carefully I think maybe we should tackle contribution api - since it throws up just about every possibility so if we can figure out something that works there it must work elsewhere.

Having said that I'm seeing worms & cans
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API v3 compliance Case API
March 09, 2011, 06:17:38 am
Quote from: Eileen on March 09, 2011, 04:10:26 am
That sounds clever - do they exist already?

I wrote it. It wrote the tests. I can't run any of the unit tests because php unit hates me (actually, silently ignores me). Hate I can cope with, but that a piece of code ignores me can't handle ;)

Can push when you are around later today.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: API v3 compliance Case API
March 09, 2011, 08:23:06 am

might eb easier to follow the convention we use for the DB code:

$types = array( 'caseID' => 'Positive',
                        'total_amount' => 'Money' );
civicrm_api_verify_types( $params, $types );

and reuse the code for the various checks in CRM/Utils/Type.php

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API v3 compliance Case API
March 09, 2011, 08:33:43 am
Pushing it a bit further, as we do have already that information from ->fields, We can skip the manual enumeration of fields/type and do it directly based on the DAO definition, no ?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: API v3 compliance Case API
March 09, 2011, 10:20:11 am

we know a fair amount and should do that automatically

the only edge case is for fields like email and a few others (credit card number etc) where its a text string and we dont know a lot more. maybe adding this info to the xml schema definitions is a good thing for 4.1

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API v3 compliance Case API
March 09, 2011, 12:25:20 pm

Yeap, might be worthwhile adding more info in the xml schema to cover that.

IMO a very bad idea to store CC in civicrm, but I'm assuming it was an example, not something you suggest doing ;)

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: API v3 compliance Case API
March 09, 2011, 12:57:06 pm
Quote
Pushing it a bit further, as we do have already that information from ->fields, We can skip the manual enumeration of fields/type and do it directly based on the DAO definition, no ?

There is another scenario, illustrated in the contribution api, where there are fields like 'soft_credit_id' which are not part of the main object but can be accessed through the API / BAO.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API v3 compliance Case API
March 09, 2011, 01:23:59 pm
So what about having the same signature as the verify_mandatory:
civicrm_api_verify_types ( $params,  $daoName = null, $extra = array() );


$extra = array( 'soft_credit_id' => 'Positive',
                        'extra_param_2' => 'Money' );
civicrm_api_verify_types ( $params, 'CRM_DAO_Core_Entity', $extra);

We have covered everything, no ?


X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: API v3 compliance Case API
March 09, 2011, 01:35:54 pm
I think so! There may be some cases where $extras may also need to be able to over-ride the 'natural' DAO ones - ie. I think there are some cases where integer fields accepts strings due to some fu'n'ky handling -but maybe we should worry about these when we hit them.

One thought  is that if the $extra array could be defined outside the main function then it would be easier to automate standards tests / generate tests using a tpl. (actually this was something I had been mulling in the context of the  verify_mandatory )

Looking at the contribution api - there are a couple of id fields it validates (contact_id, contribution_type_id)
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • API v3 compliance Case API

This forum was archived on 2017-11-26.