Permalink
Browse files

fix Instagram username discovery

  • Loading branch information...
1 parent f38e4aa commit 8de62a3e4fe0f6c9db17438cbf0cc0dc9ef18c72 @mislav committed Feb 11, 2013
Showing with 8 additions and 6 deletions.
  1. +1 −1 app.rb
  2. +7 −5 models.rb
View
2 app.rb
@@ -388,7 +388,7 @@ def photos_by_tag(tag)
end
redirect user_url(user.username)
else
- status 500
+ status 404
haml "%h1 Sorry\n%p The user ID couldn't be discovered on this page.\n" +
"%p <strong>Note:</strong> you <em>must</em> have a profile picture on Instagram."
end
View
@@ -141,11 +141,12 @@ module Instagram
module Discovery
def self.discover_user_id(url)
url = URI.parse url unless url.respond_to? :hostname
+ url.hostname = 'instagram.com' if url.hostname == 'instagr.am'
$1.to_i if get_url(url) =~ %r{profiles/profile_(\d+)_}
end
LinkRe = %r{https?://t.co/[\w-]+}
- PermalinkRe = %r{https?://instagr\.am/p/[\w-]+/?}
+ PermalinkRe = %r{https?://(instagr\.am|instagram\.com)/p/[\w-]+/?}
TwitterSearch = URI.parse 'http://search.twitter.com/search.json'
UserInfo = URI.parse 'http://api.twitter.com/1/users/show.json'
@@ -154,10 +155,11 @@ def self.search_twitter(username)
url.query = Rack::Utils.build_query q: "from:#{username} instagr.am"
data = JSON.parse get_url(url)
data['results'].each do |tweet|
- if tweet['text'] =~ LinkRe and resolve_shortened($&) =~ PermalinkRe
- link = $&
- user_id = tweet['user'] ? tweet['user']['id'] : twitter_user(username)['id'] rescue nil
- return [link, user_id]
+ if tweet['text'] =~ LinkRe
+ if (link = resolve_shortened($&)) =~ PermalinkRe
+ user_id = tweet['user'] ? tweet['user']['id'] : twitter_user(username)['id'] rescue nil
+ return [link, user_id]
+ end
end
end
return nil

0 comments on commit 8de62a3

Please sign in to comment.