ASIS (Advanced Social Image Search) indexes Flickr and Instagram images and provides a search API across both indexes.
You are reading documentation for ASIS API v1.
The server code that runs the image search component of DigitalGov Search is here on Github. Fork this repo to add features like additional datasets, or to fix bugs.
This code is currently tested against Ruby 2.1.
- Copy
instagram.yml.exampletoinstagram.ymland update the fields with your Instagram credentials. - Copy
flickr.yml.exampletoflickr.ymland update the fields with your Flickr credentials.
We use bundler to manage gems. You can install bundler and other required gems like this:
gem install bundler
bundle install
We're using Elasticsearch (>= 1.3.0) for fulltext search. On a Mac, it's easy to install with Homebrew.
$ brew install elasticsearch
Otherwise, follow the instructions to download and run it.
Sidekiq (see below) uses Redis, so make sure you have that installed and running.
You can bootstrap the system with some government Flickr/Instagram profiles and MRSS feeds to see the system working.
Sample lists are in config/instagram_profiles.csv and config/flickr_profiles.csv and config/mrss_profiles.csv.
bundle exec rake oasis:seed_profiles
You can keep the indexes up to date by periodically refreshing the last day's images. To do this manually via the Rails console:
FlickrPhotosImporter.refresh
InstagramPhotosImporter.refresh
MrssPhotosImporter.refresh
The Capistrano deploy script has whenever hooks so this refresh happens automatically via cron in your production environment.
Fire up a server and try it all out.
bundle exec rails s
Here are the profiles you have just bootstrapped. Note: Chrome does a nice job of pretty-printing the JSON response.
http://localhost:3000/api/v1/instagram_profiles.json
http://localhost:3000/api/v1/flickr_profiles.json
http://localhost:3000/api/v1/mrss_profiles.json
You can add a new profile manually via the REST API:
curl -XPOST "http://localhost:3000/api/v1/instagram_profiles.json?username=deptofdefense&id=542835249"
curl -XPOST "http://localhost:3000/api/v1/flickr_profiles.json?name=commercegov&id=61913304@N07&profile_type=user"
curl -XPOST "http://localhost:3000/api/v1/mrss_profiles.json?url=http%3A%2F%2Fremotesensing.usgs.gov%2Fgallery%2Frss.php%3Fcat%3Dall"
MRSS profiles work a little differently than Flickr and Instagram profiles. When you create the MRSS profile, Oasis assigns a short name to it that you will use when performing searches. The JSON result from the POST request will look something like this:
{
"created_at": "2014-10-26T18:25:21.167+00:00",
"updated_at": "2014-10-26T18:25:21.173+00:00",
"name": "72",
"id": "http:\/\/remotesensing.usgs.gov\/gallery\/rss.php?cat=all"
}
We use Sidekiq for job processing. You can see all your Flickr and Instagram jobs queued up here:
Kick off the indexing process:
bundle exec sidekiq
In the Rails console, you can query each index manually using the Elasticsearch Query DSL:
bin/rails c
InstagramPhoto.count
FlickrPhoto.count
MrssPhoto.count
InstagramPhoto.all(query:{term:{username:'usinterior'}})
FlickrPhoto.all(query:{term:{owner:'41555360@n03'}})
MrssPhoto.all(query:{term:{mrss_url:'http://remotesensing.usgs.gov/gallery/rss.php?cat=all'}})
These parameters are accepted for the blended search API:
- query
- flickr_groups (comma separated)
- flickr_users (comma separated)
- instagram_profiles (comma separated)
- mrss_names (comma separated list of Oasis-assigned names)
- size
- from
The top level JSON contains these fields:
totaloffsetsuggestion: The overridden spelling suggestionresults
Each result contains these fields:
type: FlickrPhoto | InstagramPhototitleurlthumbnail_urltaken_at
We support API versioning with the JSON format. The current version is v1. You can specify a specific JSON API version like this:
curl "http://localhost:3000/api/v1/image.json?flickr_groups=1058319@N21&flickr_users=35067687@n04,24662369@n07&instagram_profiles=nasa&mrss_names=72,73&query=earth"
These require an Elasticsearch server and Redis server to be running.
bundle exec rspec
We track test coverage of the codebase over time, to help identify areas where we could write better tests and to see when poorly tested code got introduced.
After running your tests, view the report by opening coverage/index.html.
Click around on the files that have < 100% coverage to see what lines weren't exercised.
We "eat our own dog food" and use this ASIS API to display image results on the government websites that use DigitalGov Search.
See the sample results below for a search for moon on DOI.gov.
You can send feedback via Github Issues.


