glpi-api 0.3.5__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,17 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: glpi-api
3
- Version: 0.3.5
3
+ Version: 0.5.0
4
4
  Summary: Wrap calls to GLPI REST API.
5
5
  Home-page: https://github.com/unistra/python-glpi-api
6
6
  Author: François Ménabé
7
- Author-email: francois.menabe@unistra.fr
7
+ Author-email: francois.menabe@gmail.fr
8
8
  License: GPLv3+
9
9
  Keywords: rest,api,glpi
10
10
  Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
11
11
  Classifier: Development Status :: 5 - Production/Stable
12
12
  Classifier: Programming Language :: Python :: 3
13
13
  License-File: LICENSE
14
+ Requires-Dist: requests
14
15
 
15
16
  ********
16
17
  glpi-api
@@ -1,16 +1,17 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: glpi-api
3
- Version: 0.3.5
3
+ Version: 0.5.0
4
4
  Summary: Wrap calls to GLPI REST API.
5
5
  Home-page: https://github.com/unistra/python-glpi-api
6
6
  Author: François Ménabé
7
- Author-email: francois.menabe@unistra.fr
7
+ Author-email: francois.menabe@gmail.fr
8
8
  License: GPLv3+
9
9
  Keywords: rest,api,glpi
10
10
  Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
11
11
  Classifier: Development Status :: 5 - Production/Stable
12
12
  Classifier: Programming Language :: Python :: 3
13
13
  License-File: LICENSE
14
+ Requires-Dist: requests
14
15
 
15
16
  ********
16
17
  glpi-api
@@ -435,6 +435,17 @@ class GLPI:
435
435
  404: lambda r: None
436
436
  }.get(response.status_code, _unknown_error)(response)
437
437
 
438
+ def _add_searchtext(self, searchText):
439
+ '''
440
+ Generate searchText parameter.
441
+ '''
442
+ if not isinstance(searchText, dict):
443
+ raise GLPIError(
444
+ 'search text should be a dict, found: {:s}'.format(str(type(searchText)))
445
+ )
446
+
447
+ return {'searchText[{:s}]'.format(k): v for k, v in searchText.items()}
448
+
438
449
  @_catch_errors
439
450
  def get_all_items(self, itemtype, **kwargs):
440
451
  """`API documentation
@@ -454,7 +465,11 @@ class GLPI:
454
465
  # Retrieve deleted computers.
455
466
  >>> glpi.get_all_items('Computer', is_deleted=True)
456
467
  []
468
+ # Using searchText.
469
+ >>> glpi.get_all_items('Computer', searchText={'name':'server'})
470
+ []
457
471
  """
472
+ kwargs.update(self._add_searchtext(kwargs.pop('searchText', {})))
458
473
  response = self.session.get(self._set_method(itemtype),
459
474
  params=_convert_bools(kwargs))
460
475
  return {
@@ -713,6 +728,35 @@ class GLPI:
713
728
  400: _glpi_error,
714
729
  401: _glpi_error
715
730
  }.get(response.status_code, _unknown_error)(response)
731
+
732
+ @_catch_errors
733
+ def add_sub_items(self, itemtype, item_id, sub_itemtype, *items):
734
+ """`API documentation
735
+ Same method used as get-sub-items, same parameter
736
+ <https://github.com/glpi-project/glpi/blob/master/apirest.md#get-sub-items>`__
737
+
738
+ Add a collection of rows of the ``sub_itemtype`` for the identified
739
+ item of type ``itemtype`` and id ``item_id``. ``kwargs`` contains
740
+ additional parameters allowed by the API.
741
+
742
+ .. code::
743
+
744
+ # Add a operatingsystem of a computer.
745
+ >>> In [241]: glpi.add_sub_items('Computer',1,'Item_OperatingSystem',{'items_id': 1 ,'itemtype':'Computer','operatingsystems_id':1 })
746
+ [{'id': 261,
747
+ 'itemtype': 'Computer',
748
+ 'items_id': 1,
749
+ ...
750
+ """
751
+ url = self._set_method(itemtype, item_id, sub_itemtype)
752
+ response = self.session.post(url,
753
+ json={'input': items})
754
+ return {
755
+ 201: lambda r: r.json(),
756
+ 207: lambda r: r.json()[1],
757
+ 400: _glpi_error,
758
+ 401: _glpi_error
759
+ }.get(response.status_code, _unknown_error)(response)
716
760
 
717
761
  @_catch_errors
718
762
  def update(self, itemtype, *items):
@@ -734,10 +778,41 @@ class GLPI:
734
778
  json={'input': items})
735
779
  return {
736
780
  200: lambda r: r.json(),
781
+ 201: lambda r: r.json(),
737
782
  207: lambda r: r.json()[1],
738
783
  400: _glpi_error,
739
784
  401: _glpi_error
740
785
  }.get(response.status_code, _unknown_error)(response)
786
+
787
+ @_catch_errors
788
+ def update_sub_items(self, itemtype, item_id, sub_itemtype, *items):
789
+ """`API documentation
790
+ Same method used as get-sub-items, same parameters
791
+ <https://github.com/glpi-project/glpi/blob/master/apirest.md#get-sub-items>`__
792
+
793
+ Updates a collection of rows of the ``sub_itemtype`` for the identified
794
+ item of type ``itemtype`` and id ``item_id``. ``kwargs`` contains
795
+ additional parameters allowed by the API.
796
+
797
+ .. code::
798
+
799
+ # update the operatingsystem a computer.
800
+ >>> In [241]: glpi.update_sub_items('Computer',1,'Item_OperatingSystem' {'id': 1 ,'itemtype':'Computer','operatingsystem_id':1 })
801
+ [{'id': 261,
802
+ 'itemtype': 'Computer',
803
+ 'items_id': 1,
804
+ ...
805
+ """
806
+ url = self._set_method(itemtype, item_id, sub_itemtype)
807
+ response = self.session.put(url,
808
+ json={'input': items})
809
+ return {
810
+ 200: lambda r: r.json(),
811
+ 201: lambda r: r.json(),
812
+ 207: lambda r: r.json(),
813
+ 400: _glpi_error,
814
+ 401: _glpi_error
815
+ }.get(response.status_code, _unknown_error)(response)
741
816
 
742
817
  @_catch_errors
743
818
  def delete(self, itemtype, *items, **kwargs):
@@ -768,6 +843,37 @@ class GLPI:
768
843
  400: lambda r: _glpi_error(r) if r.json()[0] != 'ERROR_GLPI_DELETE' else r.json()[1],
769
844
  401: _glpi_error
770
845
  }.get(response.status_code, _unknown_error)(response)
846
+
847
+ @_catch_errors
848
+ def delete_sub_items(self, itemtype, item_id, sub_itemtype, *items):
849
+ """`API documentation
850
+ Same method used as get-sub-items, same parameters
851
+ <https://github.com/glpi-project/glpi/blob/master/apirest.md#get-sub-items>`__
852
+
853
+ deletes a collection of rows of the ``sub_itemtype`` for the identified
854
+ item of type ``itemtype`` and id ``item_id``. ``kwargs`` contains
855
+ additional parameters allowed by the API.
856
+
857
+ .. code::
858
+
859
+ # delete the operatingsystem a computer.
860
+ >>> In [241]: glpi.delete_sub_items('Computer',1,'Item_OperatingSystem' {'id': 1 ,'itemtype':'Computer','operatingsystem_id':1 })
861
+ [{'id': 261,
862
+ 'itemtype': 'Computer',
863
+ 'items_id': 1,
864
+ ...
865
+ """
866
+ url = self._set_method(itemtype, item_id, sub_itemtype)
867
+ response = self.session.delete(url,
868
+ json={'input': items})
869
+ return {
870
+ 200: lambda r: r.json(),
871
+ 204: lambda r: r.json(),
872
+ 207: lambda r: r.json()[1],
873
+ 400: lambda r: _glpi_error(r) if r.json()[0] != 'ERROR_GLPI_DELETE' else r.json()[1],
874
+ 401: _glpi_error
875
+ }.get(response.status_code, _unknown_error)(response)
876
+
771
877
 
772
878
  @_catch_errors
773
879
  def upload_document(self, name, filepath):
@@ -4,9 +4,9 @@ from setuptools import setup
4
4
 
5
5
  setup(
6
6
  name='glpi-api',
7
- version='0.3.5',
7
+ version='0.5.0',
8
8
  author='François Ménabé',
9
- author_email='francois.menabe@unistra.fr',
9
+ author_email='francois.menabe@gmail.fr',
10
10
  url='https://github.com/unistra/python-glpi-api',
11
11
  license='GPLv3+',
12
12
  description='Wrap calls to GLPI REST API.',
File without changes
File without changes
File without changes