Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated name for pip and worker functions for file.get and file.put #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions TR50/TR50httpWorker.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,66 @@ def email_send(self, email_to, email_from, email_subject, email_body):
result = self.execute("email.send", params)
return (result == True and self.response["data"]["success"])

# file.put : Reserves a file handle to be used to upload a file via HTTP POST
# @param string file_name The name of the file to be uploaded to the platform.
# @param string thing_key The Thing that the file will be attached to.
# @param bool global_file If set to true, the file will be a global file and the thingKey parameter will be ignored. Defaults to false.
# @param bool public If true, identifies the file as publicly accessible outside of the organization. If false, the file is private to the organization. Defaults to false.
# @param int crc32 A IEEE CRC32 checksum of the file to be uploaded. When the file is subsequently sent via the HTTP interface, the checksum will be validated, and if incorrect, the file will be discarded an an error returned.
# @param mixed tags A list of tags to associate to the file.
# @param mixed sec_tags A list of tags to specify security access to the file.
# @param int ttl Specify an expect ttl (in seconds) for a file. If a file is uploaded partially and a ttl is set, partial file will be deleted after elapsed time.
# @param bool log_complete If set to true, creates an event log entry when the file upload is complete.
# @return mixed Returns a dict with the fileId or the failure code
def file_put(self, file_name, thing_key, global_file, public, crc32, tags, sec_tags, ttl, log_complete):
"""This command reserves a file handle to be used to upload a file via HTTP POST"""
params = { "fileName" : file_name, "global" : global_file}
if global_file == False:
params["thingKey"] = thing_key

if public:
params["public"] = public

if type(tags) is list:
params["tags"] = tags
else:
params["tags"] = [ tags ]

if type(sec_tags) is list:
params["secTags"] = sec_tags
else:
params["secTags"] = [ sec_tags ]

if log_complete:
params["logComplete"] = log_complete

if crc32 != False:
params["crc32"] = crc32

if ttl != False:
params["ttl"] = ttl

result = self.execute("file.put", params)
if result == True and self.response["data"]["success"] == True:
return self.response["data"]["params"]
else:
return self.response["data"]["success"]

# file.get : Reserves a file handle for a given file to be obtained via HTTP GET
# @param string file_name The name of the file to be retrieved from the M2M Service.
# @param string thing_key The Thing associated with the file. Defaults to the current session's Thing.
# @param bool global_file If set to true, the file is a global file and the thingKey parameter will be ignored.
# @return mixed Returns a dict with the fileId, fileSize and rcr32 or the failure code
def file_get(self, file_name, thing_key, global_file):
"""This command reserves a file handle for a given file to be obtained via HTTP GET"""
params = { "fileName" : file_name, "global" : global_file }
if global_file == False:
params["thingKey"] = thing_key
result = self.execute("file.get", params)
if result == True and self.response["data"]["success"] == True:
return self.response["data"]["params"]
else:
return self.response["data"]["success"]

# locale.get : This command is used to retrieve the current session's locale.
# @return mixed Returns the dict of the session's locale on success, or the failure code.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from distutils.core import setup

config = {
'name' :'TR500HTTP',
'name' :'devicewise',
'version':'1.0',
'description' : 'Sample code for communicating with the Telit IoT Platform via Python.',
'author' : 'Telit',
Expand Down