To set up the vagrant box, install open CV, and set the database rights right, run:
vagrant up
Then log in and create the databases:
vagrant ssh
cd /home/vagrant/offset; bundle install; rake db:create; rake db:migrate; rake db:seed
And run the server: cd /home/vagrant/offset; rails s -b 0.0.0.0
Access the site: localhost:3100
Offset is an image management tool that can be used from other web apps and has the following functionality that you don’t need to replicate:
-
Manage images
-
Serve images
-
Resize images
-
Add a name and tags to an image
-
Select an image from the collection
Authentication from external apps works through OAuth2. An account can define multiple roles that can have the following rights:
-
Upload an image (tags pre-defined)
-
Upload an image and create/choose tags
-
Browse the image gallery and select an image
-
Delete an image
Each role has its own OAuth2 account to access the app.
An account can create multiple collections. For each collection the sizes that offset should resize to can be defined.
External app redirects the user to Offset and sends the following variables:
-
Role
-
Tags
-
Collection
After offset is finished dealing with the user, it returns:
-
the id of the image
-
the url for the requested thumbnail size
-
User
-
Collections
-
Default image sizes
-
Images
-
Tags
-
-
The app uses Fog for storage settings. Among others, it can use S3.
OAuth2: use the server credentials to obtain an access token.
Post an image: POST: /collection/:collection_id/images
variables: - image_data - name - description (optional) - tags (optional) - author_email (optional) - author_name (optional) returns: - picture_id
Retrieve a list of images for GET: /collection/:collection_id?page=:page GET: /collection/:collection_id?page=:page;tag=:tag
gem install oauth2 irb -r oauth2
callback = “localhost:3001/” app_id = “fd8ecd805e8a772a20302db1191c58a853c5ba7318773ebbf2a76d47af0a6ef1” secret = “340adfb3af545b2444f5532056910f1373b74990d3a3686f5456b3fa43bad923” client = OAuth2::Client.new(app_id, secret, site: “localhost:3100/”)
auth_code = “6a5efd644e4604ec6a8201ba93ebf952036eb1e8769fc218ec882eb5a789aec5”
access = client.auth_code.get_token(auth_code, redirect_uri: callback)
access.get(“/api/v1/collections”).parsed
access.expired? access = access.refresh!
callback = “localhost:3000/” app_id = “4e90205be3584f6fddf106a673203efce55f6538f6ad9a407795219fbdd63bc7” secret = “968384c18411c1f04c5e5633a0f92b0e1424b95947103c05fef98477ec1191b1”
client = OAuth2::Client.new(app_id, secret,
:site => "http://localhost:3100/") do |b| b.request :multipart b.request :url_encoded b.adapter :net_http
end
auth_code = “0cd0fd1e7e71805a2313a427048cdbee82b1274efa2b2d05ae25552ee0788ef8”
access = client.auth_code.get_token(auth_code, redirect_uri: callback)
begin
img = Faraday::UploadIO.new('pic.jpg', 'image/jpg') data = {image: {name: "this is a tile", attachment: img}} response = access.post('api/v1/collections/1/images/', :body => data) print response.body, response.status
rescue OAuth2::Error => e
puts e
end
img = Faraday::UploadIO.new(‘pic.jpg’, ‘image/jpg’); data = {image: {name: “this is a tile”, attachment: img}}; response = access.post(‘api/v1/collections/1/images/’, :body => data)
access.get(“/api/v1/collections/1/images/5/thumbnail?width=500&height=500”).parsed[‘url’]
-
Ruby version
Developed and tested on Ruby 2.2.3
-
System dependencies
Imagemagick Open CV (for Face recognition)
-
Configuration
-
Database creation
-
Database initialization
-
How to run the test suite
-
Services (job queues, cache servers, search engines, etc.)
-
Deployment instructions
-
…
Please feel free to use a different markup language if you do not plan to run rake doc:app.