Commit 3f7bf7ca authored by ryanss's avatar ryanss
Browse files

Start adding documentation to README, add LICENSE

parent 1b332ada
Copyright (c) 2014 <ryanssdev@icloud.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
......@@ -2,7 +2,7 @@
SugarCRM
========
Simple Python client for SugarCRM API.
Python client for SugarCRM API.
Example Usage
......@@ -13,6 +13,7 @@ Example Usage
import sugarcrm
# Connect
url = "http://your-sugarcrm-domain/service/v4/rest.php"
sugar = sugarcrm.API(url, username, password)
# Create a new note
......@@ -43,3 +44,130 @@ Example Usage
op.id = "82f72939-735e-53a2-0944-5418c4edae2a"
op.sales_stage = "Approved"
sugar.set_entry(op)
Install
-------
The latest stable version can always be installed or updated via pip:
.. code-block:: bash
$ pip install sugarcrm
If the above fails, please use easy_install instead:
.. code-block:: bash
$ easy_install sugarcrm
SugarCRM Objects
----------------
.. code-block:: python
>>> contact = sugarcrm.Contact()
>>> print contact.module
"Contacts"
>>> note = sugarcrm.Note()
>>> print note.module
"Notes"
>>> opportunity = sugarcrm.Opportunity()
>>> print opportunity.module
"Opportunities"
API Object
----------
class sugarcrm.API(url, username, password)
The main class used to connect to the SugarCRM API and make quests with.
.. code-block:: python
url = "http://your-sugarcrm-domain/service/v4/rest.php"
sugar = sugarcrm.API(url, username, password)
API Methods
-----------
sugar.get_entry(module, id, track_view=False)
.. code-block:: python
note = sugar.get_entry("Notes", "f0c78aab-e051-174a-12aa-5439a7146977")
print note.name
sugar.get_entries(module, ids, track_view=False)
.. code-block:: python
ids = [
"f0c78aab-e051-174a-12aa-5439a7146977",
"32f02fj2-4ggn-4nnf-fs33-f3fh3f93n333",
"82f72939-735e-53a2-0944-5418c4edae2a",
]
notes = sugar.get_entries("Notes", ids)
for note in notes:
print note.name
sugar.get_entry_list(query_object)
.. code-block:: python
# Get a list of all notes with a name that begins with "Test"
nq = sugarcrm.Note()
note.name = "Test%"
notes = sugar.get_entry_list(nq)
for note in notes:
print note.name
sugar.set_entry(obj)
.. code-block:: python
note = sugarcrm.Note()
note.name = "Test Note"
sugar.set_entry(note)
print note.id
sugar.set_note_attachment(note, f)
.. code-block:: python
with open("test1.pdf") as pdf_file:
sugar.set_note_attachment(note1, pdf_file)
sugar.set_note_attachment(note2, "test2.pdf")
print note1.filename, note2.filename
Development Version
-------------------
The latest development version can be installed directly from GitHub:
.. code-block:: bash
$ pip install --upgrade https://github.com/ryanss/sugarcrm/tarball/master
Contributions
-------------
.. _issues: https://github.com/ryanss/sugarcrm/issues
.. __: https://github.com/ryanss/sugarcrm/pulls
Issues_ and `Pull Requests`__ are always welcome.
License
-------
.. __: https://github.com/ryanss/sugarcrm/raw/master/LICENSE
Code and documentation are available according to the MIT License
(see LICENSE__).
# SugarCRM
# --------
# Python client for SugarCRM API.
#
# Author: ryanss <ryanssdev@icloud.com>
# Website: https://github.com/ryanss/sugarcrm
# License: MIT (see LICENSE file)
__version__ = '0.1-dev'
import base64
import hashlib
import json
......@@ -33,7 +44,7 @@ class API:
data = [self.session_id, module, id, [], [], track_view]
result = self.request('get_entry', data)['entry_list'][0]
obj = SugarObject()
obj.type = module
obj.module = module
for key in result['name_value_list']:
setattr(obj, key, result['name_value_list'][key]['value'])
return obj
......@@ -46,26 +57,26 @@ class API:
ret = []
for result in results:
obj = SugarObject()
obj.type = module
obj.module = module
for key in result['name_value_list']:
setattr(obj, key, result['name_value_list'][key]['value'])
ret.append(obj)
return ret
def get_entry_list(self, q):
data = [self.session_id, q.type, q.query, "", 0, [], [], 0, 0, False]
data = [self.session_id, q.module, q.query, "", 0, [], [], 0, 0, False]
results = self.request('get_entry_list', data)['entry_list']
ret = []
for result in results:
obj = SugarObject()
obj.type = q.type
obj.module = q.module
for key in result['name_value_list']:
setattr(obj, key, result['name_value_list'][key]['value'])
ret.append(obj)
return ret
def set_entry(self, obj):
data = [self.session_id, obj.type, obj.fields]
data = [self.session_id, obj.module, obj.fields]
result = self.request('set_entry', data)
obj.id = result['id']
return obj
......@@ -108,22 +119,22 @@ class SugarObject:
if q:
q += "AND "
if value.find('%') >= 0:
q += "%s.%s LIKE '%s' " % (self.type.lower(), key, str(value))
q += "%s.%s LIKE '%s' " % (self.module.lower(), key, str(value))
else:
q += "%s.%s='%s' " % (self.type.lower(), key, str(value))
q += "%s.%s='%s' " % (self.module.lower(), key, str(value))
return q
class Contact(SugarObject):
type = "Contacts"
module = "Contacts"
class Opportunity(SugarObject):
type = "Opportunities"
module = "Opportunities"
class Note(SugarObject):
type = "Notes"
module = "Notes"
class SugarError(Exception):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment