class ConversationApiService(object):
    def __init__(self):
        self.apiaddress = ApiAddressService()
        self.storagecookie = StorageCookieService()

    def All(self):
        return requests.get("{0}/Conversation/All".format(
            self.apiaddress.getaddress()),
                            cookies=self.storagecookie.get())

    def SendMessage(self, conversationId, Message):
        return requests.post("{0}/Conversation/SendMessage".format(
            self.apiaddress.getaddress()),
                             data={
                                 "Id": conversationId,
                                 "Content": Message
                             },
                             cookies=self.storagecookie.get())

    def GetMesssages(self, conversationId, take):
        return requests.get(
            "{0}/Conversation/GetMessage?Id={1}&take={2}".format(
                self.apiaddress.getaddress(), str(conversationId), str(take)),
            cookies=self.storagecookie.get())

    def ConversationDetail(self, conversationid):
        return requests.get(
            "{0}/Conversation/ConversationDetail?id={1}".format(
                self.apiaddress.getaddress(), str(conversationid)),
            cookies=self.storagecookie.get())
Beispiel #2
0
class AuthApiService(object):
    def __init__(self):
        self.apiaddress = ApiAddressService()
        self.storagecookie = StorageCookieService()

    def Version(self):
        return requests.get("{0}/Auth/Version".format(self.apiaddress.getaddress()))

    def AuthByPassword(self, email, password):
        return requests.post("{0}/Auth/AuthByPassword".format(self.apiaddress.getaddress()), data={
            "Email": email,
            "Password": password
        })

    def InitPusher(self):
        return requests.get("{0}/Auth/InitPusher".format(self.apiaddress.getaddress()),
                         cookies=self.storagecookie.get())

    def SignInStatus(self):
        return requests.get("{0}/Auth/SignInStatus".format(self.apiaddress.getaddress(),
                         cookies=self.storagecookie.get()))

    def Me(self):
        return requests.get(
            "{0}/Auth/Me".format(self.apiaddress.getaddress()), 
                cookies=self.storagecookie.get())
Beispiel #3
0
class LoginController(Controller):
    authapiservice = None
    storagecookie = None

    def __init__(self):
        self.authapiservice = KahlaAuthApiService()
        self.storagecookie = StorageCookieService()

    # 定义参数
    def get_options(self):
        return [
            Option('-e', '--email', dest='email'),
            Option('-p', '--password', dest='password')
        ]

    # 处理输入参数, 检查合法性
    def run(self, email, password):
        # 这条必须编写, 并且带上传入的参数
        self.compute(email, password)

    # 处理业务逻辑
    def main(self, email, password):
        siginresult = self.authapiservice.AuthByPassword(email, password)
        siginresultdict = dict(json.loads(siginresult.text))
        if siginresultdict["code"] == 0:
            self.storagecookie.storage(siginresult.cookies)
            return ""
        else:
            return siginresultdict["message"]
Beispiel #4
0
class FriendShipApiService(object):
    def __init__(self):
        self.apiaddress = ApiAddressService()
        self.storagecookie = StorageCookieService()

    def Mine(self):
        return requests.get("{0}/Friendship/Mine".format(self.apiaddress.getaddress()),
                         cookies=self.storagecookie.get())

    def UserDetail(self, userid):
        return requests.get("{0}/Friendship/UserDetail?id={1}".format(self.apiaddress.getaddress(), str(userid)),
                         cookies=self.storagecookie.get())

    def DeleteFriend(self, userid):
        return requests.post("{0}/Friendship/DeleteFriend".format(self.apiaddress.getaddress()), data={
                "id": str(userid)
            }, cookies=self.storagecookie.get())
Beispiel #5
0
class GroupApiService(object):
    def __init__(self):
        self.apiaddress = ApiAddressService()
        self.storagecookie = StorageCookieService()

    def LeaveGroup(self, groupname):
        return requests.post("{0}/Groups/LeaveGroup".format(
            self.apiaddress.getaddress()),
                             data={"groupName": groupname},
                             cookies=self.storagecookie.get())
Beispiel #6
0
class FileApiService(object):
    def __init__(self):
        self.apiaddress = ApiAddressService()
        self.storagecookie = StorageCookieService()

    def FileDownloadAddress(self, filekey):
        return requests.post("{0}/Files/FileDownloadAddress".format(
            self.apiaddress.getaddress()),
                             data={"FileKey": filekey},
                             cookies=self.storagecookie.get())
class KahlaFriendShipApiService(object):
	apiaddress = None

	def __init__(self):
		self.apiaddress = KahlaApiAddressService()
		self.storagecookie = StorageCookieService()
	
	def Friends(self):
		r = requests.get("{0}/Friendship/MyFriends?orderByName=true".format(self.apiaddress.getaddress()),
				   cookies=self.storagecookie.get())
		
		return r
	
	def Me(self):
            r = requests.get("{0}/Auth/Me".format(self.apiaddress.getaddress()), cookies=self.storagecookie.get())
		
            return r
	
	def UserDetail(self, userid):
		r = requests.get("{0}/Friendship/UserDetail?id={1}".format(self.apiaddress.getaddress(), str(userid)),
						cookies=self.storagecookie.get())

		return r
	
	def DeleteFriend(self, userid):
		r = requests.post("{0}/Friendship/DeleteFriend".format(self.apiaddress.getaddress()), data={
			"id": str(userid)
		},
		cookies=self.storagecookie.get())

		return r
	
	def LeaveGroup(self, groupname):
		r = requests.post("{0}/Groups/LeaveGroup".format(self.apiaddress.getaddress()), data={
			"groupName": groupname
		},
		cookies=self.storagecookie.get())

		return r
Beispiel #8
0
class KahlaConversationApiService(object):
    def __init__(self):
        self.apiaddress = KahlaApiAddressService()
        self.storagecookie = StorageCookieService()

    def ConversationDetail(self, conversationid):
        r = requests.get("{0}/Conversation/ConversationDetail?id={1}".format(
            self.apiaddress.getaddress(), str(conversationid)),
                         cookies=self.storagecookie.get())

        return r

    def SendMessage(self, conversationId, Message):
        r = requests.post("{0}/Conversation/SendMessage".format(
            self.apiaddress.getaddress()),
                          data={
                              "Id": conversationId,
                              "Content": Message
                          },
                          cookies=self.storagecookie.get())

        return r

    def GetMesssages(self, conversationId, take):
        r = requests.get("{0}/Conversation/GetMessage?Id={1}&take={2}".format(
            self.apiaddress.getaddress(), str(conversationId), str(take)),
                         cookies=self.storagecookie.get())

        return r

    def FileDownloadAddress(self, filekey):
        r = requests.post("{0}/Files/FileDownloadAddress".format(
            self.apiaddress.getaddress()),
                          data={"FileKey": filekey},
                          cookies=self.storagecookie.get())

        return r
Beispiel #9
0
class SignInStatusCheckService(object):
    def __init__(self):
        self.storagecookie = StorageCookieService()
        self.apiaddress = ApiAddressService()

    def check(self):
        if os.path.exists("{0}/user.cookie.bin".format(
                HomeFloderConfig().getconfigpath())):
            cookies = self.storagecookie.get()
            err = requests.post("{0}/Auth/SignInStatus".format(
                self.apiaddress.getaddress()),
                                cookies=cookies)
            err = json.loads(err.text)
            if err["value"]:
                return True
            else:
                return False
        else:
            return False
class KahlaAuthApiService(object):
    apiaddress = None

    def __init__(self):
        self.apiaddress = KahlaApiAddressService()
        self.storagecookie = StorageCookieService()

    def AuthByPassword(self, email, password):
        r = requests.post("{0}/Auth/AuthByPassword".format(
            self.apiaddress.getaddress()),
                          data={
                              "Email": email,
                              "Password": password
                          })

        return r

    def InitPusher(self):
        r = requests.get("{0}/Auth/InitPusher".format(
            self.apiaddress.getaddress()),
                         cookies=self.storagecookie.get())

        return r
Beispiel #11
0
 def __init__(self):
     self.storagecookie = StorageCookieService()
     self.apiaddress = ApiAddressService()
Beispiel #12
0
 def __init__(self):
     self.authapiservice = KahlaAuthApiService()
     self.storagecookie = StorageCookieService()