Skip to content
Snippets Groups Projects
Commit 93d252d2 authored by Caner Candan's avatar Caner Candan
Browse files

* added logging and added wrapper around get and post in api interface class...

* added logging and added wrapper around get and post in api interface class in order to sign data before posting them
parent 706786d9
No related branches found
No related tags found
No related merge requests found
......@@ -19,11 +19,13 @@
from parser import Parser
from pprint import pprint
import ucoin
import json
import ucoin, json, logging
logger = logging.getLogger("cli")
def action_peering():
pprint(ucoin.ucg.Peering().get())
pprint(ucoin.ucg.Peering().post())
def action_amendments():
for am in ucoin.hdc.amendments.List().get():
......
......@@ -23,6 +23,7 @@ __version__ = '0.0.1'
__nonsense__ = 'uCoin'
import requests
import logging
settings = {
'host': 'localhost',
......@@ -30,6 +31,8 @@ settings = {
'auth': False,
}
logger = logging.getLogger("ucoin")
class API:
"""APIRequest is a class used as an interface. The intermediate derivated classes are the modules and the leaf classes are the API requests."""
......@@ -58,11 +61,27 @@ class API:
return self.url + path
def get(self):
"""wrapper of overloaded __get__ method."""
return self.__get__()
def post(self):
"""wrapper of overloaded __post__ method."""
logger.debug('do some work with')
data = self.__post__()
logger.debug('and send back')
return data
def __get__(self):
"""interface purpose for GET request"""
pass
def post(self):
def __post__(self):
"""interface purpose for POST request"""
pass
......
......@@ -16,7 +16,9 @@
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
#
from .. import API
from .. import API, logging
logger = logging.getLogger("ucoin/hdc")
class HDC(API):
def __init__(self, module='hdc'):
......
......@@ -17,6 +17,9 @@
#
from .. import HDC
import logging
logger = logging.getLogger("ucoin/hdc/amendments")
class Base(HDC):
def __init__(self):
......@@ -37,7 +40,7 @@ class Promoted(Base):
self.number = number
def get(self):
def __get__(self):
if not self.number:
return self.requests_get('/promoted').json()
......@@ -51,7 +54,7 @@ class Current(Promoted):
class List(Base):
"""GET the list of amendments through the previousHash value."""
def get(self):
def __get__(self):
"""creates a generator with one amendment per iteration."""
current = self.requests_get('/promoted').json()
......@@ -64,7 +67,7 @@ class List(Base):
class CurrentVotes(Base):
"""GET the votes that legitimate the current amendment."""
def get(self):
def __get__(self):
return self.merkle_easy_parser('/current/votes')
class Votes(Base):
......@@ -82,13 +85,13 @@ class Votes(Base):
self.amendment_id = amendment_id
def get(self):
def __get__(self):
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):
pass
from . import view
......@@ -16,7 +16,9 @@
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
#
from . import HDC
from . import HDC, logging
logger = logging.getLogger("ucoin/hdc/amendments/view")
class View(HDC):
def __init__(self, amendment_id):
......@@ -25,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):
return self.merkle_easy_parser('/members')
class Self(View):
"""Shows the raw data of the amendment [AMENDMENT_ID]."""
def get(self):
def __get__(self):
return self.requests_get('/self').json()
class Voters(View):
"""GET the voters listed in this amendment."""
def get(self):
def __get__(self):
return self.merkle_easy_parser('/voters')
class Signatures(View):
......@@ -46,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):
return self.merkle_easy_parser('/signatures')
......@@ -16,7 +16,9 @@
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
#
from .. import HDC
from .. import HDC, logging
logger = logging.getLogger("ucoin/hdc/coins")
class Coins(HDC):
def __init__(self, pgp_fingerprint):
......@@ -25,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):
return self.requests_get('/list').json()
class View(Coins):
......@@ -36,7 +38,7 @@ class View(Coins):
self.coin_number = coin_number
def get(self):
def __get__(self):
return self.requests_get('/view/%d' % self.coin_number).json()
from . import view
......@@ -16,7 +16,9 @@
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
#
from . import HDC
from . import HDC, logging
logger = logging.getLogger("ucoin/hdc/coins/view")
class Base(HDC):
def __init__(self, pgp_fingerprint, coin_number):
......@@ -25,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):
return self.requests_get('/history').json()
......@@ -16,7 +16,9 @@
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
#
from .. import HDC
from .. import HDC, logging
logger = logging.getLogger("ucoin/hdc/transactions")
class Base(HDC):
def __init__(self):
......@@ -37,13 +39,13 @@ class Process(Base):
self.transaction = transaction
self.signature = signature
def post(self):
def __post__(self):
pass
class All(Base):
"""GET all the transactions stored by this node."""
def get(self):
def __get__(self):
"""creates a generator with one transaction per iteration."""
return self.merkle_easy_parser('/all')
......@@ -51,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):
"""creates a generator with one key per iteration."""
return self.merkle_easy_parser('/keys')
......@@ -69,7 +71,7 @@ class Last(Base):
self.count = count
def get(self):
def __get__(self):
if not self.count:
return self.requests_get('/last').json()
......@@ -88,7 +90,7 @@ class Sender(Base):
self.pgp_fingerprint = pgp_fingerprint
def get(self):
def __get__(self):
return self.merkle_easy_parser('/sender/%s' % self.pgp_fingerprint)
class Recipient(Base):
......@@ -104,7 +106,7 @@ class Recipient(Base):
self.pgp_fingerprint = pgp_fingerprint
def get(self):
def __get__(self):
return self.merkle_easy_parser('/recipient/%s' % self.pgp_fingerprint)
class View(Base):
......@@ -120,7 +122,7 @@ class View(Base):
self.transaction_id = transaction_id
def get(self):
def __get__(self):
return self.requests_get('/view/%s' % self.transaction_id).json()
from . import sender
......@@ -16,7 +16,9 @@
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
#
from .. import HDC
from .. import HDC, logging
logger = logging.getLogger("ucoin/hdc/transactions/sender")
class Base(HDC):
"""Get the last received transaction of a PGP key."""
......@@ -42,7 +44,7 @@ class Last(Base):
self.count = count
def get(self):
def __get__(self):
if not self.count:
return self.requests_get('/last').json()
......@@ -51,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):
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):
return self.merkle_easy_parser('/issuance')
from . import issuance
......@@ -16,7 +16,9 @@
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
#
from . import HDC
from . import HDC, logging
logger = logging.getLogger("ucoin/hdc/transactions/sender/issuance")
class Base(HDC):
"""Get the received issuance transaction of a PGP key."""
......@@ -32,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):
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):
return self.merkle_easy_parser('/fusion')
class Dividend(Base):
......@@ -54,7 +56,7 @@ class Dividend(Base):
self.am_number = am_number
def get(self):
def __get__(self):
if not self.am_number:
return self.merkle_easy_parser('/dividend')
......
......@@ -16,7 +16,9 @@
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
#
from .. import API
from .. import API, logging
logger = logging.getLogger("ucoin/pks")
class PKS(API):
def __init__(self, module='pks'):
......@@ -25,7 +27,7 @@ class PKS(API):
class All(PKS):
"""GET all the received public keys."""
def get(self):
def __get__(self):
"""creates a generator with one public key per iteration."""
return self.merkle_easy_parser('/all')
......@@ -16,7 +16,9 @@
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
#
from .. import API
from .. import API, logging
logger = logging.getLogger("ucoin/ucg")
class UCG(API):
def __init__(self, module='ucg'):
......@@ -25,13 +27,13 @@ class UCG(API):
class Pubkey(UCG):
"""GET the public key of the peer."""
def get(self):
def __get__(self):
return self.requests_get('/pubkey').text
class Peering(UCG):
"""GET peering information about a peer."""
def get(self):
def __get__(self):
return self.requests_get('/peering').json()
class THT(UCG):
......@@ -49,13 +51,13 @@ class THT(UCG):
self.pgp_fingerprint = pgp_fingerprint
def get(self):
def __get__(self):
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):
pass
from . import peering
......@@ -16,7 +16,9 @@
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
#
from .. import UCG
from .. import UCG, logging
logger = logging.getLogger("ucoin/ucg/peering")
class Base(UCG):
def __init__(self):
......@@ -25,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):
"""creates a generator with one transaction per iteration."""
return self.merkle_easy_parser('/keys')
......@@ -33,7 +35,7 @@ class Keys(Base):
class Peer(Base):
"""GET the peering informations of this node."""
def get(self):
def __get__(self):
"""returns peering entry of the node."""
return self.requests_get('/peer').json()
......@@ -41,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):
"""creates a generator with one peering entry per iteration."""
return self.merkle_easy_parser('/peers')
def post(self):
def __post__(self):
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):
pass
class Status(Base):
"""POST a UCG status document to this node in order notify of its status."""
def post(self):
def __post__(self):
pass
from . import peers
......@@ -16,7 +16,9 @@
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
#
from . import UCG
from . import UCG, logging
logger = logging.getLogger("ucoin/ucg/peering/peers")
class Base(UCG):
def __init__(self):
......@@ -39,7 +41,7 @@ class Stream(Base):
self.request = request
self.pgp_fingerprint = pgp_fingerprint
def get(self):
def __get__(self):
"""returns the corresponding peer list."""
if not self.pgp_fingerprint:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment