Skip to content

Commit 3662b7a

Browse files
author
Brandon Black
committed
[minor] account.client should be a property, not a method
1 parent 79c25a9 commit 3662b7a

File tree

7 files changed

+25
-44
lines changed

7 files changed

+25
-44
lines changed

twitter_ads/account.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ class Account(Resource):
2929
def __init__(self, client):
3030
self._client = client
3131

32+
@property
3233
def client(self):
33-
"""
34-
Returns the :class:`Client` instance stored in this account object.
35-
"""
3634
return self._client
3735

3836
@classmethod
@@ -60,8 +58,7 @@ def reload(self, **kwargs):
6058
params.update(kwargs)
6159

6260
resource = self.RESOURCE.format(account_id=self.account.id, id=self.id)
63-
response = Request(
64-
self.account.client, 'get', resource, params=params).perform()
61+
response = Request(self.account.client, 'get', resource, params=params).perform()
6562

6663
self.from_response(response.body['data'])
6764

@@ -72,7 +69,7 @@ def features(self):
7269
self._validate_loaded()
7370

7471
resource = self.FEATURES.format(id=self.id)
75-
response = Request(self.client(), 'get', resource).perform()
72+
response = Request(self.client, 'get', resource).perform()
7673

7774
return response.body['data']
7875

@@ -135,8 +132,7 @@ def scoped_timeline(self, *ids, **kwargs):
135132
params.update(kwargs)
136133

137134
resource = self.SCOPED_TIMELINE.format(id=self.id)
138-
response = Request(
139-
self.client(), 'get', resource, params=params).perform()
135+
response = Request(self.client, 'get', resource, params=params).perform()
140136

141137
return response.body['data']
142138

twitter_ads/campaign.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def all(klass, account, line_item_id, **kwargs):
2727
params.update(kwargs)
2828

2929
resource = klass.RESOURCE_COLLECTION.format(account_id=account.id)
30-
request = Request(account.client(), 'get', resource, params=params)
30+
request = Request(account.client, 'get', resource, params=params)
3131

3232
return Cursor(klass, request, init_with=[account])
3333

@@ -112,10 +112,8 @@ def create(self, name, *ids):
112112
ids = ','.join(map(str, ids))
113113

114114
resource = self.RESOURCE_COLLECTION.format(account_id=self.account.id)
115-
params = self.to_params.update({
116-
'app_store_identifiers': ids, 'name': name})
117-
response = Request(
118-
self.account.client(), 'post', resource, params=params).perform()
115+
params = self.to_params.update({'app_store_identifiers': ids, 'name': name})
116+
response = Request(self.account.client, 'post', resource, params=params).perform()
119117

120118
return self.from_response(response.body['data'])
121119

@@ -230,7 +228,7 @@ def preview(klass, account, **kwargs):
230228
"""
231229
resource = klass.TWEET_ID_PREVIEW if kwargs.get('id') else klass.TWEET_PREVIEW
232230
resource = resource.format(account_id=account.id, id=kwargs.get('id'))
233-
response = Request(account.client(), 'get', resource, params=kwargs).perform()
231+
response = Request(account.client, 'get', resource, params=kwargs).perform()
234232
return response.body['data']
235233

236234
@classmethod
@@ -241,5 +239,5 @@ def create(klass, account, status, **kwargs):
241239
params = {'status': status}
242240
params.update(kwargs)
243241
resource = klass.TWEET_CREATE.format(account_id=account.id)
244-
response = Request(account.client(), 'post', resource, params=params).perform()
242+
response = Request(account.client, 'post', resource, params=params).perform()
245243
return response.body['data']

twitter_ads/creative.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,18 @@ def save(self):
5353
"""
5454
if self.id:
5555
method = 'put'
56-
resource = self.RESOURCE.format(
57-
account_id=self.account.id, id=self.id)
56+
resource = self.RESOURCE.format(account_id=self.account.id, id=self.id)
5857
else:
5958
method = 'post'
60-
resource = self.RESOURCE_COLLECTION.format(
61-
account_id=self.account.id)
59+
resource = self.RESOURCE_COLLECTION.format(account_id=self.account.id)
6260

6361
params = self.to_params()
6462
if 'tweet_id' in params:
6563
params['tweet_ids'] = [params['tweet_id']]
6664
del params['tweet_id']
6765

6866
response = Request(
69-
self.account.client(), method,
67+
self.account.client, method,
7068
resource, params=params).perform()
7169

7270
self.from_response(response.body['data'])

twitter_ads/cursor.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
7575

7676
def __fetch_next(self):
7777
params = self._options.copy().update({'next_cursor': self._next_cursor})
78-
response = Request(
79-
self._client, self._method, self._resource, params=params).perform()
78+
response = Request(self._client, self._method, self._resource, params=params).perform()
8079
return self.__from_response(response)
8180

8281
def __from_response(self, response):

twitter_ads/http.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ def __enable_logging(self):
7878
logging.propagate = True
7979

8080
def __user_agent(self):
81-
python_verison = "{0}.{1}".format(
82-
sys.version_info.major, sys.version_info.minor)
83-
81+
python_verison = "{0}.{1}".format(sys.version_info.major, sys.version_info.minor)
8482
return 'twitter-ads version: {0} platform: Python {1} ({2}/{3})'.format(
8583
get_version(),
8684
python_verison,

twitter_ads/resource.py

+9-14
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,14 @@ def to_params(self):
7979
def all(klass, account, **kwargs):
8080
"""Returns a Cursor instance for a given resource."""
8181
resource = klass.RESOURCE_COLLECTION.format(account_id=account.id)
82-
request = Request(account.client(), 'get', resource, params=kwargs)
82+
request = Request(account.client, 'get', resource, params=kwargs)
8383
return Cursor(klass, request, init_with=[account])
8484

8585
@classmethod
8686
def load(klass, account, id, **kwargs):
8787
"""Returns an object instance for a given resource."""
8888
resource = klass.RESOURCE.format(account_id=account.id, id=id)
89-
response = Request(
90-
account.client(), 'get', resource, params=kwargs).perform()
89+
response = Request(account.client, 'get', resource, params=kwargs).perform()
9190

9291
return klass(account).from_response(response.body['data'])
9392

@@ -98,10 +97,8 @@ def reload(self, **kwargs):
9897
if not self.id:
9998
return self
10099

101-
resource = self.RESOURCE.format(
102-
account_id=self.account.id, id=self.id)
103-
response = Request(
104-
self.account.client(), 'get', resource, params=kwargs).perform()
100+
resource = self.RESOURCE.format(account_id=self.account.id, id=self.id)
101+
response = Request(self.account.client, 'get', resource, params=kwargs).perform()
105102

106103
self.from_response(response.body['data'])
107104

@@ -139,15 +136,13 @@ def save(self):
139136
"""
140137
if self.id:
141138
method = 'put'
142-
resource = self.RESOURCE.format(
143-
account_id=self.account.id, id=self.id)
139+
resource = self.RESOURCE.format(account_id=self.account.id, id=self.id)
144140
else:
145141
method = 'post'
146-
resource = self.RESOURCE_COLLECTION.format(
147-
account_id=self.account.id)
142+
resource = self.RESOURCE_COLLECTION.format(account_id=self.account.id)
148143

149144
response = Request(
150-
self.account.client(), method,
145+
self.account.client, method,
151146
resource, params=self.to_params()).perform()
152147

153148
self.from_response(response.body['data'])
@@ -158,7 +153,7 @@ def delete(self):
158153
presence of `object.id`.
159154
"""
160155
resource = self.RESOURCE.format(account_id=self.account.id, id=self.id)
161-
response = Request(self.account.client(), 'delete', resource).perform()
156+
response = Request(self.account.client, 'delete', resource).perform()
162157
self.from_response(response.body['data'])
163158

164159

@@ -202,5 +197,5 @@ def all_stats(klass, account, ids, metrics, **kwargs):
202197
params[klass.ANALYTICS_MAP[klass.__name__]] = ','.join(ids)
203198

204199
resource = klass.RESOURCE_STATS.format(account_id=account.id)
205-
response = Request(account.client(), 'get', resource, params=params).perform()
200+
response = Request(account.client, 'get', resource, params=params).perform()
206201
return response.body['data']

twitter_ads/targeting.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ class ReachEstimate(object):
1111

1212
@classmethod
1313
def fetch(klass, account, product_type, objective, user_id, **kwargs):
14-
params = {'product_type': product_type,
15-
'objective': objective,
16-
'user_id': user_id}
14+
params = {'product_type': product_type, 'objective': objective, 'user_id': user_id}
1715
params.update(kwargs)
1816

1917
resource = klass.RESOURCE.format(account_id=account.id)
20-
response = Request(
21-
account.client(), 'get', resource, params=params).perform()
18+
response = Request(account.client, 'get', resource, params=params).perform()
2219

2320
return response.body['data']

0 commit comments

Comments
 (0)