Device Magic API Wrapper
Project description
pydevice
Device Magic API Wrapper
Currently supports:
- Device Magic Database
- Destinations
- Devices
- Forms
- Resources
- Groups
- Dispatch
Installation
pip install pydevice
Usage
>>> from pydevice import DeviceMagic
>>> args = {'org_id': 3000,'database_id': 580, 'form_id': 6000, 'resource_id': 103, 'file_path': 'path/to/file', 'device_identifier': 'Android_d5c2a885'}
>>> dm = DeviceMagic(args)
>>> dm.form.all() # destination, device, resource, group, and dispatch also have this method
{'forms': [{'id': 40015631, 'name': 'Daily Report'...}
Authentication
Authentication is handled by the DeviceMagic class. The class can handle authentication automatically if the environment variable DEVICEMAGIC_API_KEY is set with your api key.
>>> dm = DeviceMagic(args)
In preference, you can pass the key explicitly:
>>> dm = DeviceMagic({'api_key': 'HTTP_Auth_Header_Value'})
Database
>>> dm.database.json()
{'per_page': 30, 'current_page': 1, 'total_pages': 1, 'current_count': 13, 'total_count': 13, 'submissions': [{'form'...
>>> dm.database.json("from_date=2018-5-1 00:00", "to_date=2018-5-31 00:00")
{...'total_count': 1, 'submissions': [{'form': {'id': 6009105, 'name': 'Sales Report'...}
Destination
>>> dm.destination.copy(26754)
'Destination created'
Optionally you can pass the id of a different form in which you'd like to copy the destination to.
>>> dm.destination.copy(26754, form_id=4008185)
Device
>>> dm.device.approve(2801)
'Device approved'
Form
>>> dm.form.details(3005)
{'type': 'root', 'children': [{'identifier': 'Yes_No_Question', 'title': 'Yes/No Question', 'autoIdentifier': True, 'type': 'boolean'}, {'identifier': 'Date_Question', 'title': 'Date Question', 'autoIdentifier': True, 'type': 'date'}...}
Resource
>>> dm.resource.update(480,'client_list', 'client_list.xlsx')
'Resource updated'
Group
>>> dm.group.delete(615)
'Group deleted'
Dispatch
>>> import json
>>> dispatch_json = { "form_namespace" : "http://www.devicemagic.com/xforms/4c0a6400-ef90-8283-8586-22000a1ddaf9",
"payload" : {
"Group" : []
}
}
>>> dispatch_json = json.dumps(dispatch_json)
>>> dm.dispatch.push(dispatch_json)
'Dispatch successful'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pydevice-0.1.2.tar.gz
(4.9 kB
view hashes)
Built Distribution
pydevice-0.1.2-py3-none-any.whl
(12.2 kB
view hashes)