Skip to content

Commit

Permalink
feat: Move v2 translate client (#2423)
Browse files Browse the repository at this point in the history
* feat: Move v2 translate client

* address review

* add files to style check exclude

* ignore coverage

* fix ignore
  • Loading branch information
jdpedrie authored and dwsupplee committed Oct 28, 2019
1 parent 0b90be0 commit 4e9182d
Show file tree
Hide file tree
Showing 18 changed files with 647 additions and 506 deletions.
3 changes: 3 additions & 0 deletions Core/src/Testing/Snippet/Coverage/Coverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class Coverage
'/\\\GcTestListener/',
'/\\\Google\\\Cloud\\\Core\\\Logger/',
'/\\\Google\\\Cloud\\\Core\\\PhpArray/',
'/\\\Google\\\Cloud\\\Translate\\\TranslateClient/',
'/\\\Google\\\Cloud\\\Translate\\\Connection\\\Rest/',
'/\\\Google\\\Cloud\\\Translate\\\Connection\\\ConnectionInterface/',
];

/**
Expand Down
16 changes: 12 additions & 4 deletions Core/src/Testing/Snippet/Coverage/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,18 @@ public function snippets(array $classes)
{
$snippets = [];
foreach ($classes as $class) {
$snippets = array_merge(
$snippets,
$this->parser->allExamples(new \ReflectionClass($class))
);
try {
$snippets = array_merge(
$snippets,
$this->parser->allExamples(new \ReflectionClass($class))
);
} catch (\ReflectionException $e) {
throw new \RuntimeException(sprintf(
"Error in class %s: %s",
$class,
$e->getMessage()
));
}
}

return $snippets;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ $ composer require google/cloud-tasks
```php
require 'vendor/autoload.php';

use Google\Cloud\Translate\TranslateClient;
use Google\Cloud\Translate\V2\TranslateClient;

$translate = new TranslateClient([
'key' => 'your_key'
Expand Down
2 changes: 1 addition & 1 deletion Translate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ on authenticating your client. Once authenticated, you'll be ready to start maki
```php
require 'vendor/autoload.php';

use Google\Cloud\Translate\TranslateClient;
use Google\Cloud\Translate\V2\TranslateClient;

$translate = new TranslateClient([
'key' => 'your_key'
Expand Down
37 changes: 17 additions & 20 deletions Translate/src/Connection/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,26 @@
* limitations under the License.
*/

namespace Google\Cloud\Translate\Connection;
//@codeCoverageIgnoreStart

/**
* Represents a connection to
* [Google Cloud Translation](https://cloud.google.com/translation/).
*/
interface ConnectionInterface
{
/**
* @param array $args
* @return array
*/
public function listDetections(array $args = []);
namespace Google\Cloud\Translate\Connection;

/**
* @param array $args
* @return array
*/
public function listLanguages(array $args = []);
use Google\Cloud\Translate\V2;

if (false) {
/**
* @param array $args
* @return array
* This class is deprecated. Use Google\Cloud\Translate\V2\Connection\ConnectionInterface instead.
* @deprecated
*/
public function listTranslations(array $args = []);
interface ConnectionInterface {}
}

class_exists(V2\ConnectionInterface::class);
@trigger_error(
'Google\Cloud\Translate\ConnectionInterface is deprecated and will be ' .
'removed in a future release. Use ' .
'Google\Cloud\Translate\V2\ConnectionInterface instead',
E_USER_DEPRECATED
);

//@codeCoverageIgnoreEnd
75 changes: 15 additions & 60 deletions Translate/src/Connection/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,71 +15,26 @@
* limitations under the License.
*/

//@codeCoverageIgnoreStart

namespace Google\Cloud\Translate\Connection;

use Google\Cloud\Core\RequestBuilder;
use Google\Cloud\Core\RequestWrapper;
use Google\Cloud\Core\RestTrait;
use Google\Cloud\Core\UriTrait;
use Google\Cloud\Translate\TranslateClient;

/**
* Implementation of the
* [Google Cloud Translation REST API](https://cloud.google.com/translation/docs/how-to).
*/
class Rest implements ConnectionInterface
{
use RestTrait;
use UriTrait;
use Google\Cloud\Translate\V2;

if (false) {
/**
* This class is deprecated. Use Google\Cloud\Translate\V2\Connection\Rest instead.
* @deprecated
*/
const BASE_URI = 'https://translation.googleapis.com/language/translate/';

const DEFAULT_API_ENDPOINT = 'https://translation.googleapis.com';

/**
* @param array $config
*/
public function __construct(array $config = [])
{
$config += [
'serviceDefinitionPath' => __DIR__ . '/ServiceDefinition/translate-v2.json',
'componentVersion' => TranslateClient::VERSION
];

$this->setRequestWrapper(new RequestWrapper($config));
$this->setRequestBuilder(new RequestBuilder(
$config['serviceDefinitionPath'],
$this->getApiEndpoint(self::DEFAULT_API_ENDPOINT, $config)
));
}

/**
* @param array $args
* @return array
*/
public function listDetections(array $args = [])
{
return $this->send('detections', 'detect', $args);
}
class Rest {}
}

/**
* @param array $args
* @return array
*/
public function listLanguages(array $args = [])
{
return $this->send('languages', 'list', $args);
}
class_exists(V2\Rest::class);
@trigger_error(
'Google\Cloud\Translate\Rest is deprecated and will be ' .
'removed in a future release. Use ' .
'Google\Cloud\Translate\V2\Rest instead',
E_USER_DEPRECATED
);

/**
* @param array $args
* @return array
*/
public function listTranslations(array $args = [])
{
return $this->send('translations', 'translate', $args);
}
}
//@codeCoverageIgnoreEnd
Loading

0 comments on commit 4e9182d

Please sign in to comment.