CommitMsgUrlShortener::Service.define do |commit_message| def call_googl_api long_url error_safe_request do uri = URI 'http://svel.to/links' http = Net::HTTP.new uri.host http.read_timeout = 3 resp = http.post uri.path, "{'link': '#{long_url}'}", {"content-type" => "application/json", "accept" => "application/json"} json = JSON.parse resp.body json['url'] end end each_long_url(commit_message) {|url| call_googl_api url} end