Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting droplet IP the right way? #76

Closed
Forge-Media opened this issue Jan 22, 2015 · 3 comments
Closed

Getting droplet IP the right way? #76

Forge-Media opened this issue Jan 22, 2015 · 3 comments
Assignees
Labels

Comments

@Forge-Media
Copy link

Hi

I'm having a little bit of an issue, depending on how a Droplet is made (Private networking on or off) the returned Network Array will be slightly different.

I currently get the Droplet's Public IP as such:

$ip = $userAtom->networks[0]->ipAddress (For a Droplet with Private networking turned off)
&
$ip = $userAtom->networks[1]->ipAddress (For a Droplet with Private networking turned on) 

This is causing me a headache, is there no way to get the Droplet's Public IP regardless of the Private networking status, with a single statement?

Just seems a little annoying that $userAtom->ipAddress does not work.

For instance:
using $userAtom->networks[1]. (with Private network off results in no IP being found).

@yassirh yassirh self-assigned this Jan 23, 2015
@yassirh yassirh added the bug label Jan 23, 2015
@toin0u
Copy link
Contributor

toin0u commented Jan 24, 2015

Thanks for reporting this @Forge-Media. We will look at it :)

@toin0u
Copy link
Contributor

toin0u commented Feb 2, 2015

Hi @Forge-Media

I've given a closer look at this. I don't think it's an issue because you can solve the problem which is, how to get the public IP of a given droplet.

This can be solved with something like:

$ips = array_map(function ($network) {
    if ('public' === $network->type) {
        return $network->ipAddress;
    }
}, $userAtom->networks);

echo $ips[0];

Of course, we could provide a helper function but I don't think it's the scope of the lib.

Anyway, hope that helps.

@toin0u toin0u added wontfix and removed bug labels Feb 2, 2015
@toin0u toin0u closed this as completed Feb 2, 2015
@lcanali
Copy link

lcanali commented Nov 2, 2017

explaining how to use the array_map function to get the pulbic ip's was very helpful. Please consider adding it to the "howto" page for others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants