Jump to content

New extended MOFH API Client by Hostronavt Team


What do you think about MOFH Client by Hostronavt Team?  

4 members have voted

  1. 1. What do you think about MOFH Client by Hostronavt Team?

    • Awesome
    • Really good
    • Good
      0
    • Satisfactory
      0
    • Poor
      0


Recommended Posts

Why do you think the WM API is so poor? Or at least, why do you think a web scraper is better?

Sure, the reseller panel has a few more options than the API, and the output of the API is not always very consistent. But a web scraper sounds like it would suffer from these same issues but worse. APIs are at least designed to have consistent output for programmatic access, a guarantee you don't get with a web interface. iFastNet has a habit of making major changes without any notice (before or after), which would break your client completely.

As for your client itself, there are a few things which I would like to see or do differently:

  • Make it possible to pass a cookie jar to the client. You currently require a login request for every time a client instance is created, which requires a round trip to the API, which adds a lot of overhead to the web transaction this client is used in. In a production workload where you have a large volume of API calls, persisting and reusing the cookies in some kind of cache (configurable by the developer, hence the cookie jar implementation) will helps prevent MANY unnecessary calls to the panel and speed up your website. For inspiration, check how cookies are done with Guzzle.
  • Speaking of Guzzle: try it if you haven't already. It's great, much easier to use than curl_*. Which would be easy to use if combined with...
  • Composer. The best way to manage dependencies and class loading in PHP. Learn it, add support for it, your life will never be the same.
  • Another case of unnecessary HTTP calls: don't fetch the statistics every time after login. You don't need them every time, and now you're adding dozens of ms to every page load to get data which you may not need. This should be a separate API call.
  • Generally messy management of internal state. A good class should not require that implementations calls methods on that class in a specific order. If they do, that's typically a sign that your class boundaries are wrong. A good example is the Client::set function. You must create the client object first and then you MUST call this method first before you can use any of the other methods. Changing that to a constructor makes the class more fool proof and reduces the need for checks to make sure the set method was called first.
  • Speaking of internal state: most coding style guides demand that all object variables should be defined on the class, and not created on runtime. You set most values that way (except for a few booleans which determine whether these values were set - why not check the values themselves?).
  • Many functions have weird specs or don't do what I would expect them to do. I would change "initialize" to "login" (because logging in to the panel is what it does). "changePassword" changes the reseller password, not the user password. If findUsers has as first argument a string which has to be one of three hard coded values, why not create separate methods?
Link to post
Share on other sites
4 minutes ago, InfinityFree said:

Why do you think the WM API is so poor? Or at least, why do you think a web scraper is better?

Just because when I need client's email, I don't have any opportunity to get it in another way...

5 minutes ago, InfinityFree said:

As for your client itself, there are a few things which I would like to see or do differently

Okey, yeah, I see that there are problems in my code and it needs a lot of changes, thank you for you suggestions.

But, summing up, this is better than nothing?

Link to post
Share on other sites

Made some changes, thanks to @InfinityFree.

  1. Now script checks if cookie is valid and if it does doesn't login one more time.
  2. If you need reseller statistics variables, call Panel::getStatistics function first. It is for decreasing script running time.
  3. Now you don't have to initialize Panel and Client, just do like this:
$panel = new Panel($login, $password);
$client = new Client($panel, $user);

Waiting for next reviews 9_9

Latest version on https://github.com/hostronavt/mofh-client

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...