Class: Libproxy::ProxyFactory

Inherits:
Object
  • Object
show all
Defined in:
ext/libproxy/libproxy_ext.c

Instance Method Summary collapse

Constructor Details

#Libproxy::ProxyFactory.newObject

Returns a new Libproxy::ProxyFactory object.

Libproxy::ProxyFactory.new #=> #<Libproxy::ProxyFactory:0x007fde591a6500>


31
32
33
34
35
36
37
38
39
40
41
42
# File 'ext/libproxy/libproxy_ext.c', line 31

static VALUE
rb_proxy_factory_initialize(VALUE self)
{
    pxProxyFactory *pf = px_proxy_factory_new();
    if (pf == NULL) {
        rb_raise(rb_eLibproxyError, "px_proxy_factory_new");
    }

    DATA_PTR(self) = pf;

    return self;
}

Instance Method Details

#proxies(url) ⇒ Array

Returns a list of proxies to use for url as an array.

Libproxy::ProxyFactory.new.proxies("http://example.com")
#=> ["socks://proxy.example.com:1080", "socks5://proxy.example.com:1080"]

Returns:

  • (Array)


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'ext/libproxy/libproxy_ext.c', line 59

static VALUE
rb_proxy_factory_proxies(VALUE self, VALUE url)
{
    pxProxyFactory *pf = check_proxy_factory(self);
    char **proxies;
    int i;
    VALUE ret;

    StringValue(url);

    proxies = px_proxy_factory_get_proxies(pf, RSTRING_PTR(url));
    if (proxies == NULL) {
        rb_raise(rb_eLibproxyError, "px_proxy_factory_get_proxies: url='%s'", RSTRING_PTR(url));
    }

    ret = rb_ary_new();
    for (i = 0; proxies[i]; i++) {
        rb_ary_push(ret, rb_str_new_cstr(proxies[i]));
        free(proxies[i]);
    }

    free(proxies);

    return ret;
}