def _build_list(cls, attributes): resources = [] elements = Util.remove_root(attributes) if isinstance(elements, dict): elements = [elements] for element in elements: resources.append(cls(Util.remove_root(element))) return resources
def count(cls, opts=None, **kwargs): """Use this method to view the total number of resources in your account. """ if opts is None: opts = kwargs return int(Util.remove_root(cls.get(custom_path="/count", **opts)))
def attachments_count(self, opts=None, **kwargs): """Use this method to view the total number of media attachments for a message in your account. """ if opts is None: opts = kwargs url = self.klass._custom_path(id_=self.id, custom_path="/attachments/count", options=None) + \ self.klass._query_string(opts) return Util.remove_root(Attachment.request.get(url))
def save(self): """Saves :class:`Resource` object to the server. :returns: ``True`` on success, or throws an error. :raises: :class:`RequestorError`: On any communications errors. :class:`ResourceError`: On any other errors. """ attributes = self._wrap_attributes(root=self._singular) if self.id: response = self.klass.request.put( self._element_path(self.id, path=None, options=self._prefix_options), attributes) else: response = self.klass.request.post(self._collection_path( path=None, options=self._prefix_options), params=attributes) self._update(Util.remove_root(response)) return True
def _build_object(cls, attributes): return cls(Util.remove_root(attributes))