The api that brings the bacon home.
- In auth0 admin control panel make sure user has
create:pinpermission - Get an access token from auth0. We'll call it our
auth0_token - POST to
/v1/pinsusing yourauth0_tokenas aBearertoken with a body like so:Your response will look like:{ "data": { "name": "Wisconsin Unicorn", "year": 2009, "description": "This unicorn was made up, unless it exists. It is a very cool unicorn." } }{ "id": "3d3987fa-4fb6-4b2d-8980-c1919f5e63ec", "name": "Wisconsin Unicorn", "year": 2009, "description": "This unicorn was made up, unless it exists. It is a very cool unicorn.", "tags": [], "created_at": "2019-05-15T22:59:01.754Z", "updated_at": "2019-05-15T22:59:01.754Z", "images_url": "http://www.example.com/v1/pins/3d3987fa-4fb6-4b2d-8980-c1919f5e63ec/images", "url": "http://www.example.com/v1/pins/3d3987fa-4fb6-4b2d-8980-c1919f5e63ec" } - You're done! You've created a
Pin! This is the same flow for any other item in the api.
Almost everything in PinsterApi is imageable so this process can be applied to Users, Pins, Assortments, and
Collections, etc.
-
Do a
GET(POSTwill have the same data if you're creating a resource) on the resource you'd like to add an image to. Theimages_urlwill be in the response body: Example response for aPin:{ "id": "3d3987fa-4fb6-4b2d-8980-c1919f5e63ec", "name": "Wisconsin Unicorn", "year": 2009, "description": "This unicorn was made up, unless it exists. It is a very cool unicorn.", "tags": [], "created_at": "2019-05-15T22:59:01.754Z", "updated_at": "2019-05-15T22:59:01.754Z", "images_url": "http://www.example.com/v1/pins/3d3987fa-4fb6-4b2d-8980-c1919f5e63ec/images", "url": "http://www.example.com/v1/pins/3d3987fa-4fb6-4b2d-8980-c1919f5e63ec" }- Note, the
images_urlisn't special, it's just in the response for your convenience. All imageables have a/imagesroute on which you can doGETandPOST.
- Note, the
-
Parse response for the
images_url -
POSTtoimages_urlwithout abodyusing yourauth0_tokenas aBearertoken. Your response will look like this:{ "image_service_token": "eyJhbGciOiJSUzI...", "image_service_url": "http://images.example.com" }- Note: These tokens are specific to the imageable and will expire shortly after they are generated (10 minutes or so). All images uploaded to image service with this token will be attached to the imageable for which this token was generated.
-
Parse response for the
image_service_tokenandimage_service_url -
POST to
image_service_urlusing theimage_service_tokenas aBearertoken with a body like so:{ "data": { "image": "base64 encoded image", "name": "Optional name of image", "description": "Optional description", "featured": "Optional ISO8601 format" } }Your response will look like this but you don't have to parse this:
{ "bucket": "image-service-upload-dev.pinster.io", "key": "raw/d01834089090031b1c7d098882cfb41b", "message": { "ETag": "\"d01834089090031b1c7d098882cfb41b\"" } } -
Image service will process your image and if it passes moderation it will
POSTback to the api on your behalf, linking the image to your imageable (pin in this case)!
Checklist
-
Generate new
OpenSSL::PKey::RSA.generate(2048)keys for image service and pinster api. Userails generate_keysand thekeys.envfile will contain urlsafe base64 encoded keys for use in environment variables. -
Set environment variables in elasticbeanstalk configure thing.
-
Set environment variables in secrets manager for image service's keys
-
run on ec2 instance
PgSearch::Multisearch.rebuild(Pin, true) PgSearch::Multisearch.rebuild(Assortment, true)
-
Set these envs:
SWAGGER_HOST= RDS_DB_NAME= RDS_HOSTNAME= RDS_PASSWORD= RDS_PORT= RDS_USERNAME= SECRET_KEY_BASE= AUTH0_SITE= JWT_AUD= IMAGE_SERVICE_URL= PRIVATE_KEY= IMAGE_SERVICE_PUBLIC_KEY=
-
Set up auth0