コード例 #1
0
ファイル: wiggle.py プロジェクト: tim-tang/pyfi
 def post(self, resource, body):
     conn = self.conn()
     if isinstance(resource, str):
         resource = [resource]
     url = self._apiEndpoint + '/'.join(resource)
     jbody = json.dumps(body)
     vprint('POST', url, jbody, self.headers)
     curlprint(self.host, 'POST', url, headers=self.headers, data=jbody)
     conn.request('POST', url, jbody, self.headers)
     response = conn.getresponse()
     vprint('Status: ', response.status)
     if (response.status == 303):
         newurl = response.getheader('Location')
         conn = self.conn()
         conn.request('GET', newurl, '', self.headers)
         response = conn.getresponse()
         if (response.status != 200):
             print response.status
             return False
         else:
             return json.loads(response.read())
     elif (response.status == 200):
         return json.loads(response.read())
     else:
         print response.status
         return False
コード例 #2
0
ファイル: wiggle.py プロジェクト: tim-tang/pyfi
 def post_bindata(self, resource, entity, sfile, headers=None):
     conn = self.conn()
     if isinstance(resource, str):
         resource = [resource]
     url = self._apiEndpoint + '/'.join(resource) + '/' + entity
     hdrs = headers or self.headers
     vprint('POST', url, '@' + sfile.name, hdrs)
     curlprint(self.host, 'POST', url, headers=hdrs, file=sfile.name, fileMode='binary')
     conn.request('POST', url, sfile, hdrs)
     response = conn.getresponse()
     vprint('Status: ', response.status)
     if (response.status == 303):
         newurl = response.getheader('Location')
         conn = self.conn()
         conn.request('GET', newurl, '', self.headers)
         response = conn.getresponse()
         if (response.status != 200):
             print response.status
             return False
         else:
             return json.loads(response.read())
     elif (response.status == 200):
         return json.loads(response.read())
     else:
         print response.status
         return False
コード例 #3
0
ファイル: wiggle.py プロジェクト: tim-tang/pyfi
 def delete(self, resource, entity):
     conn = self.conn()
     vprint('DELETE', self._apiEndpoint + resource + '/' + entity, '', self.headers)
     curlprint(self.host, 'DELETE', self._apiEndpoint + resource + '/' + entity, self.headers)
     conn.request('DELETE', self._apiEndpoint + resource + '/' + entity, '', self.headers)
     response = conn.getresponse()
     vprint('Status: ', response.status)
     if (response.status >= 200 and response.status < 300):
         return True
     else:
         return False
コード例 #4
0
ファイル: wiggle.py プロジェクト: tim-tang/pyfi
 def list(self, resource):
     conn = self.conn()
     vprint('GET', self._apiEndpoint + resource, '', self.headers)
     curlprint(self.host, 'GET', self._apiEndpoint + resource, headers=self.headers)
     conn.request('GET', self._apiEndpoint + resource, '', self.headers)
     response = conn.getresponse()
     vprint('Status: ', response.status)
     if (response.status != 200):
         return False
     else:
         return json.loads(response.read())
コード例 #5
0
ファイル: wiggle.py プロジェクト: tim-tang/pyfi
 def delete_body(self, resource, entity, body):
     conn = self.conn()
     jbody = json.dumps(body)
     vprint('DELETE', self._apiEndpoint + resource + '/' + entity, jbody, self.headers)
     curlprint(self.host, 'DELETE', self._apiEndpoint + resource + '/' + entity, headers=self.headers, data=jbody)
     conn.request('DELETE', self._apiEndpoint + resource + '/' + entity, jbody, self.headers)
     response = conn.getresponse()
     vprint('Status: ', response.status)
     if (response.status >= 200 and response.status < 300):
         return True
     else:
         return False
コード例 #6
0
ファイル: wiggle.py プロジェクト: tim-tang/pyfi
 def delete_attr(self, resource, entity, attr):
     conn = self.conn()
     if isinstance(attr, str):
         attr = [attr]
     url = self._apiEndpoint + resource + '/' + entity + '/' + '/'.join(attr)
     vprint('DELETE', url, '', self.headers)
     curlprint(self.host, 'DELETE', url, headers=self.headers)
     conn.request('DELETE', url, '', self.headers)
     response = conn.getresponse()
     vprint('Status: ', response.status)
     if (response.status < 300 and response.status >= 300):
         return False
     else:
         return True
コード例 #7
0
ファイル: wiggle.py プロジェクト: tim-tang/pyfi
 def get_attr(self, resource, entity, attr):
     conn = self.conn()
     if isinstance(attr, str):
         attr = [attr]
     url = self._apiEndpoint + resource + '/' + entity + '/' + '/'.join(attr)
     vprint('GET', url, '', self.headers)
     curlprint(self.host, 'GET', url, headers=self.headers)
     conn.request('GET', url, '', self.headers)
     response = conn.getresponse()
     vprint('Status: ', response.status)
     if (response.status != 200):
         return False
     else:
         return json.loads(response.read())
コード例 #8
0
ファイル: wiggle.py プロジェクト: tim-tang/pyfi
 def get(self, resource, entity, suffix='', rawResponse=False, headers=None):
     conn = self.conn()
     hdrs = headers or self.headers
     vprint('GET', self._apiEndpoint + resource + '/' + entity + suffix, '', hdrs)
     curlprint(self.host, 'GET', self._apiEndpoint + resource + '/' + entity + suffix, hdrs)
     conn.request('GET', self._apiEndpoint + resource + '/' + entity + suffix, '', hdrs)
     response = conn.getresponse()
     vprint('Status: ', response.status)
     if (response.status != 200):
         return False
     else:
         if rawResponse:
             return response
         else:
             return json.loads(response.read())
コード例 #9
0
ファイル: wiggle.py プロジェクト: tim-tang/pyfi
 def full_list(self, resource, fields):
     conn = self.conn()
     hdrs = self.headers
     params = '?full-list=true'
     if fields != []:
         params = params + '&full-list-fields=' + ','.join(fields)
     vprint('GET', self._apiEndpoint + resource, '', hdrs)
     url = self._apiEndpoint + resource + params
     curlprint(self.host, 'GET', url, headers=hdrs)
     conn.request('GET', url, '', hdrs)
     response = conn.getresponse()
     vprint('Status: ', response.status)
     if (response.status != 200):
         return False
     else:
         return json.loads(response.read())
コード例 #10
0
ファイル: wiggle.py プロジェクト: tim-tang/pyfi
 def put_bindata(self, resource, entity, target, suffix='', headers=None):
     conn = self.conn()
     if isinstance(entity, str):
         entity = [entity]
     url = self._apiEndpoint + resource + '/' + '/'.join(entity) + suffix
     hdrs = headers or self.headers
     vprint('PUT', url, '@' + target.name, hdrs)
     curlprint(self.host, 'PUT', url, headers=hdrs, upload=target.name)
     conn.request('PUT', url, target, hdrs)
     response = conn.getresponse()
     vprint('Status: ', response.status)
     if (response.status > 200 and response.status > 200):
         return response.status
     if (response.status != 200):
         return False
     else:
         return json.loads(response.read())
コード例 #11
0
ファイル: wiggle.py プロジェクト: tim-tang/pyfi
 def put(self, resource, entity, body):
     conn = self.conn()
     if isinstance(entity, str):
         entity = [entity]
     url = self._apiEndpoint + resource + '/' + '/'.join(entity)
     jbody = json.dumps(body)
     vprint('PUT', url, jbody, self.headers)
     curlprint(self.host, 'PUT', url, headers=self.headers, data=jbody)
     conn.request('PUT', url, jbody, self.headers)
     response = conn.getresponse()
     vprint('Status: ', response.status)
     if (response.status == 201): # This was added for dryrun. Add body?
         return True
     if (response.status != 200):
         return False
     else:
         return json.loads(response.read())
コード例 #12
0
ファイル: wiggle.py プロジェクト: tim-tang/pyfi
 def put_attr(self, resource, entity, attr, body):
     conn = self.conn()
     if isinstance(attr, str):
         attr = [attr]
     jbody = json.dumps(body)
     url = self._apiEndpoint + resource + '/' + entity + '/' + '/'.join(attr)
     vprint('PUT', url, jbody, self.headers)
     curlprint(self.host, 'PUT', url, headers=self.headers, data=jbody)
     conn.request('PUT', url, jbody, self.headers)
     response = conn.getresponse()
     vprint('Status: ', response.status)
     if response.status == 200:
         return json.loads(response.read())
     elif (response.status > 200 and response.status < 400):
         print response.status
         return True
     else:
         return False
コード例 #13
0
ファイル: wiggle.py プロジェクト: tim-tang/pyfi
 def connect(self, user, pw):
     conn = self.conn()
     if self._apiVersion == '0.1.0':
         print "the 0.1.0 API is no longer supported!"
         exit(1)
     else:
         form = urllib.urlencode({'username' :user, 'password': pw, 'grant_type': 'password'})
         url = self._apiEndpoint + 'oauth/token'
         headers = copy.copy(self.headers)
         headers['content-type'] = 'application/x-www-form-urlencoded'
         vprint('POST', url, form, self.headers)
         curlprint(self.host, 'POST', url, headers=self.headers, data=form)
         conn.request('POST', url, form, self.headers)
         response = conn.getresponse()
         vprint('Status:', response.status)
         if (response.status == 200):
             resp = json.loads(response.read())
             self._token = resp['access_token']
             self.headers['authorization'] = 'Bearer ' + self._token
             return self._token
         else:
             return False
コード例 #14
0
ファイル: wiggle.py プロジェクト: tim-tang/pyfi
 def post_attr(self, resource, entity, attr, body):
     conn = self.conn()
     if isinstance(attr, str):
         attr = [attr]
     url = self._apiEndpoint + resource + '/' + entity + '/' + '/'.join(attr)
     jbody = json.dumps(body)
     vprint('POST', url, jbody, self.headers)
     curlprint(self.host, 'POST', url, headers=self.headers, data=jbody)
     conn.request('POST', url, jbody, self.headers)
     response = conn.getresponse()
     vprint('Status: ', response.status)
     if (response.status == 303):
         newurl = response.getheader('Location')
         conn = self.conn()
         conn.request('GET', newurl, '', self.headers)
         response = conn.getresponse()
         vprint('Status (after redirect): ', response.status)
         if (response.status == 404):
             time.sleep(5)
             conn = self.conn()
             conn.request('GET', newurl, '', self.headers)
             response = conn.getresponse()
             vprint('Status (after reload): ', response.status)
             if (response.status != 200):
                 return False
             else:
                 return json.loads(response.read())
         elif (response.status != 200):
             return False
         else:
             return json.loads(response.read())
     elif (response.status == 201):
         return 201
     elif (response.status == 200):
         return json.loads(response.read())
     else:
         return False