milesrichardson / ParsePy

A relatively up-to-date fork of ParsePy, the Python wrapper for the Parse.com API. Originally maintained by @dgrtwo
MIT License
516 stars 184 forks source link

X-Parse-Session-Token support ? #74

Closed theho closed 7 years ago

theho commented 10 years ago

Any plans for supporting something similar to Parse.become ?

Am thinking something like,

register(APPLICATION_ID, REST_API_KEY, master_key=None, session_token='')

Then all subsequent requests would be by whichever user the token belongs to.

I suppose ultimately, would like to have

with sessionToken('token123'): Appointment.Query.all() ...

theho commented 10 years ago

A quick two-line 'hack' in connection.py, line 92

    if ACCESS_KEYS.get('session_token'):
        headers.update({'X-Parse-Session-Token': ACCESS_KEYS.get('session_token')})

in my code: class sessionToken: def init(self, token): self.token = token def enter(self): parse_rest.connection.ACCESS_KEYS.update({'session_token': self.token}) def exit(self, type, value, traceback): del parse_rest.connection.ACCESS_KEYS['session_token']

with sessionToken('abcdef'): x = Appointment.Query.all().limit(5) for p in x: print(p)