Skip to content

Commit

Permalink
Implement new endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
kiliczsh committed Apr 22, 2023
1 parent 6b8512f commit c7be23c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
6 changes: 6 additions & 0 deletions gokyuzu/BlueskyEndpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ def getAuthorFeed(self):
def getPostThread(self):
return self.get_url("/xrpc/app.bsky.feed.getPostThread")

def getLikes(self):
return self.get_url("/xrpc/app.bsky.feed.getLikes")

def getRepostedBy(self):
return self.get_url("/xrpc/app.bsky.feed.getRepostedBy")

# app.bsky.graph
def getFollowers(self):
return self.get_url("/xrpc/app.bsky.graph.getFollowers")
Expand Down
7 changes: 7 additions & 0 deletions gokyuzu/BlueskySession.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ def post(self, url, data=None, json=None, **kwargs):
response = requests.post(url, headers=headers, data=data, json=json, **kwargs)
return response

def post(self, url, headers=None, data=None, json=None, **kwargs):
if headers is None:
headers = {}
headers['Authorization'] = f'Bearer {self.getAccessToken()}'
response = requests.post(url, headers=headers, data=data, json=json, **kwargs)
return response

def postJson(self, url, json, **kwargs):
headers = { 'Authorization': f'Bearer {self.getAccessToken()}', 'Content-Type': 'application/json' }
response = requests.post(url, headers=headers, json=json, **kwargs)
Expand Down
35 changes: 35 additions & 0 deletions gokyuzu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ def getPostThread(self, post_id, limit=10, cursor=""):
response = self.SESSION.get(request_url)
return response

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

def getRepostedBy(self, post_id, limit=10, cursor=""):
request_url = self.ENDPOINTS.getRepostedBy() + "?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:
Expand Down Expand Up @@ -197,3 +207,28 @@ def health(self):
request_url = self.ENDPOINTS.health()
response = self.SESSION.get(request_url)
return response

def uploadImage(self, image_path, content_type="image/jpeg"):
request_url = self.ENDPOINTS.uploadBlob()
headers = {"Content-Type": content_type}
with open(image_path, 'rb') as f:
data = f.read()
response = self.SESSION.post(request_url, data=data, headers=headers)
return response

def searchTypeAhead(self, query="", limit=10):
typeahead_url = "https://bsky.social/xrpc/app.bsky.actor.searchActorsTypeahead"
request_url = "{}?term={}&limit={}".format(typeahead_url, query, limit)
response = self.SESSION.get(request_url)
return response

def search(self, query_type="posts", query=""):
request_url = "https://search.bsky.social/search/{}?q={}".format(query_type, query)
response = self.SESSION.get(request_url)
return response

def search_profiles(self, query):
return self.search(query_type="profiles", query=query)

def search_posts(self, query):
return self.search(query_type="posts", query=query)
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 = "1.0.0"
version = "1.0.1"
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='1.0.0',
version='1.0.1',
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 c7be23c

Please sign in to comment.