CommitMsgUrlShortener::Service.define do |commit_message| def call_googl_api long_url error_safe_request do uri = URI 'https://www.googleapis.com/urlshortener/v1/url' http = Net::HTTP.new uri.host, 443 http.use_ssl = true http.read_timeout = 3 http.verify_mode = OpenSSL::SSL::VERIFY_NONE resp = http.post uri.path, "{'longUrl': '#{long_url}'}", {"content-type" => "application/json"} json = JSON.parse resp.body json['id'] end end each_long_url(commit_message) {|url| call_googl_api url} end