PolyEdge / scratchapi

[CURRENTLY UNMAINTAINED] Scratch API Interface
40 stars 15 forks source link

A couple of suggestions... #1

Closed TheLogFather closed 8 years ago

TheLogFather commented 8 years ago

I've found this to be a useful framework for manipulating cloud data in projects, so thanks for that! (I hacked together some python for it myself some time back, but I was discovering and experimenting at the time, so it really ended up quite messy.)

However, there is one thing I find I'm missing - a simple wrapper to get all the cloudvars for a project (rather than getting one at a time, which ends up with a server request for each).

Was thinking perhaps something like:

....
    self.cloud.get_vars = self._cloud_getvars
....
def _cloud_getvars(self, projId):
    dt = self.lib.utils.request(path='/varserver/' + str(projId)).json()['variables']
    vardict = {}
    for x in dt:
      xn = x['name']
      if xn.startswith('☁'+chr(32)):  # want to ignore leading cloud+space chars
        vardict[xn[2:]] = x['value']
      else:  # probably can't happen? (server appears to automatically add cloud+space anyway)
        vardict[xn] = x['value']
    return vardict  # a dictionary with var names as keys

Also, maybe a couple of 'convenience' defs for the CloudSession class...?

def get_var(self, name):
    return self.scratch.cloud.get_var(name,self.projectId)

def get_vars(self):
    return self.scratch.cloud.get_vars(self.projectId)
PolyEdge commented 8 years ago

Thanks! I am implementing those. My internet very slow (0.03 mbits/sec) today, so I might be able to push the code tomorrow after testing it if my internet gets any better.

PolyEdge commented 8 years ago

Never mind, I managed to test and push some other stuff I was working as well as your cloud data additions :)

PolyEdge commented 8 years ago

Closing now that the features are added :)

TheLogFather commented 8 years ago

Great, thanks!

One other related thing I thought about...

It's not actually necessary to have a user session in order to get the cloudvars (the varserver URL works perfectly fine without being signed in - though I suppose it's an interesting question whether or not that's intended...)

So I wondered if it might be worth having a sessionless cloudvar(s) getter?