├── .bowerrc ├── githubContent ├── skip.png ├── appID.png ├── envars.png ├── addNewApp.png ├── alchemy.png ├── appName.png ├── appSecret.png ├── overview.png ├── restart.png ├── settings.png ├── siteUrl.png ├── website.png ├── addPlatform.png ├── userDefined.png ├── websitePlatform.png └── architectureDiagram.png ├── public ├── images │ └── FB-f-Logo__blue_144.png └── css │ └── style.css ├── bower.json ├── manifest.yml ├── config.js ├── .gitignore ├── .cfignore ├── views ├── footer.ejs ├── header.ejs └── index.ejs ├── package.json ├── vcap-local-example.json ├── README.bmd ├── README.md ├── app.js └── LICENSE /.bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory": "public/vendor/" 3 | } 4 | -------------------------------------------------------------------------------- /githubContent/skip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/facebook-photo-analyzer/HEAD/githubContent/skip.png -------------------------------------------------------------------------------- /githubContent/appID.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/facebook-photo-analyzer/HEAD/githubContent/appID.png -------------------------------------------------------------------------------- /githubContent/envars.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/facebook-photo-analyzer/HEAD/githubContent/envars.png -------------------------------------------------------------------------------- /githubContent/addNewApp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/facebook-photo-analyzer/HEAD/githubContent/addNewApp.png -------------------------------------------------------------------------------- /githubContent/alchemy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/facebook-photo-analyzer/HEAD/githubContent/alchemy.png -------------------------------------------------------------------------------- /githubContent/appName.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/facebook-photo-analyzer/HEAD/githubContent/appName.png -------------------------------------------------------------------------------- /githubContent/appSecret.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/facebook-photo-analyzer/HEAD/githubContent/appSecret.png -------------------------------------------------------------------------------- /githubContent/overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/facebook-photo-analyzer/HEAD/githubContent/overview.png -------------------------------------------------------------------------------- /githubContent/restart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/facebook-photo-analyzer/HEAD/githubContent/restart.png -------------------------------------------------------------------------------- /githubContent/settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/facebook-photo-analyzer/HEAD/githubContent/settings.png -------------------------------------------------------------------------------- /githubContent/siteUrl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/facebook-photo-analyzer/HEAD/githubContent/siteUrl.png -------------------------------------------------------------------------------- /githubContent/website.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/facebook-photo-analyzer/HEAD/githubContent/website.png -------------------------------------------------------------------------------- /githubContent/addPlatform.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/facebook-photo-analyzer/HEAD/githubContent/addPlatform.png -------------------------------------------------------------------------------- /githubContent/userDefined.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/facebook-photo-analyzer/HEAD/githubContent/userDefined.png -------------------------------------------------------------------------------- /githubContent/websitePlatform.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/facebook-photo-analyzer/HEAD/githubContent/websitePlatform.png -------------------------------------------------------------------------------- /githubContent/architectureDiagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/facebook-photo-analyzer/HEAD/githubContent/architectureDiagram.png -------------------------------------------------------------------------------- /public/images/FB-f-Logo__blue_144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/facebook-photo-analyzer/HEAD/public/images/FB-f-Logo__blue_144.png -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "box-sample-app", 3 | "version": "1.0.0", 4 | "private": false, 5 | "ignore": [ 6 | "**/.*", 7 | "node_modules", 8 | "public/vendor" 9 | ], 10 | "dependencies": { 11 | "bootstrap": "*", 12 | "jquery": "*", 13 | "angular": "*", 14 | "underscore": "*", 15 | "d3": "*", 16 | "angular-socket-io": "" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /manifest.yml: -------------------------------------------------------------------------------- 1 | --- 2 | declared-services: 3 | cloudant-photo-analyzer: 4 | label: cloudantNoSQLDB 5 | plan: Shared 6 | visual-recognition-photo-analyzer: 7 | label: watson_vision_combined 8 | plan: free 9 | applications: 10 | - name: facebook-photo-analyzer 11 | framework: node 12 | runtime: node12 13 | memory: 256M 14 | instances: 1 15 | host: facebook-photo-analyzer 16 | path: . 17 | command: node app.js 18 | services: 19 | - visual-recognition-photo-analyzer 20 | - cloudant-photo-analyzer 21 | -------------------------------------------------------------------------------- /config.js: -------------------------------------------------------------------------------- 1 | var VCAP_APPLICATION = process.env["VCAP_APPLICATION"], 2 | vcapApplication; 3 | if (VCAP_APPLICATION) { 4 | vcapApplication = JSON.parse(VCAP_APPLICATION); 5 | } 6 | 7 | module.exports = function() { 8 | return { 9 | appURL: function(port) { 10 | if (VCAP_APPLICATION) { 11 | return "https://" + vcapApplication.application_uris[0]; 12 | } 13 | else { 14 | return "http://localhost:" + port.toString(); 15 | } 16 | } 17 | }; 18 | }; 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | 29 | .DS_STORE 30 | npm-debug.log 31 | vcap-local.json 32 | 33 | public/vendor/ 34 | -------------------------------------------------------------------------------- /.cfignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | 29 | .DS_STORE 30 | npm-debug.log 31 | vcap-local.json 32 | vcap-local-example.json 33 | 34 | public/vendor/ 35 | -------------------------------------------------------------------------------- /views/footer.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "facebook-photo-sentiment", 3 | "version": "1.0.0", 4 | "private": false, 5 | "main": "app.js", 6 | "scripts": { 7 | "start": "node app.js", 8 | "postinstall": "bower install --allow-root --config.interactive=false" 9 | }, 10 | "engines": { 11 | "node": "0.12.*" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/IBM-Bluemix/facebook-photo-analyzer.git" 16 | }, 17 | "dependencies": { 18 | "alchemy-api": "^1.3.1", 19 | "async": "^1.5.0", 20 | "body-parser": "*", 21 | "bower": "*", 22 | "cf-deployment-tracker-client": "*", 23 | "cfenv": "*", 24 | "cloudant": "^1.3.0", 25 | "cookie-parser": "*", 26 | "ejs": "*", 27 | "express": "4.9.x", 28 | "express-force-ssl": "^0.3.0", 29 | "express-session": "*", 30 | "fbgraph": "^1.1.0", 31 | "method-override": "*", 32 | "passport": "0.2.1", 33 | "passport-facebook": "^2.0.0", 34 | "request": "^2.65.0", 35 | "underscore": "*", 36 | "watson-developer-cloud": "0.10.6" 37 | }, 38 | "author": [ 39 | { 40 | "name": "Jeff Sloyer", 41 | "email": "jbsloyer@us.ibm.com" 42 | } 43 | ], 44 | "contributors": [ 45 | { 46 | "name": "Jake Peyser", 47 | "email": "jepeyser@us.ibm.com" 48 | } 49 | ], 50 | "license": "Apache License" 51 | } 52 | -------------------------------------------------------------------------------- /vcap-local-example.json: -------------------------------------------------------------------------------- 1 | { 2 | "services": { 3 | "visual_recognition": [ 4 | { 5 | "name": "visual-recognition-photo-analyzer", 6 | "label": "visual_recognition", 7 | "plan": "free", 8 | "credentials": { 9 | "url": "https://gateway.watsonplatform.net/visual-recognition-beta/api", 10 | "username": "YOURUSERNAME", 11 | "password": "YOURPASSWORD" 12 | } 13 | } 14 | ], 15 | "alchemy_api": [ 16 | { 17 | "credentials": { 18 | "apikey": "YOURAPIKEY", 19 | "note": "It may take up to 5 minutes for this key to become active", 20 | "url": "https://gateway-a.watsonplatform.net/calls" 21 | }, 22 | "label": "alchemy_api", 23 | "name": "alchemy-api-photo-analyzer", 24 | "plan": "Free", 25 | "tags": [ 26 | "watson", 27 | "ibm_created", 28 | "ibm_dedicated_public" 29 | ] 30 | } 31 | ], 32 | "cloudantNoSQLDB": [ 33 | { 34 | "name": "cloudant-photo-analyzer", 35 | "label": "cloudantNoSQLDB", 36 | "plan": "Shared", 37 | "credentials": { 38 | "username": "YOURUSERNAME", 39 | "password": "YOURPASSWORD", 40 | "host": "YOURHOST", 41 | "port": 443, 42 | "url": "YOURURL" 43 | } 44 | } 45 | ] 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /views/header.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Facebook Photo Analyzer 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 | <% if (user) { %> 17 |
18 |
19 |
20 |
21 | 22 |
23 |
24 |
25 | 28 |
29 |
30 |
31 | <% } %> 32 |
33 | -------------------------------------------------------------------------------- /views/index.ejs: -------------------------------------------------------------------------------- 1 | <%- include header.ejs %> 2 | <% if (!setup) { %> 3 |
4 | Fork me on GitHub 5 |
6 | 7 |
8 |
Facebook Photo Analyzer 10 |
11 |
Let Watson analyze your photos...

13 |
14 |
15 | You must setup 3 environment variables: 16 |
    17 |
  • FACEBOOK_APP_ID
  • 18 |
  • FACEBOOK_APP_SECRET
  • 19 |
  • ALCHEMY_API_KEY
  • 20 |
21 |
22 |
23 | <% } else if (!user) { %> 24 |
25 | Fork me on GitHub 26 |
27 | 28 |
29 |
Facebook Photo Analyzer 31 |
32 |
Let Watson analyze your photos...

34 |
35 | 40 |
41 | <% } else { %> 42 |

Hello, <%= user.displayName %>!

43 |
44 |

Below are some photos from your Facebook account

45 |
46 | <% for(var i=0; i 47 | <% var photo = photos[i].value; %> 48 |
49 | 50 | <% if (photo.sentiment) { %> 51 |
Comment Sentiment: <%= photo.sentiment.type %>
52 | <% } %> 53 |
Items in Picture:
54 |
    55 | <% for(var k=0; k 56 |
  • <%= photo.labels[k].label_name %> - <%= photo.labels[k].label_score %>
  • 57 | <% } %> 58 |
59 |
60 | <% } %> 61 |
62 | <% } %> 63 | <%- include footer.ejs %> 64 | -------------------------------------------------------------------------------- /public/css/style.css: -------------------------------------------------------------------------------- 1 | body, html { 2 | font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; 3 | min-height: 100%; 4 | height: 100%; 5 | width: 100%; 6 | padding: 0; 7 | margin: 0; 8 | } 9 | 10 | .container-fluid, .container-fluid .jumbotron { 11 | padding-right: 0px; 12 | padding-left: 0px; 13 | } 14 | 15 | .container-fluid .jumbotron { 16 | border-radius: 0px; 17 | } 18 | 19 | .full-screen-wrapper { 20 | min-height: 100%; 21 | position: relative; 22 | background-color: #dfe6eb 23 | } 24 | 25 | .jumbotron { 26 | margin-bottom: 10px; 27 | padding: 10px 0px; 28 | background-color: #5aaaf9; 29 | color: white; 30 | width: 100%; 31 | } 32 | 33 | #nav-header { 34 | margin: 0px; 35 | padding-left: 15px; 36 | } 37 | 38 | #search-col { 39 | padding-right: 0px; 40 | padding-left: 0px; 41 | } 42 | 43 | #logout-link { 44 | padding-right: 10px; 45 | padding-top: 7px; 46 | } 47 | 48 | #logout-link a { 49 | color: white; 50 | font-size: 15px; 51 | } 52 | 53 | #logout-link a:hover { 54 | text-decoration: none; 55 | color: #dfe6eb; 56 | } 57 | 58 | .form-group { 59 | margin-bottom: 0px; 60 | } 61 | 62 | .hidden { 63 | display: none; 64 | } 65 | 66 | .splash { 67 | padding: 80px 0px; 68 | } 69 | 70 | .logo { 71 | display: inline-block; 72 | } 73 | 74 | #box { 75 | padding: 20px 40px 35px 40px; 76 | } 77 | 78 | .splash-header { 79 | font-size: 60px; 80 | font-family: "Trebuchet MS", Helvetica, sans-serif; 81 | padding-top: 20px; 82 | } 83 | 84 | .splash-sub-header { 85 | font-size: 30px; 86 | } 87 | 88 | .btn-primary { 89 | background-color: #1d3648; 90 | border: none; 91 | border-radius: 0; 92 | } 93 | 94 | .personality-btn { 95 | background-color: #ecf0f2; 96 | } 97 | 98 | .panel-title { 99 | color: #5aaaf9; 100 | } 101 | 102 | .panel-title a:hover { 103 | text-decoration: none; 104 | } 105 | 106 | .panel-description{ 107 | margin: 2px 0px 0px 0px; 108 | } 109 | 110 | .panel-group .panel { 111 | margin-bottom: 10px; 112 | border-radius: 0px; 113 | } 114 | 115 | .panel-group { 116 | margin-bottom: 60px; 117 | } 118 | 119 | .panel-heading { 120 | cursor: pointer; 121 | background: url(/../images/down_arrow.png) no-repeat; 122 | background-position: right 10px center; 123 | padding: 10px 40px 10px 15px; 124 | } 125 | 126 | #footer { 127 | position: absolute; 128 | bottom: 0; 129 | font-size: 15px; 130 | width: 100%; 131 | height: 40px; 132 | padding-top: 10px; 133 | padding-bottom: 50px; 134 | color: #333; 135 | text-align: center; 136 | clear: both; 137 | } 138 | 139 | #footer a { 140 | color: #333; 141 | } 142 | 143 | 144 | * {  145 | -moz-box-sizing: border-box;  146 | box-sizing: border-box; 147 | } 148 | 149 | #main { 150 | margin: 40px auto 10px auto; 151 | min-height: 400px; 152 | width: 960px; 153 | } 154 | 155 | .frame { 156 | float: left; 157 | height: 450px; 158 | overflow: hidden; 159 | position: relative; 160 | width: 340px; 161 | } 162 | 163 | .frame a { 164 | display: block; 165 | height: 100%; 166 | width: 100%; 167 | } 168 | 169 | .frame img { 170 | display: block; 171 | height: auto; 172 | position: absolute; 173 | width: auto; 174 | z-index: 0; 175 | } 176 | 177 | .frame:nth-child(2) img { 178 | top: -90%; 179 | left: -70%; 180 | } 181 | .frame:nth-child(3) img { 182 | top: -90%; 183 | } 184 | 185 | .frame a .caption { 186 | background-color: rgba(0, 0, 0, 0.8); 187 | display: block; 188 | overflow: hidden; 189 | padding-left: 10px; 190 | position: absolute; 191 | left: 0; 192 | right: 0; 193 | bottom: 0; 194 | top: 410px; 195 | transition-property: top; 196 | transition-duration: 0.2s; 197 | width: 100%; 198 | z-index: 10; 199 | } 200 | 201 | .frame a .caption:hover { 202 | top: 250px; 203 | transition: all 2s; 204 | } 205 | 206 | .frame a .caption h4 { 207 | color: #5aaaf9; 208 | margin-bottom: 20px; 209 | } 210 | 211 | .frame a .caption p { 212 | color: white; 213 | display: none; 214 | line-height: 150%; 215 | transition: all 0.2s; 216 | width: 90%; 217 | } 218 | 219 | .frame a:hover .caption p { 220 | display: block; 221 | margin-bottom: 20px; 222 | } 223 | 224 | .spinner { 225 | display: inline-block; 226 | opacity: 0; 227 | width: 0; 228 | 229 | -webkit-transition: opacity 0.25s, width 0.25s; 230 | -moz-transition: opacity 0.25s, width 0.25s; 231 | -o-transition: opacity 0.25s, width 0.25s; 232 | transition: opacity 0.25s, width 0.25s; 233 | } 234 | 235 | .traits li { 236 | list-style: none; 237 | } 238 | 239 | blockquote { 240 | border: none; 241 | color: inherit; 242 | font-family: Georgia, serif !important; 243 | font-size: 18px; 244 | font-style: italic; 245 | width: 450px; 246 | margin: 0.25em 0; 247 | padding: 0.25em 40px; 248 | line-height: 1.45; 249 | position: relative; 250 | } 251 | 252 | blockquote:before { 253 | display: block; 254 | content: "\201C"; 255 | font-size: 80px; 256 | position: absolute; 257 | left: -10px; 258 | top: -10px; 259 | color: #7a7a7a; 260 | } 261 | 262 | blockquote cite { 263 | color: #999999; 264 | font-size: 14px; 265 | display: block; 266 | margin-top: 5px; 267 | } 268 | 269 | blockquote cite:before { 270 | content: "\2014 \2009"; 271 | } 272 | 273 | blockquote:hover{ 274 | color: inherit !important; 275 | border: inherit !important; 276 | } 277 | -------------------------------------------------------------------------------- /README.bmd: -------------------------------------------------------------------------------- 1 | # Facebook Photo Analyzer 2 | 3 | ## Architecture Diagram 4 | ![][architectureDiagram] 5 | 6 | ## Deploy 7 | 8 | There are two menthods to deploy this app. With both ways you will need to create a [Facebook developer app](https://developer.facebook.com) and signup for a [AlchemyAPI account](http://www.alchemyapi.com/api/register.html). 9 | 10 | ### Facebook setup 11 | 12 | 1. Goto [https://developer.facebook.com](https://developer.facebook.com) 13 | 2. Sign in and click hover over My Apps at the top, then click new app. 14 | ![][newAppImage] 15 | 3. Click Website for the app type 16 | ![][websiteImage] 17 | 4. Click Skip and Create App ID 18 | ![][skipImage] 19 | 5. Give your application a name and category. Click "Create App ID". 20 | ![][appNameImage] 21 | 6. Leave the page open on Facebook that it brings you to. It should have an App ID and App Secret displayed at the top. We will need this info later. 22 | 23 | 24 | ### Quick and easy 25 | 26 | Click the following button 27 | 28 | [![Deploy to Bluemix](https://deployment-tracker.mybluemix.net/stats/98666763715aa857bce80728b1c4b606/button.svg)](https://bluemix.net/deploy?repository=https://github.com/IBM-Bluemix/facebook-photo-analyzer.git) 29 | 30 | **You might get a screen asking you to create an alias on DevOps services. If you do just use the part before the @ sign in your email address. Example if your email is johnsmith@gmail.com your username would be johnsmith*** 31 | 32 | Once the deployment is done, skip to step 10 below. 33 | 34 | ### Developer way 35 | 1. Create a Bluemix Account 36 | 37 | [Sign up][bluemix_signup_url] for Bluemix, or use an existing account. 38 | 39 | 2. Download and install the [Cloud-foundry CLI][cloud_foundry_url] tool 40 | 41 | 3. Download and [install Git][git_install] 42 | 43 | 3. Clone the app to your local environment from your terminal using the following command 44 | 45 | ``` 46 | git clone https://github.com/IBM-Bluemix/facebook-photo-analyzer.git 47 | ``` 48 | 4. cd into this newly created directory 49 | 50 | ``` 51 | cd facebook-photo-analyzer 52 | ``` 53 | 54 | 5. Edit the `manifest.yml` file and change the `` and `` to something unique. 55 | 56 | ``` 57 | applications: 58 | - name: facebook-photo-analyzer 59 | framework: node 60 | runtime: node12 61 | memory: 256M 62 | instances: 1 63 | host: facebook-photo-analyzer 64 | path: . 65 | command: node app.js 66 | ``` 67 | 68 | The host you use will determinate your application url initially, e.g. `.mybluemix.net`. 69 | 70 | 6. Connect to Bluemix in the command line tool and follow the prompts to log in. 71 | 72 | ``` 73 | $ cf api https://api.ng.bluemix.net 74 | $ cf login 75 | ``` 76 | 77 | If you want to deploy this app to the EU region in London use the following 78 | ``` 79 | $ cf api https://api.eu-gb.bluemix.net 80 | $ cf login 81 | ``` 82 | 83 | If you want to deploy this app to the Asia/Pacific region in Australia use the following 84 | ``` 85 | $ cf api https://api.au-syd.bluemix.net 86 | $ cf login 87 | ``` 88 | 7. Create the Visual Recognition service in Bluemix. 89 | 90 | ``` 91 | $ cf create-service visual_recognition free visual-recognition-photo-analyzer 92 | ``` 93 | 94 | 8. Create the Cloudant service in Bluemix. 95 | 96 | ``` 97 | $ cf create-service cloudantNoSQLDB Shared cloudant-photo-analyzer 98 | ``` 99 | 100 | 9. Push it to Bluemix. We need to perform additional steps once it is deployed, so we will add the option --no-start argument 101 | 102 | ``` 103 | $ cf push --no-start 104 | ``` 105 | 106 | 10. In the Bluemix UI click on your application. At the top of the screen there will be a url for your application, ex. `http://facebook-photo-analyzer.mybluemix.net`. Copy this and go back to your Facebook app tab in your browser. We need to use this url as our application URL. 107 | 11. Click "Settings" on the left hand side and then click "Add Platform" 108 | ![][settingsImage] 109 | 12. Click WWW 110 | ![][websitePlatformImage] 111 | 13. Type in the URL for your application, ex. `http://myapp.mybluemix.net`, click "Save Changes". 112 | ![][siteUrlImage] 113 | 14. On the left click Dashboard, copy the Facebook app ID. 114 | 15. Go back to Bluemix and click on Environment variables on the left hand side. 115 | ![][envarsImage] 116 | 16. Click on user defined 117 | ![][userDefinedImage] 118 | 17. For the name of the enviroment variable enter `FACEBOOK_APP_ID`. For the value paste your Facebook app ID. 119 | ![][appIDImage] 120 | 18. Go back to Facebook, copy the app secret. Go back to Bluemix. Repeat step 4 expect this time the variable name is `FACEBOOK_APP_SECRET`. Paste in the value for the Facebook app secret. 121 | ![][appSecretImage] 122 | 19. When we signed up for the Alchemy API we should of recieved an API key in our email. We need to create an environment variable to store this. Create another environment variable called `ALCHEMY_API_KEY`, paste in api key for Alchemy for the value. 123 | ![][alchemyImage] 124 | 20. Click save. 125 | 21. Click overview in the top left. 126 | ![][overviewImage] 127 | 22. On the right hand side, click restart or start. 128 | ![][restartImage] 129 | 130 | ### Privacy Notice 131 | 132 | The Personality Box sample web application includes code to track deployments to Bluemix and other Cloud Foundry platforms. The following information is sent to a [Deployment Tracker] [deploy_track_url] service on each deployment: 133 | 134 | * Application Name (`application_name`) 135 | * Space ID (`space_id`) 136 | * Application Version (`application_version`) 137 | * Application URIs (`application_uris`) 138 | 139 | This data is collected from the `VCAP_APPLICATION` environment variable in IBM Bluemix and other Cloud Foundry platforms. This data is used by IBM to track metrics around deployments of sample applications to IBM Bluemix. Only deployments of sample applications that include code to ping the Deployment Tracker service will be tracked. 140 | 141 | ### Disabling Deployment Tracking 142 | 143 | Deployment tracking can be disabled by removing `require("cf-deployment-tracker-client").track();` from the beginning of the [`app.js`](app.js#L23) main server file. 144 | 145 | 146 | [newAppImage]: githubContent/addNewApp.png?raw=true 147 | [websiteImage]: githubContent/website.png?raw=true 148 | [skipImage]: githubContent/skip.png?raw=true 149 | [appNameImage]: githubContent/appName.png?raw=true 150 | [settingsImage]: githubContent/settings.png?raw=true 151 | [websitePlatformImage]: githubContent/websitePlatform.png?raw=true 152 | [siteUrlImage]: githubContent/siteUrl.png?raw=true 153 | [envarsImage]: githubContent/envars.png?raw=true 154 | [userDefinedImage]: githubContent/userDefined.png?raw=true 155 | [appIDImage]: githubContent/appID.png?raw=true 156 | [appSecretImage]: githubContent/appSecret.png?raw=true 157 | [alchemyImage]: githubContent/alchemy.png?raw=true 158 | [overviewImage]: githubContent/overview.png?raw=true 159 | [restartImage]: githubContent/restart.png?raw=true 160 | [bluemix_signup_url]: https://console.ng.bluemix.net/?cm_mmc=GitHubReadMe-_-BluemixSampleApp-_-Node-_-Watson 161 | [cloud_foundry_url]: https://github.com/cloudfoundry/cli 162 | [git_install]: https://git-scm.com/downloads 163 | [architectureDiagram]: githubContent/architectureDiagram.png?raw=true 164 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Facebook Photo Analyzer 2 | 3 | ## Architecture Diagram 4 | ![][architectureDiagram] 5 | 6 | ## Deploy 7 | 8 | There are two menthods to deploy this app. With both ways you will need to create a [Facebook developer app](https://developer.facebook.com) and signup for a [AlchemyAPI account](http://www.alchemyapi.com/api/register.html). 9 | 10 | ### Facebook setup 11 | 12 | 1. Goto [https://developer.facebook.com](https://developer.facebook.com) 13 | 2. Sign in and click hover over My Apps at the top, then click new app. 14 | ![][newAppImage] 15 | 3. Click Website for the app type 16 | ![][websiteImage] 17 | 4. Click Skip and Create App ID 18 | ![][skipImage] 19 | 5. Give your application a name and category. Click "Create App ID". 20 | ![][appNameImage] 21 | 6. Leave the page open on Facebook that it brings you to. It should have an App ID and App Secret displayed at the top. We will need this info later. 22 | 23 | 24 | ### Quick and easy 25 | 26 | Click the following button 27 | 28 | [![Deploy to Bluemix](https://deployment-tracker.mybluemix.net/stats/98666763715aa857bce80728b1c4b606/button.svg)](https://bluemix.net/deploy?repository=https://github.com/IBM-Bluemix/facebook-photo-analyzer.git) 29 | 30 | **You might get a screen asking you to create an alias on DevOps services. If you do just use the part before the @ sign in your email address. Example if your email is johnsmith@gmail.com your username would be johnsmith*** 31 | 32 | Once the deployment is done, skip to step 10 below. 33 | 34 | ### Developer way 35 | 1. Create a Bluemix Account 36 | 37 | [Sign up][bluemix_signup_url] for Bluemix, or use an existing account. 38 | 39 | 2. Download and install the [Cloud-foundry CLI][cloud_foundry_url] tool 40 | 41 | 3. Download and [install Git][git_install] 42 | 43 | 3. Clone the app to your local environment from your terminal using the following command 44 | 45 | ``` 46 | git clone https://github.com/IBM-Bluemix/facebook-photo-analyzer.git 47 | ``` 48 | 4. cd into this newly created directory 49 | 50 | ``` 51 | cd facebook-photo-analyzer 52 | ``` 53 | 54 | 5. Edit the `manifest.yml` file and change the `` and `` to something unique. 55 | 56 | ``` 57 | applications: 58 | - name: facebook-photo-analyzer 59 | framework: node 60 | runtime: node12 61 | memory: 256M 62 | instances: 1 63 | host: facebook-photo-analyzer 64 | path: . 65 | command: node app.js 66 | ``` 67 | 68 | The host you use will determinate your application url initially, e.g. `.mybluemix.net`. 69 | 70 | 6. Connect to Bluemix in the command line tool and follow the prompts to log in. 71 | 72 | ``` 73 | $ cf api https://api.ng.bluemix.net 74 | $ cf login 75 | ``` 76 | 77 | If you want to deploy this app to the EU region in London use the following 78 | ``` 79 | $ cf api https://api.eu-gb.bluemix.net 80 | $ cf login 81 | ``` 82 | 83 | If you want to deploy this app to the Asia/Pacific region in Australia use the following 84 | ``` 85 | $ cf api https://api.au-syd.bluemix.net 86 | $ cf login 87 | ``` 88 | 7. Create the Visual Recognition service in Bluemix. 89 | 90 | ``` 91 | $ cf create-service visual_recognition free visual-recognition-photo-analyzer 92 | ``` 93 | 94 | 8. Create the Cloudant service in Bluemix. 95 | 96 | ``` 97 | $ cf create-service cloudantNoSQLDB Shared cloudant-photo-analyzer 98 | ``` 99 | 100 | 9. Push it to Bluemix. We need to perform additional steps once it is deployed, so we will add the option --no-start argument 101 | 102 | ``` 103 | $ cf push --no-start 104 | ``` 105 | 106 | 10. In the Bluemix UI click on your application. At the top of the screen there will be a url for your application, ex. `http://facebook-photo-analyzer.mybluemix.net`. Copy this and go back to your Facebook app tab in your browser. We need to use this url as our application URL. 107 | 11. Click "Settings" on the left hand side and then click "Add Platform" 108 | ![][settingsImage] 109 | 12. Click WWW 110 | ![][websitePlatformImage] 111 | 13. Type in the URL for your application, ex. `http://myapp.mybluemix.net`, click "Save Changes". 112 | ![][siteUrlImage] 113 | 14. On the left click Dashboard, copy the Facebook app ID. 114 | 15. Go back to Bluemix and click on Environment variables on the left hand side. 115 | ![][envarsImage] 116 | 16. Click on user defined 117 | ![][userDefinedImage] 118 | 17. For the name of the enviroment variable enter `FACEBOOK_APP_ID`. For the value paste your Facebook app ID. 119 | ![][appIDImage] 120 | 18. Go back to Facebook, copy the app secret. Go back to Bluemix. Repeat step 4 expect this time the variable name is `FACEBOOK_APP_SECRET`. Paste in the value for the Facebook app secret. 121 | ![][appSecretImage] 122 | 19. When we signed up for the Alchemy API we should of recieved an API key in our email. We need to create an environment variable to store this. Create another environment variable called `ALCHEMY_API_KEY`, paste in api key for Alchemy for the value. 123 | ![][alchemyImage] 124 | 20. Click save. 125 | 21. Click overview in the top left. 126 | ![][overviewImage] 127 | 22. On the right hand side, click restart or start. 128 | ![][restartImage] 129 | 130 | ### Privacy Notice 131 | 132 | The Personality Box sample web application includes code to track deployments to Bluemix and other Cloud Foundry platforms. The following information is sent to a [Deployment Tracker] [deploy_track_url] service on each deployment: 133 | 134 | * Application Name (`application_name`) 135 | * Space ID (`space_id`) 136 | * Application Version (`application_version`) 137 | * Application URIs (`application_uris`) 138 | 139 | This data is collected from the `VCAP_APPLICATION` environment variable in IBM Bluemix and other Cloud Foundry platforms. This data is used by IBM to track metrics around deployments of sample applications to IBM Bluemix. Only deployments of sample applications that include code to ping the Deployment Tracker service will be tracked. 140 | 141 | ### Disabling Deployment Tracking 142 | 143 | Deployment tracking can be disabled by removing `require("cf-deployment-tracker-client").track();` from the beginning of the [`app.js`](app.js#L23) main server file. 144 | 145 | 146 | [newAppImage]: githubContent/addNewApp.png?raw=true 147 | [websiteImage]: githubContent/website.png?raw=true 148 | [skipImage]: githubContent/skip.png?raw=true 149 | [appNameImage]: githubContent/appName.png?raw=true 150 | [settingsImage]: githubContent/settings.png?raw=true 151 | [websitePlatformImage]: githubContent/websitePlatform.png?raw=true 152 | [siteUrlImage]: githubContent/siteUrl.png?raw=true 153 | [envarsImage]: githubContent/envars.png?raw=true 154 | [userDefinedImage]: githubContent/userDefined.png?raw=true 155 | [appIDImage]: githubContent/appID.png?raw=true 156 | [appSecretImage]: githubContent/appSecret.png?raw=true 157 | [alchemyImage]: githubContent/alchemy.png?raw=true 158 | [overviewImage]: githubContent/overview.png?raw=true 159 | [restartImage]: githubContent/restart.png?raw=true 160 | [bluemix_signup_url]: https://console.ng.bluemix.net/?cm_mmc=GitHubReadMe-_-BluemixSampleApp-_-Node-_-Watson 161 | [cloud_foundry_url]: https://github.com/cloudfoundry/cli 162 | [git_install]: https://git-scm.com/downloads 163 | [architectureDiagram]: githubContent/architectureDiagram.png?raw=true 164 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | var express = require('express'), 2 | app = express(), 3 | config = require("./config")(), 4 | passport = require('passport'), 5 | bodyParser = require('body-parser'), 6 | cookieParser = require('cookie-parser'), 7 | session = require('express-session'), 8 | methodOverride = require('method-override'), 9 | watson = require('watson-developer-cloud'), 10 | FacebookStrategy = require('passport-facebook').Strategy, 11 | _ = require("underscore"), 12 | cfenv = require("cfenv"), 13 | async = require("async"), 14 | graph = require('fbgraph'), 15 | request = require('request'), 16 | AlchemyApi = require('alchemy-api'), 17 | fs = require("fs"), 18 | path = require("path"), 19 | os = require("os"), 20 | Cloudant = require('cloudant'); 21 | 22 | //---Deployment Tracker--------------------------------------------------------- 23 | require("cf-deployment-tracker-client").track(); 24 | 25 | 26 | //---Environment Vars----------------------------------------------------------- 27 | var vcapLocal = null 28 | try { 29 | vcapLocal = require("./vcap-local.json") 30 | } 31 | catch (e) {} 32 | 33 | var appEnvOpts = vcapLocal ? {vcap:vcapLocal} : {} 34 | var appEnv = cfenv.getAppEnv(appEnvOpts); 35 | 36 | // Retrieves service credentials for the input service 37 | function getServiceCreds(appEnv, serviceName) { 38 | var serviceCreds = appEnv.getServiceCreds(serviceName) 39 | if (!serviceCreds) { 40 | console.log("service " + serviceName + " not bound to this application"); 41 | return null; 42 | } 43 | return serviceCreds; 44 | } 45 | 46 | //---Set up Watson Personality Insights----------------------------------------- 47 | var visualRecognitionCreds = getServiceCreds(appEnv, "visual-recognition-photo-analyzer"); 48 | visualRecognitionCreds.version = "v1"; 49 | delete visualRecognitionCreds.url; 50 | var visualRecognition = watson.visual_recognition(visualRecognitionCreds); 51 | 52 | var alchemy = new AlchemyApi(process.env.ALCHEMY_API_KEY); 53 | 54 | //---Set up Cloudant------------------------------------------------------------ 55 | var cloudantCreds = getServiceCreds(appEnv, "cloudant-photo-analyzer"), 56 | dbName = "photo-analyzer", 57 | cloudant, 58 | db; 59 | 60 | //---Routers and View Engine---------------------------------------------------- 61 | app.set('views', __dirname + '/views'); 62 | app.set('view engine', 'ejs'); 63 | app.use(cookieParser()); 64 | app.use(bodyParser()); 65 | app.use(methodOverride()); 66 | app.use(session({ 67 | secret: 'keyboard cat' 68 | })); 69 | app.use(passport.initialize()); 70 | app.use(passport.session()); 71 | app.use(express.static(__dirname + '/public')); 72 | 73 | //---auth stuff----------------------------------------------------------------- 74 | passport.serializeUser(function (user, done) { 75 | done(null, user); 76 | }); 77 | 78 | passport.deserializeUser(function (obj, done) { 79 | done(null, obj); 80 | }); 81 | 82 | if (process.env.FACEBOOK_APP_ID !== undefined && process.env.FACEBOOK_APP_SECRET !== undefined) { 83 | 84 | passport.use(new FacebookStrategy({ 85 | clientID: process.env.FACEBOOK_APP_ID, 86 | clientSecret: process.env.FACEBOOK_APP_SECRET, 87 | callbackURL: appEnv.url + "/auth/facebook/callback", 88 | scope: ["user_photos", "user_posts"] 89 | }, 90 | function(accessToken, refreshToken, profile, done) { 91 | async.waterfall([ 92 | function (next) { 93 | graph.setAccessToken(accessToken); 94 | graph.get("/me/photos", next); 95 | }, 96 | function (photos, next) { 97 | var params = { fields: "images" }; 98 | _.each(photos.data, function(photo) { 99 | photo.graph = graph; 100 | photo.userId = profile.id; 101 | }); 102 | console.log("analyzing",photos.data.length, "photos"); 103 | async.each(photos.data, analyzePhoto, next); 104 | } 105 | ], function (error, result) { 106 | if (error) { 107 | console.log(error); 108 | done(error); 109 | } 110 | else { 111 | done(null, profile); 112 | } 113 | } 114 | ); 115 | } 116 | )); 117 | } 118 | 119 | app.get('/auth/facebook', passport.authenticate('facebook')); 120 | 121 | app.get('/auth/facebook/callback', 122 | passport.authenticate('facebook', { 123 | successRedirect: '/', 124 | failureRedirect: '/login' 125 | }) 126 | ); 127 | 128 | //---Start the server, conenct to cloudant-------------------------------------- 129 | app.listen(appEnv.port, function() { 130 | console.log("server started on port " + appEnv.port); 131 | var dbCreated = false; 132 | Cloudant({account:cloudantCreds.username, password:cloudantCreds.password}, function(er, dbInstance) { 133 | cloudant = dbInstance; 134 | if (er) { 135 | return console.log('Error connecting to Cloudant account %s: %s', cloudantCreds.username, er.message); 136 | } 137 | 138 | console.log('Connected to cloudant'); 139 | cloudant.ping(function(er, reply) { 140 | if (er) { 141 | return console.log('Failed to ping Cloudant. Did the network just go down?'); 142 | } 143 | 144 | console.log('Server version = %s', reply.version); 145 | console.log('I am %s and my roles are %j', reply.userCtx.name, reply.userCtx.roles); 146 | 147 | cloudant.db.list(function(er, all_dbs) { 148 | if (er) { 149 | return console.log('Error listing databases: %s', er.message); 150 | } 151 | 152 | console.log('All my databases: %s', all_dbs.join(', ')); 153 | 154 | _.each(all_dbs, function(name) { 155 | if (name === dbName) { 156 | dbCreated = true; 157 | } 158 | }); 159 | if (dbCreated === false) { 160 | cloudant.db.create(dbName, seedDB); 161 | } 162 | else { 163 | db = cloudant.db.use(dbName); 164 | console.log("DB", dbName, "is already created"); 165 | } 166 | }); 167 | }); 168 | }); 169 | }); 170 | 171 | //--Analyze a photo from Facebook with Watson and AlchemyAPI-------------------- 172 | function analyzePhoto(photo, callback) { 173 | var graph = photo.graph, 174 | file = path.join(os.tmpdir(), photo.id + ".jpg"), 175 | response = { 176 | photoId: photo.id, 177 | userId: photo.userId 178 | }; 179 | 180 | async.waterfall([ 181 | function (next) { 182 | var params = { fields: "images" }; 183 | graph.get("/" + photo.id, params, next); 184 | }, 185 | function (result, next) { 186 | response.source = result.images[0].source; 187 | var stream = request.get(result.images[0].source).pipe(fs.createWriteStream(file)); 188 | stream.on("finish", function() { 189 | var params = { 190 | image_file: fs.createReadStream(file) 191 | }; 192 | 193 | visualRecognition.recognize(params, function (error, result) { 194 | if (error) { 195 | console.log(error); 196 | callback(null); 197 | return; 198 | } 199 | next(null, result) 200 | }); 201 | }); 202 | }, 203 | function (result, next) { 204 | response.labels = result.images[0].labels; 205 | graph.get("/" + photo.id + "/comments", next); 206 | }, 207 | function (comments, next) { 208 | var commentsString = ""; 209 | 210 | _.each(comments.data, function(comment) { 211 | commentsString += " " + comment.message 212 | }); 213 | 214 | if (commentsString != "") { 215 | alchemy.sentiment(commentsString, {}, next); 216 | } 217 | else { 218 | next(null, null); 219 | } 220 | 221 | }, 222 | function (result, next) { 223 | if (result !== null) { 224 | response.sentiment = result.docSentiment; 225 | } 226 | 227 | response.type = "photo"; 228 | db.view("photos", "photo", { keys: [response.photoId]}, next); 229 | }, 230 | function (result, headers, next) { 231 | if (result.rows.length === 0) { 232 | db.insert(response, next); 233 | } 234 | else { 235 | next(null, result); 236 | } 237 | } 238 | ], callback); 239 | } 240 | 241 | //---Route handle for the default entry point to the app------------------------ 242 | app.get('/', function (request, response) { 243 | var setup = false; 244 | if (process.env.FACEBOOK_APP_ID !== undefined && process.env.FACEBOOK_APP_SECRET !== undefined && process.env.ALCHEMY_API_KEY !== undefined) { 245 | setup = true; 246 | } 247 | var opts = { 248 | user: request.user, 249 | setup: setup 250 | }; 251 | 252 | if (request.user) { 253 | db.view("photos", "user", { keys: [request.user.id]}, function (error, result) { 254 | opts.photos = result.rows; 255 | response.render('index', opts); 256 | }); 257 | } 258 | else { 259 | response.render('index', opts); 260 | } 261 | 262 | }); 263 | 264 | //--Route handle for logging out------------------------------------------------ 265 | app.get('/logout', function (request, response) { 266 | request.logout(); 267 | response.redirect('/'); 268 | }); 269 | 270 | //---Seed the db---------------------------------------------------------------- 271 | function seedDB(callback) { 272 | db = cloudant.use(dbName); 273 | 274 | async.waterfall([ 275 | function (next) { 276 | var designDocs = [ 277 | { 278 | _id: '_design/photos', 279 | views: { 280 | all: { 281 | map: function (doc) { if (doc.type === 'photo') { emit(doc._id, doc); } } 282 | }, 283 | user: { 284 | map: function (doc) { if (doc.type === 'photo') { emit(doc.userId, doc); } } 285 | }, 286 | photo: { 287 | map: function (doc) { if (doc.type === 'photo') { emit(doc.photoId, doc); } } 288 | } 289 | } 290 | } 291 | ]; 292 | 293 | async.each(designDocs, db.insert, next); 294 | }, 295 | function (next) { 296 | console.log("Created DB", dbName, "and populated it with initial purchases"); 297 | next(); 298 | } 299 | ], callback) 300 | } 301 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {2015} {IBM} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | --------------------------------------------------------------------------------