Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to not use static method calls (quick showcase) #687

Closed
Korbeil opened this issue Aug 8, 2019 · 1 comment
Closed

Refactor to not use static method calls (quick showcase) #687

Korbeil opened this issue Aug 8, 2019 · 1 comment

Comments

@Korbeil
Copy link

Korbeil commented Aug 8, 2019

Since we can't reply to #124 (@ob-stripe you can remove this issue if you want after reading it, I just wanted to show some research I've made around non-static methods generation)

I created a quick issue to showcase of Jane based on Stripe OpenAPI specification that I created some months ago for my own usage: https://github.com/Korbeil/stripe-php-api/

This is not battle tested and strongly depends on OpenAPI definition quality but this is a very easy way to generate a Client based on an OpenAPI spec.

We already made a client for the Slack API with their OpenAPI spec: https://github.com/jolicode/slack-php-api with Jane which is referenced by Slack as one of the Client to use when using PHP https://api.slack.com/community.

@Korbeil Korbeil changed the title [Feature] Refactor to not use static method calls (quick showcase) Refactor to not use static method calls (quick showcase) Aug 8, 2019
@ob-stripe
Copy link
Contributor

Hi @Korbeil, thanks for sharing this! This looks very interesting, and close in concept to what we're trying to achieve.

As I briefly mentioned in the other thread, we're in the process of rolling out our own OpenAPI-based client library generator. We've chosen to write our own generator instead of using one of the many existing ones because 1/ we want to maintain a single codebase that will let us generate all our different client libraries (seven different programming languages at the moment, and we're looking to add more as the project matures) and 2/ we wanted to be able to generate libraries with APIs that are as close as possible to the existing manually written libraries.

Of course this would not prevent us from adding new APIs, i.e. in the case of PHP the plan is to add new non-static methods while still keeping backwards compatibility with the existing methods. It's too early to discuss any specific technical details, but I imagine it will look something like this:

// Existing static APIs, would still work
\Stripe\Stripe::setApiKey("sk_test_123");
$customer = \Stripe\Customer::retrieve("cus_123");

// New non-static APIs
$stripe = new \Stripe\StripeClient("sk_test_123");
$customer = $stripe->customers->retrieve("cus_123");

where $stripe->customers would return an instance of a new CustomerService class that holds non-static methods for customer-related API requests.

I'm closing the issue but keeping this thread open, so feel free to reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants