Skip to content

Commit

Permalink
Merge pull request #498 from stripe/ob-better-classurl
Browse files Browse the repository at this point in the history
Better `classUrl()`
  • Loading branch information
ob-stripe committed Jul 19, 2018
2 parents dcd993f + 1ae9095 commit cc4e808
Show file tree
Hide file tree
Showing 11 changed files with 8 additions and 110 deletions.
28 changes: 3 additions & 25 deletions lib/ApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,6 @@ public function refresh()
return $this;
}

/**
* @return string The name of the class, with namespacing and underscores
* stripped.
*/
public static function className()
{
$class = get_called_class();
// Useful for namespaces: Foo\Charge
if ($postfixNamespaces = strrchr($class, '\\')) {
$class = substr($postfixNamespaces, 1);
}
// Useful for underscored 'namespaces': Foo_Charge
if ($postfixFakeNamespaces = strrchr($class, '')) {
$class = $postfixFakeNamespaces;
}
if (substr($class, 0, strlen('Stripe')) == 'Stripe') {
$class = substr($class, strlen('Stripe'));
}
$class = str_replace('_', '', $class);
$name = urlencode($class);
$name = strtolower($name);
return $name;
}

/**
* @return string The base URL for the given class.
*/
Expand All @@ -103,7 +79,9 @@ public static function baseUrl()
*/
public static function classUrl()
{
$base = static::className();
// Replace dots with slashes for namespaced resources, e.g. if the object's name is
// "foo.bar", then its URL will be "/v1/foo/bars".
$base = str_replace('.', '/', static::OBJECT_NAME);
return "/v1/${base}s";
}

Expand Down
11 changes: 0 additions & 11 deletions lib/ApplicationFee.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ class ApplicationFee extends ApiResource

const PATH_REFUNDS = '/refunds';

/**
* This is a special case because the application fee endpoint has an
* underscore in it. The parent `className` function strips underscores.
*
* @return string The name of the class.
*/
public static function className()
{
return 'application_fee';
}

/**
* @param array|null $params
* @param array|string|null $opts
Expand Down
11 changes: 0 additions & 11 deletions lib/CountrySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,4 @@ class CountrySpec extends ApiResource

use ApiOperations\All;
use ApiOperations\Retrieve;

/**
* This is a special case because the country specs endpoint has an
* underscore in it. The parent `className` function strips underscores.
*
* @return string The name of the class.
*/
public static function className()
{
return 'country_spec';
}
}
11 changes: 0 additions & 11 deletions lib/EphemeralKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ class EphemeralKey extends ApiResource
}
use ApiOperations\Delete;

/**
* This is a special case because the ephemeral key endpoint has an
* underscore in it. The parent `className` function strips underscores.
*
* @return string The name of the class.
*/
public static function className()
{
return 'ephemeral_key';
}

/**
* @param array|null $params
* @param array|string|null $opts
Expand Down
11 changes: 0 additions & 11 deletions lib/ExchangeRate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,4 @@ class ExchangeRate extends ApiResource

use ApiOperations\All;
use ApiOperations\Retrieve;

/**
* This is a special case because the exchange rates endpoint has an
* underscore in it. The parent `className` function strips underscores.
*
* @return string The name of the class.
*/
public static function className()
{
return 'exchange_rate';
}
}
4 changes: 2 additions & 2 deletions lib/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public static function baseUrl()
return Stripe::$apiUploadBase;
}

public static function className()
public static function classUrl()
{
return 'file';
return '/v1/files';
}
}
5 changes: 0 additions & 5 deletions lib/IssuerFraudRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,4 @@ class IssuerFraudRecord extends ApiResource

use ApiOperations\All;
use ApiOperations\Retrieve;

public static function classUrl()
{
return "/v1/issuer_fraud_records";
}
}
11 changes: 0 additions & 11 deletions lib/OrderReturn.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,4 @@ class OrderReturn extends ApiResource

use ApiOperations\All;
use ApiOperations\Retrieve;

/**
* This is a special case because the order returns endpoint has an
* underscore in it. The parent `className` function strips underscores.
*
* @return string The name of the class.
*/
public static function className()
{
return 'order_return';
}
}
11 changes: 0 additions & 11 deletions lib/PaymentIntent.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,6 @@ class PaymentIntent extends ApiResource
use ApiOperations\Retrieve;
use ApiOperations\Update;

/**
* This is a special case because the payment intents endpoint has an
* underscore in it. The parent `className` function strips underscores.
*
* @return string The name of the class.
*/
public static function className()
{
return 'payment_intent';
}

/**
* @param array|null $params
* @param array|string|null $options
Expand Down
4 changes: 3 additions & 1 deletion lib/SingletonApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ protected static function _singletonRetrieve($options = null)
*/
public static function classUrl()
{
$base = static::className();
// Replace dots with slashes for namespaced resources, e.g. if the object's name is
// "foo.bar", then its URL will be "/v1/foo/bar".
$base = str_replace('.', '/', static::OBJECT_NAME);
return "/v1/${base}";
}

Expand Down
11 changes: 0 additions & 11 deletions lib/SubscriptionItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,4 @@ class SubscriptionItem extends ApiResource
use ApiOperations\Delete;
use ApiOperations\Retrieve;
use ApiOperations\Update;

/**
* This is a special case because the subscription items endpoint has an
* underscore in it. The parent `className` function strips underscores.
*
* @return string The name of the class.
*/
public static function className()
{
return 'subscription_item';
}
}

0 comments on commit cc4e808

Please sign in to comment.