Skip to content

Commit 05d4df6

Browse files
committed
Reorganized code a little.
1 parent cc53af6 commit 05d4df6

File tree

1 file changed

+126
-126
lines changed

1 file changed

+126
-126
lines changed

src/Gwt/Client.php

Lines changed: 126 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -96,38 +96,6 @@ private function __construct()
9696
$this->_tables = $this->getAllowedTableNames();
9797
}
9898

99-
/**
100-
* Factory for new object
101-
*
102-
* @param string $login
103-
* @param string $pass
104-
* @return Gwt_Client
105-
*/
106-
public static function create($login, $pass)
107-
{
108-
$self = new self();
109-
return $self->logIn($login, $pass);
110-
}
111-
112-
/**
113-
* Get list of possible tables
114-
*
115-
* @return array
116-
*/
117-
public function getAllowedTableNames()
118-
{
119-
return array(
120-
'TOP_PAGES',
121-
'TOP_QUERIES',
122-
'CONTENT_ERRORS',
123-
'CONTENT_KEYWORDS',
124-
'INTERNAL_LINKS',
125-
'EXTERNAL_LINKS',
126-
'SOCIAL_ACTIVITY',
127-
'LATEST_BACKLINKS',
128-
);
129-
}
130-
13199
/**
132100
* Magic method to support shorthands for getTableData methods
133101
* getTopPagesTableData
@@ -168,103 +136,16 @@ function ($item)
168136
}
169137

170138
/**
171-
* Get data for requested table
172-
*
173-
* @param string $tableName
174-
* @param string $site
175-
* @param DateTime $dateStart
176-
* @param DateTime $dateEnd
177-
* @param string $lang
178-
* @return mixed
179-
*/
180-
public function getTableData($tableName)
181-
{
182-
switch ($tableName) {
183-
case 'CONTENT_ERRORS':
184-
case 'CONTENT_KEYWORDS':
185-
case 'INTERNAL_LINKS':
186-
case 'EXTERNAL_LINKS':
187-
case 'SOCIAL_ACTIVITY':
188-
case 'LATEST_BACKLINKS':
189-
$options = $this->getTableOptions($tableName);
190-
191-
$url = sprintf(
192-
self::SERVICEURI . $options['token_uri'] . '?hl=%s&siteUrl=%s',
193-
$this->getLanguage(), $this->getWebsite()
194-
);
195-
$token = $this->getToken($url, $options['token_delimiter'], $options['dl_uri']);
196-
197-
$url = sprintf(
198-
self::SERVICEURI . $options['dl_uri'] . '?hl=%s&siteUrl=%s&security_token=%s&prop=ALL&db=%s&de=%s&more=true',
199-
$this->getLanguage(), $this->getWebsite(), $token, $this->getDateStart()->format('Ymd'), $this->getDateEnd()->format('Ymd')
200-
);
201-
202-
$data = $this->getData($url);
203-
break;
204-
default: // TOP_QUERIES || TOP_PAGES
205-
$downloadUrls = $this->getDownloadUrls($this->getWebsite());
206-
$finalUrl = $downloadUrls[$tableName] . '&prop=ALL&db=%s&de=%s&more=true';
207-
$finalUrl = sprintf(
208-
$finalUrl,
209-
$this->getDateStart()->format('Ymd'), $this->getDateEnd()->format('Ymd')
210-
);
211-
$data = $this->getData($finalUrl);
212-
}
213-
214-
foreach ($this->_processors as $processor) {
215-
$data = $processor->process($data, $tableName);
216-
}
217-
218-
return $data;
219-
}
220-
221-
/**
222-
* Get options for given table
139+
* Factory for new object
223140
*
224-
* @throws Exception
225-
* @param string $tableName
226-
* @return array
141+
* @param string $login
142+
* @param string $pass
143+
* @return Gwt_Client
227144
*/
228-
private function getTableOptions($tableName)
145+
public static function create($login, $pass)
229146
{
230-
$options = array(
231-
'CONTENT_ERRORS' => array(
232-
'token_uri' => 'html-suggestions',
233-
'token_delimiter' => '\)',
234-
'dl_uri' => 'content-problems-dl',
235-
),
236-
'CONTENT_KEYWORDS' => array(
237-
'token_uri' => 'keywords',
238-
'token_delimiter' => '\)',
239-
'dl_uri' => 'content-words-dl',
240-
),
241-
'INTERNAL_LINKS' => array(
242-
'token_uri' => 'internal-links',
243-
'token_delimiter' => '\)',
244-
'dl_uri' => 'internal-links-dl',
245-
),
246-
'EXTERNAL_LINKS' => array(
247-
'token_uri' => 'external-links-domain',
248-
'token_delimiter' => '\)',
249-
'dl_uri' => 'external-links-domain-dl',
250-
),
251-
'SOCIAL_ACTIVITY' => array(
252-
'token_uri' => 'social-activity',
253-
'token_delimiter' => 'x26',
254-
'dl_uri' => 'social-activity-dl',
255-
),
256-
'LATEST_BACKLINKS' => array(
257-
'token_uri' => 'external-links-domain',
258-
'token_delimiter' => '\)',
259-
'dl_uri' => 'backlinks-latest-dl',
260-
),
261-
);
262-
263-
if (!array_key_exists($tableName, $options)) {
264-
throw new Exception('Requested options for unknown table.');
265-
}
266-
267-
return $options[$tableName];
147+
$self = new self();
148+
return $self->logIn($login, $pass);
268149
}
269150

270151
/**
@@ -376,6 +257,125 @@ public function getDateEnd()
376257
return $this->_dateEnd;
377258
}
378259

260+
/**
261+
* Get list of possible tables
262+
*
263+
* @return array
264+
*/
265+
public function getAllowedTableNames()
266+
{
267+
return array(
268+
'TOP_PAGES',
269+
'TOP_QUERIES',
270+
'CONTENT_ERRORS',
271+
'CONTENT_KEYWORDS',
272+
'INTERNAL_LINKS',
273+
'EXTERNAL_LINKS',
274+
'SOCIAL_ACTIVITY',
275+
'LATEST_BACKLINKS',
276+
);
277+
}
278+
279+
/**
280+
* Get data for requested table
281+
*
282+
* @param string $tableName
283+
* @param string $site
284+
* @param DateTime $dateStart
285+
* @param DateTime $dateEnd
286+
* @param string $lang
287+
* @return mixed
288+
*/
289+
public function getTableData($tableName)
290+
{
291+
switch ($tableName) {
292+
case 'CONTENT_ERRORS':
293+
case 'CONTENT_KEYWORDS':
294+
case 'INTERNAL_LINKS':
295+
case 'EXTERNAL_LINKS':
296+
case 'SOCIAL_ACTIVITY':
297+
case 'LATEST_BACKLINKS':
298+
$options = $this->getTableOptions($tableName);
299+
300+
$url = sprintf(
301+
self::SERVICEURI . $options['token_uri'] . '?hl=%s&siteUrl=%s',
302+
$this->getLanguage(), $this->getWebsite()
303+
);
304+
$token = $this->getToken($url, $options['token_delimiter'], $options['dl_uri']);
305+
306+
$url = sprintf(
307+
self::SERVICEURI . $options['dl_uri'] . '?hl=%s&siteUrl=%s&security_token=%s&prop=ALL&db=%s&de=%s&more=true',
308+
$this->getLanguage(), $this->getWebsite(), $token, $this->getDateStart()->format('Ymd'), $this->getDateEnd()->format('Ymd')
309+
);
310+
311+
$data = $this->getData($url);
312+
break;
313+
default: // TOP_QUERIES || TOP_PAGES
314+
$downloadUrls = $this->getDownloadUrls($this->getWebsite());
315+
$finalUrl = $downloadUrls[$tableName] . '&prop=ALL&db=%s&de=%s&more=true';
316+
$finalUrl = sprintf(
317+
$finalUrl,
318+
$this->getDateStart()->format('Ymd'), $this->getDateEnd()->format('Ymd')
319+
);
320+
$data = $this->getData($finalUrl);
321+
}
322+
323+
foreach ($this->_processors as $processor) {
324+
$data = $processor->process($data, $tableName);
325+
}
326+
327+
return $data;
328+
}
329+
330+
/**
331+
* Get options for given table
332+
*
333+
* @throws Exception
334+
* @param string $tableName
335+
* @return array
336+
*/
337+
private function getTableOptions($tableName)
338+
{
339+
$options = array(
340+
'CONTENT_ERRORS' => array(
341+
'token_uri' => 'html-suggestions',
342+
'token_delimiter' => '\)',
343+
'dl_uri' => 'content-problems-dl',
344+
),
345+
'CONTENT_KEYWORDS' => array(
346+
'token_uri' => 'keywords',
347+
'token_delimiter' => '\)',
348+
'dl_uri' => 'content-words-dl',
349+
),
350+
'INTERNAL_LINKS' => array(
351+
'token_uri' => 'internal-links',
352+
'token_delimiter' => '\)',
353+
'dl_uri' => 'internal-links-dl',
354+
),
355+
'EXTERNAL_LINKS' => array(
356+
'token_uri' => 'external-links-domain',
357+
'token_delimiter' => '\)',
358+
'dl_uri' => 'external-links-domain-dl',
359+
),
360+
'SOCIAL_ACTIVITY' => array(
361+
'token_uri' => 'social-activity',
362+
'token_delimiter' => 'x26',
363+
'dl_uri' => 'social-activity-dl',
364+
),
365+
'LATEST_BACKLINKS' => array(
366+
'token_uri' => 'external-links-domain',
367+
'token_delimiter' => '\)',
368+
'dl_uri' => 'backlinks-latest-dl',
369+
),
370+
);
371+
372+
if (!array_key_exists($tableName, $options)) {
373+
throw new Exception('Requested options for unknown table.');
374+
}
375+
376+
return $options[$tableName];
377+
}
378+
379379
/**
380380
* Add data processor
381381
*

0 commit comments

Comments
 (0)