diff --git a/ucoin/__init__.py b/ucoin/__init__.py index 30c50e0a8c6f62ce44e5cd632e9cb8ad5559e26b..0b622c022b6e72156e43b249730bbc1ba3b0acc9 100644 --- a/ucoin/__init__.py +++ b/ucoin/__init__.py @@ -129,33 +129,33 @@ class API: return self.url + path - def get(self): + def get(self, **kwargs): """wrapper of overloaded __get__ method.""" - return self.__get__() + return self.__get__(**kwargs) - def post(self): + def post(self, **kwargs): """wrapper of overloaded __post__ method.""" logger.debug('do some work with') - data = self.__post__() + data = self.__post__(**kwargs) logger.debug('and send back') return data - def __get__(self): + def __get__(self, **kwargs): """interface purpose for GET request""" pass - def __post__(self): + def __post__(self, **kwargs): """interface purpose for POST request""" pass - def requests_get(self, path): + def requests_get(self, path, **kwargs): """ Requests GET wrapper in order to use API parameters. @@ -164,11 +164,11 @@ class API: """ if not settings.get('auth'): - return requests.get(self.reverse_url(path), headers=self.headers) + return requests.get(self.reverse_url(path), params=kwargs, headers=self.headers) - return Response(requests.get(self.reverse_url(path), headers=self.headers)) + return Response(requests.get(self.reverse_url(path), params=kwargs, headers=self.headers)) - def requests_post(self, path): + def requests_post(self, path, **kwargs): """ Requests POST wrapper in order to use API parameters. @@ -176,11 +176,11 @@ class API: - `path`: the request path """ - return requests.post(self.reverse_url(path), headers=self.headers) + return requests.post(self.reverse_url(path), data=kwargs, headers=self.headers) def merkle_easy_parser(self, path): - root = self.requests_get(path + '?leaves=true').json() + root = self.requests_get(path, leaves='true').json() for leaf in root['leaves']: - yield self.requests_get(path + '?leaf=%s' % leaf).json()['leaf'] + yield self.requests_get(path, leaf=leaf).json()['leaf'] from . import pks, ucg, hdc diff --git a/ucoin/hdc/amendments/__init__.py b/ucoin/hdc/amendments/__init__.py index 613e663a5ce89c7cacb3b565aaa8325c5961d3ff..6bbe031f0a9fcd3c2368db684b6ebfb3132b4847 100644 --- a/ucoin/hdc/amendments/__init__.py +++ b/ucoin/hdc/amendments/__init__.py @@ -40,7 +40,7 @@ class Promoted(Base): self.number = number - def __get__(self): + def __get__(self, **kwargs): if not self.number: return self.requests_get('/promoted').json() @@ -54,7 +54,7 @@ class Current(Promoted): class List(Base): """GET the list of amendments through the previousHash value.""" - def __get__(self): + def __get__(self, **kwargs): """creates a generator with one amendment per iteration.""" current = self.requests_get('/promoted').json() @@ -67,7 +67,7 @@ class List(Base): class CurrentVotes(Base): """GET the votes that legitimate the current amendment.""" - def __get__(self): + def __get__(self, **kwargs): return self.merkle_easy_parser('/current/votes') class Votes(Base): @@ -85,13 +85,13 @@ class Votes(Base): self.amendment_id = amendment_id - def __get__(self): + def __get__(self, **kwargs): if not self.amendment_id: return self.requests_get('/votes').json() return self.merkle_easy_parser('/votes/%s' % self.amendment_id) - def __post__(self): + def __post__(self, **kwargs): pass from . import view diff --git a/ucoin/hdc/amendments/view.py b/ucoin/hdc/amendments/view.py index 434d9a73baba3500c8088319a0b050ed08a4b786..e32dce03a148303b54fc04713ce310295383b4de 100644 --- a/ucoin/hdc/amendments/view.py +++ b/ucoin/hdc/amendments/view.py @@ -27,19 +27,19 @@ class View(HDC): class Members(View): """GET the members present in the Community for this amendment.""" - def __get__(self): + def __get__(self, **kwargs): return self.merkle_easy_parser('/members') class Self(View): """Shows the raw data of the amendment [AMENDMENT_ID].""" - def __get__(self): + def __get__(self, **kwargs): return self.requests_get('/self').json() class Voters(View): """GET the voters listed in this amendment.""" - def __get__(self): + def __get__(self, **kwargs): return self.merkle_easy_parser('/voters') class Signatures(View): @@ -48,5 +48,5 @@ class Signatures(View): This URL should give the same result as hdc/amendments/votes/[PREVIOUS_AMENDEMENT_ID] if all votes present in this URL were taken in count as signatures for this AMENDMENT_ID. """ - def __get__(self): + def __get__(self, **kwargs): return self.merkle_easy_parser('/signatures') diff --git a/ucoin/hdc/coins/__init__.py b/ucoin/hdc/coins/__init__.py index 76809e91119fbaf3f12c2120b195fbee061e58a0..5c6933c7b3e44884298a8c8ea11c17a65ae45756 100644 --- a/ucoin/hdc/coins/__init__.py +++ b/ucoin/hdc/coins/__init__.py @@ -27,7 +27,7 @@ class Coins(HDC): class List(Coins): """GET a list of coins owned by the given [PGP_FINGERPRINT].""" - def __get__(self): + def __get__(self, **kwargs): return self.requests_get('/list').json() class View(Coins): @@ -38,7 +38,7 @@ class View(Coins): self.coin_number = coin_number - def __get__(self): + def __get__(self, **kwargs): return self.requests_get('/view/%d' % self.coin_number).json() from . import view diff --git a/ucoin/hdc/coins/view.py b/ucoin/hdc/coins/view.py index 1d3c9bfeb472cc8643b50e66de8a370ee3c16b16..cfda8cbf0ec448ad539e4d32787c70edc43cac61 100644 --- a/ucoin/hdc/coins/view.py +++ b/ucoin/hdc/coins/view.py @@ -27,5 +27,5 @@ class Base(HDC): class History(Base): """GET a transaction history of the coin [COIN_NUMBER] issued by [PGP_FINGERPRINT].""" - def __get__(self): + def __get__(self, **kwargs): return self.requests_get('/history').json() diff --git a/ucoin/hdc/transactions/__init__.py b/ucoin/hdc/transactions/__init__.py index 61c735ae5e967bd3c672fd98a603c55fd1a987f6..ffe8f5ccd2f53572e4a29d411349d232d2803cf5 100644 --- a/ucoin/hdc/transactions/__init__.py +++ b/ucoin/hdc/transactions/__init__.py @@ -45,7 +45,7 @@ class Process(Base): class All(Base): """GET all the transactions stored by this node.""" - def __get__(self): + def __get__(self, **kwargs): """creates a generator with one transaction per iteration.""" return self.merkle_easy_parser('/all') @@ -53,7 +53,7 @@ class All(Base): class Keys(Base): """GET PGP keys for which some transactions have been recoreded by this node (sent and received).""" - def __get__(self): + def __get__(self, **kwargs): """creates a generator with one key per iteration.""" return self.merkle_easy_parser('/keys') @@ -71,7 +71,7 @@ class Last(Base): self.count = count - def __get__(self): + def __get__(self, **kwargs): if not self.count: return self.requests_get('/last').json() @@ -90,7 +90,7 @@ class Sender(Base): self.pgp_fingerprint = pgp_fingerprint - def __get__(self): + def __get__(self, **kwargs): return self.merkle_easy_parser('/sender/%s' % self.pgp_fingerprint) class Recipient(Base): @@ -106,7 +106,7 @@ class Recipient(Base): self.pgp_fingerprint = pgp_fingerprint - def __get__(self): + def __get__(self, **kwargs): return self.merkle_easy_parser('/recipient/%s' % self.pgp_fingerprint) class View(Base): @@ -122,7 +122,7 @@ class View(Base): self.transaction_id = transaction_id - def __get__(self): + def __get__(self, **kwargs): return self.requests_get('/view/%s' % self.transaction_id).json() from . import sender diff --git a/ucoin/hdc/transactions/sender/__init__.py b/ucoin/hdc/transactions/sender/__init__.py index d388f16b0a3156b6e65cd0637499008075e79fa7..d95208b8848e8b6704c096e5fe582f9706cc655d 100644 --- a/ucoin/hdc/transactions/sender/__init__.py +++ b/ucoin/hdc/transactions/sender/__init__.py @@ -44,7 +44,7 @@ class Last(Base): self.count = count - def __get__(self): + def __get__(self, **kwargs): if not self.count: return self.requests_get('/last').json() @@ -53,13 +53,13 @@ class Last(Base): class Transfer(Base): """GET all transfer transactions sent by this sender and stored by this node (should contain all transfert transactions of the sender).""" - def __get__(self): + def __get__(self, **kwargs): return self.merkle_easy_parser('/transfert') class Issuance(Base): """GET all issuance transactions (forged coins) sent by this sender and stored by this node (should contain all issuance transactions of the sender).""" - def __get__(self): + def __get__(self, **kwargs): return self.merkle_easy_parser('/issuance') from . import issuance diff --git a/ucoin/hdc/transactions/sender/issuance.py b/ucoin/hdc/transactions/sender/issuance.py index 9a488508c33d72b502bec1494ea9359b61556084..d4a5c1e4f3b51cd915b58841eb59813658e4baa0 100644 --- a/ucoin/hdc/transactions/sender/issuance.py +++ b/ucoin/hdc/transactions/sender/issuance.py @@ -34,13 +34,13 @@ class Base(HDC): class Last(Base): """GET the last received issuance transaction of a PGP key.""" - def __get__(self): + def __get__(self, **kwargs): return self.requests_get('/last').json() class Fusion(Base): """GET all fusion transactions sent by this sender and stored by this node (should contain all fusion transactions of the sender).""" - def __get__(self): + def __get__(self, **kwargs): return self.merkle_easy_parser('/fusion') class Dividend(Base): @@ -56,7 +56,7 @@ class Dividend(Base): self.am_number = am_number - def __get__(self): + def __get__(self, **kwargs): if not self.am_number: return self.merkle_easy_parser('/dividend') diff --git a/ucoin/pks/__init__.py b/ucoin/pks/__init__.py index e5a640b87e47b5cb4e7c09d79db8f996b68d1f98..949714cd31679999de0cc851532415628f5cfccc 100644 --- a/ucoin/pks/__init__.py +++ b/ucoin/pks/__init__.py @@ -27,7 +27,7 @@ class PKS(API): class All(PKS): """GET all the received public keys.""" - def __get__(self): + def __get__(self, **kwargs): """creates a generator with one public key per iteration.""" return self.merkle_easy_parser('/all') diff --git a/ucoin/ucg/__init__.py b/ucoin/ucg/__init__.py index 08b3d05b3d78fcc072c6c7cfa2d11ed7e71d009c..125dbeb9dc46d214dd2142fa67d61082e4bda40a 100644 --- a/ucoin/ucg/__init__.py +++ b/ucoin/ucg/__init__.py @@ -27,13 +27,13 @@ class UCG(API): class Pubkey(UCG): """GET the public key of the peer.""" - def __get__(self): + def __get__(self, **kwargs): return self.requests_get('/pubkey').text class Peering(UCG): """GET peering information about a peer.""" - def __get__(self): + def __get__(self, **kwargs): return self.requests_get('/peering').json() class THT(UCG): @@ -51,13 +51,13 @@ class THT(UCG): self.pgp_fingerprint = pgp_fingerprint - def __get__(self): + def __get__(self, **kwargs): if not self.pgp_fingerprint: return self.merkle_easy_parser('/tht').json() return self.merkle_easy_parser('/tht/%s' % self.pgp_fingerprint).json() - def __post__(self): + def __post__(self, **kwargs): pass from . import peering diff --git a/ucoin/ucg/peering/__init__.py b/ucoin/ucg/peering/__init__.py index 9074febb1d3a0408839c08ff569ea5b14a6888ca..f74d48b77146c2a97e0c65709c7909d6f385b6c4 100644 --- a/ucoin/ucg/peering/__init__.py +++ b/ucoin/ucg/peering/__init__.py @@ -27,7 +27,7 @@ class Base(UCG): class Keys(Base): """GET PGP keys' fingerprint this node manages, i.e. this node will have transactions history and follow ohter nodes for this history.""" - def __get__(self): + def __get__(self, **kwargs): """creates a generator with one transaction per iteration.""" return self.merkle_easy_parser('/keys') @@ -35,7 +35,7 @@ class Keys(Base): class Peer(Base): """GET the peering informations of this node.""" - def __get__(self): + def __get__(self, **kwargs): """returns peering entry of the node.""" return self.requests_get('/peer').json() @@ -43,24 +43,24 @@ class Peer(Base): class Peers(Base): """GET peering entries of every node inside the currency network.""" - def __get__(self): + def __get__(self, **kwargs): """creates a generator with one peering entry per iteration.""" return self.merkle_easy_parser('/peers') - def __post__(self): + def __post__(self, **kwargs): pass class Forward(Base): """POST a UCG forward document to this node in order to be sent back incoming transactions.""" - def __post__(self): + def __post__(self, **kwargs): pass class Status(Base): """POST a UCG status document to this node in order notify of its status.""" - def __post__(self): + def __post__(self, **kwargs): pass from . import peers diff --git a/ucoin/ucg/peering/peers.py b/ucoin/ucg/peering/peers.py index 1ce89880df53e077c42912548dd408fe41af9952..f03cbe88f6e012e880995097b52fc645487b999c 100644 --- a/ucoin/ucg/peering/peers.py +++ b/ucoin/ucg/peering/peers.py @@ -41,7 +41,7 @@ class Stream(Base): self.request = request self.pgp_fingerprint = pgp_fingerprint - def __get__(self): + def __get__(self, **kwargs): """returns the corresponding peer list.""" if not self.pgp_fingerprint: