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.

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

    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

    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

    Looks all right to me. I think I would have done a similar flow if not the same πŸ™‚

  • U03TXRYL7U7
    U03TXRYL7U7 Posts: 64 πŸ§‘πŸ»β€πŸš€ - Cadet

    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

    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

    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

    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

    In other words change your method to createBSLSprykerDataWriter and everything will be ok πŸ™‚

  • Chemaclass
    Chemaclass Tech Lead Spryker Solution Partner Posts: 213 πŸ§‘πŸ»β€πŸš€ - Cadet

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

  • U03TXRYL7U7
    U03TXRYL7U7 Posts: 64 πŸ§‘πŸ»β€πŸš€ - Cadet

    ok got it
    Thank you so much @UKEP86J66 and @U015S0C0V29 πŸ™‚