{"action":"opened","issue":{"url":"https://api.github.com/repos/twilio/twilio-ruby/issues/198","repository_url":"https://api.github.com/repos/twilio/twilio-ruby","labels_url":"https://api.github.com/repos/twilio/twilio-ruby/issues/198/labels{/name}","comments_url":"https://api.github.com/repos/twilio/twilio-ruby/issues/198/comments","events_url":"https://api.github.com/repos/twilio/twilio-ruby/issues/198/events","html_url":"https://github.com/twilio/twilio-ruby/issues/198","id":153371752,"number":198,"title":"Media objects should include a way to get the final resources URL","user":{"login":"markquezada","id":154123,"avatar_url":"https://avatars.githubusercontent.com/u/154123?v=3","gravatar_id":"","url":"https://api.github.com/users/markquezada","html_url":"https://github.com/markquezada","followers_url":"https://api.github.com/users/markquezada/followers","following_url":"https://api.github.com/users/markquezada/following{/other_user}","gists_url":"https://api.github.com/users/markquezada/gists{/gist_id}","starred_url":"https://api.github.com/users/markquezada/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markquezada/subscriptions","organizations_url":"https://api.github.com/users/markquezada/orgs","repos_url":"https://api.github.com/users/markquezada/repos","events_url":"https://api.github.com/users/markquezada/events{/privacy}","received_events_url":"https://api.github.com/users/markquezada/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-05-06T03:33:47Z","updated_at":"2016-05-06T03:33:47Z","closed_at":null,"body":"Using 5.0.0.rc4\r\n\r\nThis might be considered a feature request but I find the absence of a way to get a media object's final URL surprising.\r\n\r\nThis may be a limitation with the [Twilio Media API][media-api] itself but there is no direct way to get the final URL for media through the object returned from this gem. The problem is exacerbated by the fact that the URI returned via the API can redirect several times before reaching the final destination.\r\n\r\n[media-api]: https://www.twilio.com/docs/api/rest/media\r\n\r\nI've resorted to using this custom class:\r\n\r\n```ruby\r\nclass TwilioMedium\r\n  delegate :content_type, to: :@twilio_medium_instance\r\n  delegate :delete, to: :@twilio_medium_context\r\n\r\n  def initialize(twilio_medium_context)\r\n    @twilio_medium_context = twilio_medium_context\r\n    @twilio_medium_instance = twilio_medium_context.fetch\r\n  end\r\n\r\n  def url\r\n    @url ||= expanded_url\r\n  end\r\n\r\nprivate\r\n  def uri\r\n    @twilio_medium_instance.uri.gsub('.json', '')\r\n  end\r\n\r\n  def raw_url\r\n    \"https://api.twilio.com#{uri}\"\r\n  end\r\n\r\n  def expanded_url\r\n    result = Curl::Easy.perform(raw_url) do |curl|\r\n      curl.head = true\r\n      curl.follow_location = true\r\n    end\r\n    result.last_effective_url\r\n  end\r\nend\r\n```\r\n(Splitting context from instance is required due to the bug reported in #197)\r\n\r\nThis allows me to do this:\r\n\r\n```ruby\r\nmedia_context = $twilio.account.messages(@message_sid).media(@medium_sid)\r\ntwilio_medium = TwilioMedium.new(twilio_medium_context)\r\ntwilio_medium.url\r\n=> https://api.twilio.com/2010-04-01/Accounts/AC.../Message/MM.../Media/ME557ce644e5ab84fa21cc21112e22c485\r\n```"}}