Exemplo n.º 1
0
 def execute(self) -> Optional[JsonType]:
     params = {}
     headers = {
         "X-Access-Token": self.gmi.access_token,
         "User-Agent": "GroupYouLibrary/1.0",
     }
     args = self.args()
     if self.mode() == "GET" and isinstance(args, dict):
         params.update(args)
         r = requests.get(url=self.url(), params=params, headers=headers)
     elif self.mode() == "POST" and isinstance(args, dict):
         headers["Content-Type"] = "application/json"
         r = requests.post(
             url=self.url(),
             params=params,
             headers=headers,
             data=json.dumps(self.args()),
         )
     elif self.mode() == "POST_RAW" and isinstance(args, bytes):
         r = requests.post(
             url=self.url(), params=params, headers=headers, data=self.args()
         )
     else:
         raise InvalidOperationException()
     self.error_check(r)
     if r.content.decode("utf-8").isspace():
         return None
     else:
         return self.extract_response(r)
Exemplo n.º 2
0
 def execute(self):
     params = {}
     headers = {
         'X-Access-Token': self.gmi.access_token,
         'User-Agent': 'GroupYouLibrary/1.0'
     }
     if self.mode() == "GET":
         params.update(self.args())
         r = requests.get(url=self.url(), params=params, headers=headers)
     elif self.mode() == "POST":
         headers['Content-Type'] = 'application/json'
         r = requests.post(url=self.url(),
                           params=params,
                           headers=headers,
                           data=json.dumps(self.args()))
     elif self.mode() == "POST_RAW":
         r = requests.post(url=self.url(),
                           params=params,
                           headers=headers,
                           data=self.args())
     else:
         raise InvalidOperationException()
     self.error_check(r)
     if r.content.decode('utf-8').isspace():
         return None
     else:
         return r.json()["response"]
Exemplo n.º 3
0
 def refresh(self):
     if self.group_id is None:
         raise InvalidOperationException(
             'Must have an id to perform this operation')
     else:
         new_data = GroupsShowRequest(self.gmi,
                                      group_id=self.group_id).result
         self._refresh_from_other(new_data)
Exemplo n.º 4
0
 def refresh(self):
     if self.message_id:
         new_data = MessagesShowRequest(self.gmi, self.group_id,
                                        self.message_id).result
         self._refresh_from_other(new_data)
     else:
         raise InvalidOperationException(
             "Must have a message_id to pull data from the server")
Exemplo n.º 5
0
 def save(self):
     if self.message_id:
         from lowerpines.exceptions import InvalidOperationException
         raise InvalidOperationException(
             "You cannot change a message that has already been sent")
     else:
         self.message_id = str(uuid.uuid4()).replace('-', '')
         global_messages[self.group_id].append(self)
Exemplo n.º 6
0
 def save(self):
     if self.message_id:
         raise InvalidOperationException(
             "You cannot change a message that has already been sent")
     else:
         new_data = MessagesCreateRequest(self.gmi, self.group_id,
                                          self.source_guid, self.text,
                                          self.attachments).result
         self._refresh_from_other(new_data)
Exemplo n.º 7
0
 def save(self):
     if self.direct_message_id is None:
         new_data = DirectMessageCreateRequest(self.gmi, self.source_guid,
                                               self.recipient_id, self.text,
                                               self.attachments).result
         self._refresh_from_other(new_data)
     else:
         raise InvalidOperationException(
             "You cannot change a message that has already been sent")
Exemplo n.º 8
0
 def get(gmi: "GMI", *args: Any) -> None:
     raise InvalidOperationException("This operation does not make sense")
Exemplo n.º 9
0
 def delete(self):
     if self.group_id is None:
         raise InvalidOperationException(
             'Cannot destroy a group that isn\'t saved!')
     else:
         GroupsDestroyRequest(self.gmi, self.group_id)
Exemplo n.º 10
0
 def get(gmi, *args):
     raise InvalidOperationException('This is non-trivial to implement')
Exemplo n.º 11
0
 def get(gmi: "GMI", bot_id: str) -> None:  # type: ignore
     raise InvalidOperationException("This is non trivial to implement")
Exemplo n.º 12
0
 def refresh(self) -> None:
     if self.bot_id is None:
         raise InvalidOperationException("This operation is not permitted")
     else:
         raise InvalidOperationException("This is non trivial to implement")
Exemplo n.º 13
0
 def delete(self) -> None:
     if self.bot_id is None:
         raise InvalidOperationException(
             "Cannot destroy a bot that isn't saved!")
     else:
         BotDestroyRequest(self.gmi, self.bot_id)
Exemplo n.º 14
0
 def get(gmi, *args):
     raise InvalidOperationException('This operation does not make sense')
Exemplo n.º 15
0
 def refresh(self):
     raise InvalidOperationException('Nontrivial to implement')
Exemplo n.º 16
0
 def save(self) -> None:
     raise InvalidOperationException("This operation is not permitted")
Exemplo n.º 17
0
 def refresh(self):
     raise InvalidOperationException('This is non-trivial to implement')
Exemplo n.º 18
0
 def get(gmi: "GMI", member_id: str) -> None:  # type: ignore
     raise InvalidOperationException("Nontrivial to implement")
Exemplo n.º 19
0
 def get(gmi: "GMI", *args: Any) -> None:
     raise InvalidOperationException("This is non-trivial to implement")
Exemplo n.º 20
0
 def refresh(self) -> None:
     raise InvalidOperationException("This is non-trivial to implement")
Exemplo n.º 21
0
 def get(gmi, member_id):
     raise InvalidOperationException('Nontrivial to implement')
Exemplo n.º 22
0
 def save(self):
     raise InvalidOperationException('This operation is not permitted')