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

Use url encoding on part id #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 6 additions & 5 deletions onshape_to_robot/onshape_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
import os
import json
import hashlib
import urllib.parse
from pathlib import Path

def escape_slash(s):
return s.replace('/', '%2f')
def urlencode(s):
return urllib.parse.quote(s)

class Client():
'''
Expand Down Expand Up @@ -338,18 +339,18 @@ def invoke():
req_headers = {
'Accept': '*/*'
}
return self._api.request('get', '/api/parts/d/' + did + '/m/' + mid + '/e/' + eid + '/partid/'+escape_slash(partid)+'/stl', query={'mode': 'binary', 'units': 'meter', 'configuration': configuration}, headers=req_headers)
return self._api.request('get', '/api/parts/d/' + did + '/m/' + mid + '/e/' + eid + '/partid/'+urlencode(partid)+'/stl', query={'mode': 'binary', 'units': 'meter', 'configuration': configuration}, headers=req_headers)

return self.cache_get('part_stl', (did, mid, eid, self.hash_partid(partid), configuration), invoke)

def part_get_metadata(self, did, mid, eid, partid, configuration = 'default'):
def invoke():
return self._api.request('get', '/api/metadata/d/' + did + '/m/' + mid + '/e/' + eid + '/p/'+escape_slash(partid), query={'configuration': configuration})
return self._api.request('get', '/api/metadata/d/' + did + '/m/' + mid + '/e/' + eid + '/p/'+urlencode(partid), query={'configuration': configuration})

return json.loads(self.cache_get('metadata', (did, mid, eid, self.hash_partid(partid), configuration), invoke, True))

def part_mass_properties(self, did, mid, eid, partid, configuration = 'default'):
def invoke():
return self._api.request('get', '/api/parts/d/' + did + '/m/' + mid + '/e/' + eid + '/partid/'+escape_slash(partid)+'/massproperties', query={'configuration': configuration, 'useMassPropertyOverrides': True})
return self._api.request('get', '/api/parts/d/' + did + '/m/' + mid + '/e/' + eid + '/partid/'+urlencode(partid)+'/massproperties', query={'configuration': configuration, 'useMassPropertyOverrides': True})

return json.loads(self.cache_get('massproperties', (did, mid, eid, self.hash_partid(partid), configuration), invoke, True))