altmetric / embiggen

A Ruby library to expand shortened URLs
https://rubygems.org/gems/embiggen
MIT License
124 stars 6 forks source link

perma.cc support #36

Open Denubis opened 5 years ago

Denubis commented 5 years ago

Hi Folks...

I'm wondering if you could add perma.cc to embiggen. While perma.cc isn't strictly a link shortener, for purposes of altmetrics, it's usually desirable to look at the parent page.

def parsePermaCC(incomingurl)
    if incomingurl.include? "perma.cc"
        archive = incomingurl.split("perma.cc/")[1]

        # https://perma.cc/docs/developer#get-one-archive
        url = "https://api.perma.cc/v1/public/archives/#{archive}"
        uri = URI(url)
        response = JSON.parse(Net::HTTP.get(uri))
        return URI(response['url'])
    else
        return incomingurl
    end
end

this is some ruby I hacked up (I usually code in python, so... this is probably all sorts of badwrong) which takes a uri and finds the perma.cc parent url or just passes the url through if not perma.cc'd. I'm thinking an invocation for this can go into follow()

Let me know if this is something you folks would like to include here, or if I should go raise a ticket in altmetric for this.

Cheers, -Brian

jbilbo commented 5 years ago

Hey Brian, I'd like to add support for it into Altmetric indeed, I have my reckons about putting it here on Embiggen though. Will discuss further with the team and let you know. Thanks for sending!

Denubis commented 5 years ago

No worries. It isn't an amazing fit for enbiggen since it isn't... quite a link shortener. Let me know how I can help though. Hopefully my proof of concept above is useful. Oh, and I opened a ticket with support on your end: 90862