Giter Site home page Giter Site logo

Comments (3)

ryanwinchester avatar ryanwinchester commented on May 17, 2024

Yeah I'm not familiar with how the oauth stuff works since I just use an api key.

If you think it would be helpful, we could do that, but maybe just move checking if the client is passed, to the constructor like this?

    /**
     * @param string|null $apiKey
     * @param bool $oauth
     * @param HttpClient $client
     * @throws HubSpotException
     */
    protected function __construct($apiKey = null, $oauth = false, HttpClient $client = null)
    {
        $this->oauth = $oauth;
        $this->apiKey = $apiKey ?: getenv('HUBSPOT_API_KEY');
        if (empty($this->apiKey)) {
            throw new HubSpotException("You must provide a HubSpot api key.");
        }
        $this->client = $client ?: new Client;
    }

    /**
     * @param string $access_token HubSpot oauth access token
     * @param HttpClient $client An Http Client
     * @return static
     */
    public static function makeWithToken($access_token, HttpClient $client = null)
    {
        return new static($access_token, true, $client);
    }

    /**
     * @param string $name
     * @param null $arguments
     * @return mixed
     * @throws HubSpotException
     */
    public function __call($name, $arguments = null)
    {
        $apiClass = $this->getApiClassName($name);
        if (! (new \ReflectionClass($apiClass))->isInstantiable()) {
            throw new HubSpotException("Target [$apiClass] is not instantiable.");
        }

        return new $apiClass($this->apiKey, $this->client, $this->oauth);
    }

from hubspot-php.

fyfey avatar fyfey commented on May 17, 2024

Yeah that makes sense, it means there's only ever one client per HubSpotService too, which is a bit more efficient.

from hubspot-php.

ryanwinchester avatar ryanwinchester commented on May 17, 2024

👍

from hubspot-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.