Skip to content

Commit

Permalink
Merge pull request #25 from stanvanrooy/19_update_function_names
Browse files Browse the repository at this point in the history
Update function names in actions.friendships
  • Loading branch information
stanvanrooy committed Aug 25, 2020
2 parents 14283f6 + 6fd8522 commit e85056f
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ client = ApiClient(user_name="yourusername", password="yourpassword")
client.login()

f = fs.ShowFollowers.create(user_id="2283025667")
obj, result = client.get_followers(f) # grabs first page
obj, result = client.followers_get(f) # grabs first page
while result: # paginates until all followers are extracted
parsed = result.json()
print(f"Extracted {len(parsed['users'])} followers")
print(f"The username of the first extracted follower is {parsed['users'][0]['username']}")
obj, result = client.get_followers(obj)
obj, result = client.followers_get(obj)
sleep(random.randint(10, 60))
```
A few other examples of how to use the package, can be found in the examples directory.
Expand Down
4 changes: 2 additions & 2 deletions examples/friendships/approve_all_follow_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
client.save_to_disk('./.instauto.save')

p = fs.PendingRequests()
users = client.get_follow_requests(p)
users = client.follow_requests_get(p)

for user in users: # approves all requests
a = fs.ApproveRequest.create(str(user['pk']))
resp = client.approve_follow_request(a)
resp = client.follow_request_approve(a)
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
user_id = resp['users'][0]['pk']

a = fs.ApproveRequest.create(user_id)
resp = client.approve_follow_request(a)
resp = client.follow_request_approve(a)
2 changes: 1 addition & 1 deletion examples/friendships/create_friendship.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
client.save_to_disk('./.instauto.save')

f = fs.Create.create(user_id="6889845893")
client.follow_user(f)
client.user_follow(f)
2 changes: 1 addition & 1 deletion examples/friendships/destroy_friendship.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
client.save_to_disk('./.instauto.save')

f = fs.Destroy.create(user_id="6889845893")
client.unfollow_user(f)
client.user_unfollow(f)
4 changes: 2 additions & 2 deletions examples/friendships/get_followers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
client.save_to_disk('./.instauto.save')

f = fs.ShowFollowers.create(user_id="2283025667")
obj, result = client.get_followers(f) # grabs first page
obj, result = client.followers_get(f) # grabs first page
while result: # paginates until all followers are extracted
parsed = result.json()
print(f"Extracted {len(parsed['users'])} followers")
print(f"The username of the first extracted follower is {parsed['users'][0]['username']}")
obj, result = client.get_followers(obj)
obj, result = client.followers_get(obj)
sleep(random.randint(10, 60))
4 changes: 2 additions & 2 deletions examples/friendships/get_following.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
client.save_to_disk('./.instauto.save')

f = fs.ShowFollowing.create(user_id="2283025667")
obj, result = client.get_following(f) # grabs the first page
obj, result = client.following_get(f) # grabs the first page
while result: # paginate until all users are extracted
parsed = result.json()
print(f"Extracted {len(parsed['users'])} users following")
print(f"The username of the first extracted user following is {parsed['users'][0]['username']}")
obj, result = client.get_following(obj)
obj, result = client.following_get(obj)
sleep(random.randint(10, 60))
2 changes: 1 addition & 1 deletion examples/friendships/remove_follower.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
client.save_to_disk('./.instauto.save')

f = fs.Remove.create(user_id="38720650610")
client.remove_follower(f)
client.follower_remove(f)
2 changes: 1 addition & 1 deletion examples/friendships/show_friendship.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
client.save_to_disk('./.instauto.save')

f = fs.Show.create(user_id="38720650610")
resp = client.show_follower(f)
resp = client.follower_show(f)
print("status: ", resp.json())
36 changes: 18 additions & 18 deletions instauto/api/actions/friendships.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,24 @@ class FriendshipsMixin:
state: State
_request: Callable

def _friendships_act(self, obj: Union[Create, Destroy, Remove]) -> Response:
obj._csrftoken = self._session.cookies['csrftoken']
obj.device_id = self.state.device_id
obj._uid = self.state.user_id
obj._uuid = self.state.uuid
as_d = obj.__dict__
as_d['radio_type'] = obj.radio_type # why does this get removed, even though it has a default value?

return self._request(f'friendships/{obj.endpoint}/{obj.user_id}/', Method.POST, data=as_d, signed=True)

def follow_user(self, obj: Create) -> Response:
def user_follow(self, obj: Create) -> Response:
"""Follow a user"""
return self._friendships_act(obj)

def unfollow_user(self, obj: Destroy) -> Response:
def user_unfollow(self, obj: Destroy) -> Response:
"""Unfollow a user"""
return self._friendships_act(obj)

def remove_follower(self, obj: Remove) -> Response:
def follower_remove(self, obj: Remove) -> Response:
"""Remove someone from your followers list, that is currently following you"""
return self._friendships_act(obj)

def show_follower(self, obj: Show) -> Response:
def follower_show(self, obj: Show) -> Response:
"""Retrieve information about a user"""
# doesn't use _friendship_act, because it is a GET request.
return self._request(f"friendships/{obj.endpoint}/{obj.user_id}/", Method.GET)

def get_followers(self, obj: ShowFollowers) -> Tuple[ShowFollowers, Union[Response, bool]]:
def followers_get(self, obj: ShowFollowers) -> Tuple[ShowFollowers, Union[Response, bool]]:
"""Retrieves the followers of an Instagram user. Examples of how to use can be found in
examples/friendships/get_followers.py.
Returns
Expand Down Expand Up @@ -91,7 +81,7 @@ def get_followers(self, obj: ShowFollowers) -> Tuple[ShowFollowers, Union[Respon
obj.page += 1
return obj, resp

def get_following(self, obj: ShowFollowing) -> Tuple[ShowFollowing, Union[Response, bool]]:
def following_get(self, obj: ShowFollowing) -> Tuple[ShowFollowing, Union[Response, bool]]:
"""Retrieves the following of an Instagram user. Examples of how to use can be found in
examples/friendships/get_following.py.
Returns
Expand Down Expand Up @@ -143,7 +133,7 @@ def get_following(self, obj: ShowFollowing) -> Tuple[ShowFollowing, Union[Respon
obj.page += 1
return obj, resp

def get_follow_requests(self, obj: PendingRequests) -> List[dict]:
def follow_requests_get(self, obj: PendingRequests) -> List[dict]:
"""
Returns
-------
Expand All @@ -167,8 +157,18 @@ def get_follow_requests(self, obj: PendingRequests) -> List[dict]:
parsed = resp.json()
return parsed['users']

def approve_follow_request(self, obj: ApproveRequest) -> Response:
def follow_request_approve(self, obj: ApproveRequest) -> Response:
obj._csrftoken = self._session.cookies.get('csrftoken', domain='instagram.com')
obj._uid = self.state.user_id
obj._uuid = self.state.uuid
return self._request(f'friendships/approve/{obj.user_id}/', Method.POST, data=obj.__dict__)

def _friendships_act(self, obj: Union[Create, Destroy, Remove]) -> Response:
obj._csrftoken = self._session.cookies['csrftoken']
obj.device_id = self.state.device_id
obj._uid = self.state.user_id
obj._uuid = self.state.uuid
as_d = obj.__dict__
as_d['radio_type'] = obj.radio_type # why does this get removed, even though it has a default value?

return self._request(f'friendships/{obj.endpoint}/{obj.user_id}/', Method.POST, data=as_d, signed=True)

0 comments on commit e85056f

Please sign in to comment.