Skip to content

Commit

Permalink
Implement missing endpoints and bump to 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kiliczsh committed Apr 22, 2023
1 parent 599867a commit 8eeeff3
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 38 deletions.
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,26 @@ print(response.json())

List of Implemented API Calls:

- `resolveHandle(username)`
- `getProfile(user_did)`
- `follow(handle=None, user_did=None)`
- `getAccountInviteCodes(limit=10)`
- `getFollowers(handle=None, user_did=None, limit=10, cursor="")`
- `getFollows(handle=None, user_did=None, limit=10, cursor="")`
- `listNotifications(limit=10, cursor="")`
- `updateSeen(limit=10, cursor="")`
- `getTimeline(limit=10, cursor="", algorithm="reverse-chronological")`
- `createAccount(self, email, handle, password, inviteCode)`
- `getSession(self)`
- `getAccountInviteCodes(self, limit=10)`
- `getProfile(self, user_did)`
- `getProfiles(self, user_dids)`
- `getPopular(self, limit=10, cursor="")`
- `getTimeline(self, limit=10, cursor="", algorithm="reverse-chronological")`
- `getAuthorFeed(self, handle=None, user_did=None, limit=10, cursor="")`
- `getPostThread(self, post_id, limit=10, cursor="")`
- `getFollowers(self, handle=None, user_did=None, limit=10, cursor="")`
- `getFollows(self, handle=None, user_did=None, limit=10, cursor="")`
- `listNotifications(self, limit=10, cursor="")`
- `updateSeen(self, limit=10, cursor="")`
- `createRecord(self, repo, record, collection)`
- `deleteRecord(self, repo, record, collection)`
- `follow(self, handle=None, user_did=None)`
- `unfollow(self, handle=None, user_did=None)`
- `resolveHandle(self, handle)`
- `updateHandle(self, handle)`


### Development

Expand Down
155 changes: 128 additions & 27 deletions gokyuzu/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json
from types import SimpleNamespace
from gokyuzu.BlueskyEndpoints import BlueskyEndpoints
from gokyuzu.BlueskyHelper import BlueskyHelper
from gokyuzu.BlueskySession import BlueskySession
Expand All @@ -12,41 +14,69 @@ def __init__(self, handle, password):
def __str__(self):
return f"Bluesky(server={self.BSKY_SERVER}, handle={self.SESSION.getHandle()}, email={self.SESSION.getEmail()}, did={self.SESSION.getDID()}, accessToken={self.SESSION.getAccessToken()}, refreshToken={self.SESSION.getRefreshToken()})"

def resolveHandle(self, handle):
request_url = self.ENDPOINTS.resolveHandle() + "?handle={}".format(handle)
# com.atproto.server
def createAccount(self, email, handle, password, inviteCode):
request_data = {
"email": email,
"handle": handle,
"password": password,
"inviteCode": inviteCode
}

response = self.SESSION.postJson(self.ENDPOINTS.createAccount(), json=request_data)
return response

def getSession(self):
request_url = self.ENDPOINTS.getSession()
response = self.SESSION.get(request_url)
return response

def getAccountInviteCodes(self, limit=10):
request_url = self.ENDPOINTS.getAccountInviteCodes() + "?limit={}".format(limit)
response = self.SESSION.get(request_url)
return response

# app.bsky.actor
def getProfile(self, user_did):
request_url = self.ENDPOINTS.getProfile() + "?actor={}".format(user_did)
response = self.SESSION.get(request_url)
return response

def follow(self, handle=None, user_did=None):
if handle:
user_did = self.resolveHandle(handle).json().get("did")

if not user_did or user_did is None:
raise ValueError("Invalid username")

follow_request_data = {
"repo": self.DID,
"record": {
"subject": user_did,
"createdAt": BlueskyHelper.getTimestamp(),
"$type": "app.bsky.graph.follow"
},
"collection": "app.bsky.graph.follow"
}

response = self.SESSION.post(self.ENDPOINTS.createRecord(), json=follow_request_data)

def getProfiles(self, user_dids):
request_url = self.ENDPOINTS.getProfiles() + "?actors={}".format(user_dids)
response = self.SESSION.get(request_url)
return response

def getAccountInviteCodes(self, limit=10):
request_url = self.ENDPOINTS.getAccountInviteCodes() + "?limit={}".format(limit)

# app.bsky.unspecced
def getPopular(self, limit=10, cursor=""):
request_url = self.ENDPOINTS.getPopular() + "?limit={}&cursor={}".format(limit, cursor)
response = self.SESSION.get(request_url)
return response

# app.bsky.feed
def getTimeline(self, limit=10, cursor="", algorithm="reverse-chronological"):
request_url = self.ENDPOINTS.getTimeline() + "?algorithm={}&limit={}&cursor={}".format(algorithm, limit, cursor)
response = self.SESSION.get(request_url)
return response

def getAuthorFeed(self, handle=None, user_did=None, limit=10, cursor=""):
if handle:
actor = handle
elif user_did:
actor = user_did
else:
raise ValueError("Invalid username or did")

request_url = self.ENDPOINTS.getAuthorFeed() + "?actor={}&limit={}&cursor={}".format(actor, limit, cursor)
response = self.SESSION.get(request_url)
return response

def getPostThread(self, post_id, limit=10, cursor=""):
request_url = self.ENDPOINTS.getPostThread() + "?uri={}&limit={}&cursor={}".format(post_id, limit, cursor)
response = self.SESSION.get(request_url)
return response

# app.bsky.graph
def getFollowers(self, handle=None, user_did=None, limit=10, cursor=""):
if handle:
actor = handle
Expand All @@ -70,7 +100,8 @@ def getFollows(self, handle=None, user_did=None, limit=10, cursor=""):
request_url = self.ENDPOINTS.getFollows() + "?actor={}&limit={}&cursor={}".format(actor, limit, cursor)
response = self.SESSION.get(request_url)
return response


# app.bsky.notification
def listNotifications(self, limit=10, cursor=""):
request_url = self.ENDPOINTS.listNotifications() + "?limit={}&cursor={}".format(limit, cursor)
response = self.SESSION.get(request_url)
Expand All @@ -82,7 +113,77 @@ def updateSeen(self, limit=10, cursor=""):
response = self.SESSION.postJson(request_url, json=data)
return response

def getTimeline(self, limit=10, cursor="", algorithm="reverse-chronological"):
request_url = self.ENDPOINTS.getTimeline() + "?algorithm={}&limit={}&cursor={}".format(algorithm, limit, cursor)
# com.atproto.repo
def createRecord(self, repo, record, collection):
request_data = {
"repo": repo,
"record": record,
"collection": collection
}

response = self.SESSION.postJson(self.ENDPOINTS.createRecord(), json=request_data)
return response

def deleteRecord(self, repo, record, collection):
request_data = {
"repo": repo,
"record": record,
"collection": collection
}

response = self.SESSION.postJson(self.ENDPOINTS.deleteRecord(), json=request_data)
return response

def follow(self, handle=None, user_did=None):
if handle:
user_did = self.resolveHandle(handle).json().get("did")

if not user_did or user_did is None:
raise ValueError("Invalid username")

follow_request_data = {
"repo": self.DID,
"record": {
"subject": user_did,
"createdAt": BlueskyHelper.getTimestamp(),
"$type": "app.bsky.graph.follow"
},
"collection": "app.bsky.graph.follow"
}

response = self.SESSION.post(self.ENDPOINTS.createRecord(), json=follow_request_data)
return response

def unfollow(self, handle=None, user_did=None):
if handle:
user_did = self.resolveHandle(handle).json().get("did")

if not user_did or user_did is None:
raise ValueError("Invalid username")

unfollow_request_data = {
"repo": self.DID,
"record": {
"subject": user_did,
"createdAt": BlueskyHelper.getTimestamp(),
"$type": "app.bsky.graph.unfollow"
},
"collection": "app.bsky.graph.unfollow"
}

response = self.SESSION.postJson(self.ENDPOINTS.deleteRecord(), json=unfollow_request_data)
return response

# com.atproto.identity
def resolveHandle(self, handle):
request_url = self.ENDPOINTS.resolveHandle() + "?handle={}".format(handle)
response = self.SESSION.get(request_url)
return response

def updateHandle(self, handle):
request_data = {
"handle": handle
}

response = self.SESSION.postJson(self.ENDPOINTS.updateHandle(), json=request_data)
return response
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[tool.poetry]
name = "gokyuzu"
version = "0.0.7"
version = "1.0.0"
description = "bsky.social client library"
authors = ["Muhammed Kılıç <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='gokyuzu',
version='0.0.7',
version='1.0.0',
description='bsky.social client library',
long_description=open('README.md', 'r', encoding='utf-8').read(),
long_description_content_type='text/markdown',
Expand Down

0 comments on commit 8eeeff3

Please sign in to comment.