Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit 417f5b2

Browse files
author
Mike Krieger
committed
Merge remote-tracking branch 'michaelhelmick/relationship_status'
2 parents 6906a95 + 0e48d18 commit 417f5b2

6 files changed

Lines changed: 56 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ Relationships: http://instagr.am/developer/endpoints/relationships/
118118
api.unblock_user(user_id)
119119
api.approve_user_request(user_id)
120120
api.ignore_user_request(user_id)
121+
api.user_relationship(user_id)
121122

122123

123124
Media: http://instagr.am/developer/endpoints/media/

instagram/bind.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
import urllib
22
from oauth2 import OAuth2Request
33
import re
4-
import simplejson
4+
5+
try:
6+
import simplejson
7+
except ImportError:
8+
try:
9+
import json as simplejson
10+
except ImportError:
11+
try:
12+
from django.utils import simplejson
13+
except ImportError:
14+
raise ImportError('A json library is required to use this python library. Lol, yay for being verbose. ;)')
15+
516
re_path_template = re.compile('{\w+}')
617

718

@@ -91,7 +102,12 @@ def _do_api_request(self, url, method="GET", body=None, headers=None):
91102
response, content = OAuth2Request(self.api).make_request(url, method=method, body=body, headers=headers)
92103
if response['status'] == '503':
93104
raise InstagramAPIError(response['status'], "Rate limited", "Your client is making too many request per second")
94-
content_obj = simplejson.loads(content)
105+
106+
try:
107+
content_obj = simplejson.loads(content)
108+
except ValueError:
109+
raise InstagramClientError('Unable to parse response, not valid JSON.')
110+
95111
api_responses = []
96112
status_code = content_obj['meta']['code']
97113
if status_code == 200:

instagram/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ def __init__(self, *args, **kwargs):
174174
requires_target_user=True,
175175
response_type="entry")
176176

177+
user_relationship = bind_method(
178+
method="GET",
179+
path="/users/{user_id}/relationship",
180+
root_class=Relationship,
181+
accepts_parameters=["user_id"],
182+
paginates=False,
183+
requires_target_user=True,
184+
response_type="entry")
185+
177186
def _make_relationship_shortcut(action):
178187
def _inner(self, *args, **kwargs):
179188
return self.change_user_relationship(user_id=kwargs.get("user_id"),

instagram/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,9 @@ def __init__(self, incoming_status="none", outgoing_status="none", target_user_i
154154
self.incoming_status = incoming_status
155155
self.outgoing_status = outgoing_status
156156
self.target_user_is_private = target_user_is_private
157+
158+
def __unicode__(self):
159+
follows = False if self.outgoing_status == 'none' else True
160+
followed = False if self.incoming_status == 'none' else True
161+
162+
return "Relationship: (Follows: %s, Followed by: %s)" % (follows, followed)

instagram/subscriptions.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import hmac
22
import hashlib
3-
import simplejson
3+
4+
try:
5+
import simplejson
6+
except ImportError:
7+
try:
8+
import json as simplejson
9+
except ImportError:
10+
try:
11+
from django.utils import simplejson
12+
except ImportError:
13+
raise ImportError('A json library is required to use this python library. Lol, yay for being verbose. ;)')
414

515

616
class SubscriptionType:
@@ -10,7 +20,11 @@ class SubscriptionType:
1020
LOCATION = 'location'
1121

1222

13-
class SubscriptionVerifyError(Exception):
23+
class SubscriptionError(Exception):
24+
pass
25+
26+
27+
class SubscriptionVerifyError(SubscriptionError):
1428
pass
1529

1630

@@ -28,7 +42,11 @@ def process(self, client_secret, raw_response, x_hub_signature):
2842
if not self._verify_signature(client_secret, raw_response, x_hub_signature):
2943
raise SubscriptionVerifyError("X-Hub-Signature and hmac digest did not match")
3044

31-
response = simplejson.loads(raw_response)
45+
try:
46+
response = simplejson.loads(raw_response)
47+
except ValueError:
48+
raise SubscriptionError('Unable to parse response, not valid JSON.')
49+
3250
for update in response:
3351
self._process_update(update)
3452

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from setuptools import setup, find_packages
33

44
setup(name="python-instagram",
5-
version="0.7.3",
5+
version="0.8.0",
66
description="Instagram API client",
77
license="MIT",
88
install_requires=["simplejson","httplib2"],

0 commit comments

Comments
 (0)