Skip to content

Include the "Services" API endpoint?  #2

@phillipadsmith

Description

@phillipadsmith

Hey there Greg,

I'm doing some more work on Embed.ly and noticed that they have a "services" end point, which lets you query the providers they support: http://embed.ly/docs/endpoints/1/service#s=service

I wanted a way to quickly check the provided URL against Embed.ly's supported services, so I'm doing it like this:

my $url = shift @ARGV;

my $response = HTTP::Tiny->new->get('http://api.embed.ly/1/services/ruby');

die "Failed!\n" unless $response->{success};

my $json  = decode_json $response->{content};

foreach my $provider ( @$json ) {
    my @urls;
    foreach my $reg ( @{ $provider->{'regex'} } ) {
        push @urls, $reg;
    }
    my $regex = join("|", @urls);
    # Run the input URL through the regex of all possible URLs
    if ( $url =~ /$regex/ ) {
    # Report back on a match
        say 'Got a match on ', $provider->{'name'};
        return $provider;
    }
}

I was about to implement that, but then I wondered about integrating with the Webservice::Embedly module so that I could simply do this:

my $e = new WebService::Embedly(key => "api key goes here");
my $r = $e->service_match("http://vimeo.com/18150336");

Or something along those lines.

What do you think?

UPDATE: Oh, yes, sorry, I forget to mention that I'm just grabbing the Ruby regular expressions because they're Perl-compatible and, thus, lets me quickly build a regex for all of their supported service URLs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions