Calling Developers!
We are reenergizing our code contribution process! Learn More

What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hi Team Please let me know which layer should be used to consume third-party APIs.

Options
U03TXRYL7U7
U03TXRYL7U7 Posts: 64 🧑🏻‍🚀 - Cadet

Hi Team
Please let me know which layer should be used to consume third-party APIs.

Comments

  • Chemaclass
    Chemaclass Tech Lead Spryker Solution Partner Posts: 213 🧑🏻‍🚀 - Cadet
    edited September 2022
    Options

    It depends on what type of 3rd party. It could be Zed or Service, depending on what do you want to do with that API.

  • U03TXRYL7U7
    U03TXRYL7U7 Posts: 64 🧑🏻‍🚀 - Cadet
    Options

    With that API , we want to save Data in Database. and simultaneously publish and synchronize to RabbitMq
    Currently, flow going from Pyz/Zed/Module/Communication/Console Command to Business Facade and then from facade to Business Factory and there depends on parameter, new business model objects are getting instantiated. In those business models, third party API is consumed and API response is getting saved to Database
    Please confirm the flow.

  • Chemaclass
    Chemaclass Tech Lead Spryker Solution Partner Posts: 213 🧑🏻‍🚀 - Cadet
    Options

    Looks all right to me. I think I would have done a similar flow if not the same 🙂

  • U03TXRYL7U7
    U03TXRYL7U7 Posts: 64 🧑🏻‍🚀 - Cadet
    Options

    ok thanks.🙂
    One more point if I am running code sniffer architecure on my module then I am getting
    method in factories must not contain a new keyword violation. Can you please help me how to resolve the above violation.

  • Chemaclass
    Chemaclass Tech Lead Spryker Solution Partner Posts: 213 🧑🏻‍🚀 - Cadet
    edited September 2022
    Options

    That’s right. you need to extract in “private methods”, one “new” per method. For example:

    # Spryker\Zed\Cms\Business\CmsBusinessFactory:110
    public function createGlossaryKeyMappingManager(): GlossaryKeyMappingManagerInterface
    {
        return new GlossaryKeyMappingManager(
            $this->getGlossaryFacade(),
            $this->getQueryContainer(),
            $this->createTemplateManager(),
            $this->createPageManager()
        );
    }
    [...]
    // public/private depends on the scope of the function itself, of course
    public function createTemplateManager(): TemplateManagerInterface
    {
        return new TemplateManager(
            $this->getQueryContainer(),
            $this->getConfig(),
            $this->createFinder()
        );
    }
    [...]
    # etc
    

    you can see, there is only one new keyword on each factory method 🙂

  • U03TXRYL7U7
    U03TXRYL7U7 Posts: 64 🧑🏻‍🚀 - Cadet
    Options

    Please look into that, I found some contradiction here. If I have written only one new statement in factory method then also it is giving error
    if I have written following function:
    public function getBSLSprykerDataWriter()
    {
    return new BSLSprykerDataMappingWriter();
    }
    then also c:s:a giving following error

    Factories: The factory method Pyz\Zed\BSLSprykerDataMapping\Business\BSLSprykerDataMappingBusinessFactory::getBSLSprykerDataWriter() contains 1 new statements which violates rule "A get*() method in factories must not contain a new keyword."

  • UKEP86J66
    UKEP86J66 Posts: 208 🧑🏻‍🚀 - Cadet
    Options

    Factories have a naming convention. You must use the create prefix if you are using new. You should only use the get prefix if you are fetching an instance from the container.

  • UKEP86J66
    UKEP86J66 Posts: 208 🧑🏻‍🚀 - Cadet
    Options

    In other words change your method to createBSLSprykerDataWriter and everything will be ok 🙂

  • Chemaclass
    Chemaclass Tech Lead Spryker Solution Partner Posts: 213 🧑🏻‍🚀 - Cadet
    Options

    Exactly.
    • createFoo(): Foo -> needs a new
    • getBar(): Bar -> no new keyword -> this uses the DependencyProvider from the Factory

  • U03TXRYL7U7
    U03TXRYL7U7 Posts: 64 🧑🏻‍🚀 - Cadet
    Options

    ok got it
    Thank you so much @UKEP86J66 and @U015S0C0V29 🙂