ahmader / node-zoho

Zoho API access for NodeJS
21 stars 15 forks source link

Initial implementation of the uploadFile method for Leads #5

Closed chemerisuk closed 10 years ago

chemerisuk commented 10 years ago

Hi again,

I had a task related to uploading a file to Zoho, so decided to implement it. The new method has 4 input arguments. The argument descriptor supports properties below (see https://github.com/felixge/node-form-data#alternative-submission-methods):

{
    filename: 'unicycle.jpg',
    contentType: 'image/jpg',
    knownLength: 19806
  }

No specs yet, please review if it makes sense.


Thanks, Maksim

interlock commented 10 years ago

We will need a spec for this as well. Are you doing the integration tests suite as well? I can help you set that up to test this flow if you like.

How similar is this to the uploadPhoto for Leads and Contacts? May be able to make this even more generic for use with those as well.

I assume this code would work for all CRM modules, so you may as well move it down to CrmModule (new as of yesterday for common implementations between modules for CRM) and we get it for free for the other implemented modules.

chemerisuk commented 10 years ago

While uploadFile and uploadPhoto look similar they have completely different format of response.

for uploadFile:

<?xml version="1.0" encoding="UTF-8" ?>
<response uri="/crm/private/xml/Leads/uploadFile">
      <result>
            <message>File has been attached successfully</message>
            <recorddetail>
                  <FL val="Id">335751000000578001</FL>
                  <FL val="Created Time">2012-06-20 14:57:34</FL>
                  <FL val="Modified Time">2012-06-20 14:57:34</FL>
                  <FL val="Created By"><![CDATA[krrish]]></FL>
                  <FL val="Modified By"><![CDATA[krrish]]></FL>
            </recorddetail>
      </result>
</response>

for uploadPhoto:

<?xml version="1.0" encoding="UTF-8" ?>
<response uri="/crm/private/xml/Leads/uploadPhoto">
<status>
<code>200</code>
</status>
<success>
<code>4800</code>
<message>Photo uploaded succuessfully</message>
</success>
</response>

Also not all entities support uploadFile operation. For instance Notes does not. I guess we need a [non-public] helper method to encapsulate common logic.

interlock commented 10 years ago

Well that is not entirely unexpected from Zoho API... Can you add a spec test for the leads implementation and we will make an issue to follow up with a private function to deal with this.

chemerisuk commented 10 years ago

The specs were added

interlock commented 10 years ago

Thanks. Pushed to NPM as well.