Skip to content

Instantly share code, notes, and snippets.

@lclemence
Created November 9, 2017 18:18
Show Gist options
  • Save lclemence/39173c890fb8eb035a25603a7dc15415 to your computer and use it in GitHub Desktop.
Save lclemence/39173c890fb8eb035a25603a7dc15415 to your computer and use it in GitHub Desktop.
Not working as the referer url is not matching!
---
gem 'google-api-client'
---
require 'google/apis/urlshortener_v1'
Urlshortener = Google::Apis::UrlshortenerV1
class ThirdPartyApi::Google::UrlShortener
def initialize
@shortener = Urlshortener::UrlshortenerService.new
@shortener.authorization = nil
@shortener.key = Rails.application.secrets.google['api_key']
@shortener.request_options = @shortener.request_options.merge(header: ["Referer: #{Settings.koolicar.host}"])
end
def shorten(url)
response = Urlshortener::Url.new(long_url: url)
shortened_url = @shortener.insert_url(response).try(:id)
Rollbar.error("Failed to generate a shorten url for #{url}") unless shortened_url.present?
shortened_url
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment