thinkshout/mailchimp-api-php

Abstract Away HTTP Client Dependency

Closed this issue ยท 12 comments

w3guy commented

I am suggesting any HTTP client to be used should be it's own (wrapper) class that extends an interface which contains a handleRequest() method that all HTTP client must implement.

The following code

if ($this->use_curl) {
   return $this->handleRequestCURL($method, $this->endpoint . $path, $options, $parameters, $returnAssoc);
    }
    else {
      return $this->handleRequest($method, $this->endpoint . $path, $options, $parameters, $returnAssoc);
    }

will now become just

   return $this->handleRequest($method, $this->endpoint . $path, $options, $parameters, $returnAssoc);

By doing this, therefore means an instance of an HTTP client will be passed to the MailChimp class constructor or a special method to include the HTTP client dependency.

Why am i proposing this?

Because in WordPress, it is bundled with it own HTTP client and would love to use that instead.

That's a good suggestion. We're already part of the way there with the cURL client being its own class.

I'll spend some time on this next week.

w3guy commented

Great work. Let me know if you need my help / input.

w3guy commented

Need my help with this?

That would be appreciated if you have time. Unfortunately I haven't had chance to get to it.

@collizo4sky How does this look?

master...http-client

The changes are on the http-client branch.

I wanted to get your opinion on this before merging it in.

w3guy commented

Now that's what I am talking about. Great job.

Could you please add a method for setting httpclient after class instantiation?

Off topic, but out of curiosity, are you using this in an open-source WP plugin? Asking because we love WP :)

w3guy commented

It's actually a commercial plugin that will have a free/lite version at WordPress.org repository.

I will contribute back the WP HTTP API client to this repo once i have successfully converted from curl to it when this branch is tagged/released.

That's fantastic. you should link us to you're project when you're ready to tell the world :)

w3guy commented

Sure thing.

I'll get that client set function added today.

w3guy commented

Sorry this is coming late, I last month launch my project utilizing this excellent MailChimp class. I called it MailOptin with the lite/free version at https://wordpress.org/plugins/mailoptin/