Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
Defined the Instagram service.
Browse files Browse the repository at this point in the history
(The account namespace is a little irregular, but I think it covers the prominent special cases.)
Shifted titles in the spec so errors make more sense.
Closes #9.
  • Loading branch information
globalspin committed Jul 8, 2013
1 parent 94971cb commit ae26454
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 6 deletions.
44 changes: 44 additions & 0 deletions lib/services/instagram_service.rb
@@ -0,0 +1,44 @@
class InstagramService < Service
def self.handles?(uri)
# Exclude help.instagram.com, blog.instagram.com, etc.
uri.host =~ /^instagram.com$/
end

def self.shortname
:instagram
end

def display_name
"#{account} on Instagram"
end

def account
/^\/(?<account>[\w-]+)/ =~ @uri.path


@exclude = ['p', 'popular', 'developer', 'press', 'about']
if @exclude.any? {|stopword| account == stopword}
account = nil
end

account
end

def service_url_example
"http://instagram.com/username"
end

def service_url_canonical
"http://instagram.com/#{account}"
end

private

def fetch_details
{
:account => account,
}
end
end

Service.register(:instagram, InstagramService)
40 changes: 34 additions & 6 deletions spec/models/service_spec.rb
Expand Up @@ -7,7 +7,7 @@
unknown.should be_nil
end

describe "Twitter plugin" do
describe "definition for Twitter" do

it "should be chosen for Twitter URLs" do
service = Service.find_by_url("http://twitter.com/usagov")
Expand All @@ -25,15 +25,15 @@
end
end

describe "Facebook plugin" do
describe "definition for Facebook" do

it "should be chosen for Facebook URLs" do
service = Service.find_by_url("http://facebook.com/USAgov")
service.shortname.should == :facebook
end
end

describe "Youtube plugin" do
describe "definition for Youtube" do

it "should be chosen for Youtube URLs" do
service = Service.find_by_url("http://www.youtube.com/USGovernment")
Expand All @@ -46,7 +46,7 @@
end
end

describe "Flickr plugin" do
describe "definition for Flickr" do

it "should be chosen for Flickr URLs" do
service = Service.find_by_url("http://www.flickr.com/groups/usagov/")
Expand Down Expand Up @@ -78,7 +78,7 @@
end
end

describe "Slideshare plugin" do
describe "definition for Slideshare" do

it "should be chosen for Slideshare URLs" do
service = Service.find_by_url("http://www.slideshare.net/nasa")
Expand All @@ -94,7 +94,7 @@
end
end

describe "Pinterest plugin" do
describe "definition for Pinterest" do
it "should be chosen for Pinterest URLs" do
service = Service.find_by_url("http://pinterest.com/michelleobama/")
service.shortname.should == :pinterest
Expand All @@ -105,4 +105,32 @@
service.account.should == 'michelleobama'
end
end

describe "definition for Instagram" do
it "should be chosen for Instagram URLs" do
service = Service.find_by_url("http://instagram.com/morgantown_wv/")
service.shortname.should == :instagram
end

it "should pick out the correct account name" do
service = Service.find_by_url("http://instagram.com/morgantown_wv/")
service.shortname.should == :instagram
service.account.should == 'morgantown_wv'

service = Service.find_by_url("http://instagram.com/cityofdetroit#")
service.shortname.should == :instagram
service.account.should == 'cityofdetroit'
end

it "should ignore system URLs" do
service = Service.find_by_url("http://instagram.com/about/us/")
service.account.should be_nil

service = Service.find_by_url("http://instagram.com/press/")
service.account.should be_nil

service = Service.find_by_url("http://blog.instagram.com/")
service.should be_nil
end
end
end

0 comments on commit ae26454

Please sign in to comment.