Created
November 9, 2017 18:18
-
-
Save lclemence/39173c890fb8eb035a25603a7dc15415 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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