Go to file
Rick Carlino eaadad79ef Documentation updates. 2017-02-10 08:06:24 -06:00
app Remove profiler, add `add_point` 2017-02-09 14:58:51 -06:00
bin Add more fields, validations to image and start writing model tests. 2017-01-11 09:27:06 -06:00
config Add SMTP_PORT to ENV vars 2017-02-10 07:58:52 -06:00
db Add points to sync object 2017-02-07 13:26:01 -06:00
lib/tasks Move tasks folder back into lib 2016-11-30 09:22:19 -06:00
spec Map points on FE. 2017-02-07 15:04:48 -06:00
.buildpacks use heroku-postbuild 2016-09-22 11:17:12 -05:00
.gitignore [STABLE] Clean up ENV vars for Google Cloud Storage. 2017-01-12 16:55:21 -06:00
.hound.yml WIP, browserify 2015-09-22 12:17:06 -05:00
.ruby-gemset rename application from `dss` to `farmbot` 2015-03-09 05:31:05 -05:00
.ruby-version if_statement --> _if migration 2016-12-29 10:16:15 -06:00
.travis.yml Fix CI bug. 2017-01-18 09:20:03 -06:00
CONTRIBUTING.md Create CONTRIBUTING.md 2015-09-18 22:48:44 -07:00
DEPLOYMENT.md Documentation updates. 2017-02-10 08:06:24 -06:00
Gemfile Remove my custom TimeFilter now that mutations has one on master 2017-01-24 07:36:06 -06:00
Gemfile.lock Remove my custom TimeFilter now that mutations has one on master 2017-01-24 07:36:06 -06:00
LICENSE Spruce up the README 2015-08-19 10:37:13 -05:00
README.md Add SMTP_PORT to ENV vars 2017-02-10 07:58:52 -06:00
Rakefile Cruft removal, part I 2015-10-20 13:03:42 -05:00
api_docs.md.erb if_statement --> _if migration 2016-12-29 10:16:15 -06:00
config.ru Added foundation and high voltage. Readme updates, too. 2014-03-31 06:31:38 -07:00
deploy.sh -g flag for webpack 2016-09-23 14:36:11 -05:00
deploy_errors.txt -g flag for webpack 2016-09-23 14:36:11 -05:00
frontend_build.yml Re-deploy 2016-09-21 15:41:33 -05:00
index.js Add `rake frontend:install`. 2016-09-22 09:15:57 -05:00
install_frontend.sh Add NPM_ADDON to frontend builder 2016-12-08 17:38:28 -06:00
latest_corpus.rb Ability to execute (only one) script from the sequence editor 2017-01-26 15:36:09 -06:00
latest_corpus.ts Allow set_user_env in rpc blocks 2017-01-27 12:04:01 -06:00
latest_schema.json Pushing up because FE is on Farmbotjs rc13 now. 2017-01-06 12:40:27 -06:00
maybe_save_this.rb [UNSTABLE] Got GCS policy objects working, need to tidy ENVs 2017-01-12 15:47:56 -06:00
package.json Add NPM_ADDON to frontend builder 2016-12-08 17:38:28 -06:00
rubocop.yml Document classes and modules in model directory 2016-12-27 11:32:49 -06:00
scratch_pad.rb Ascii art indentation 2016-11-18 16:40:25 -06:00
snippet.rb Bump image size limit. 2017-01-13 13:51:55 -06:00

README.md

Code Climate Test Coverage

Do I need this?

This repository is intended for software developers who wish to modify the Farmbot Web App. If you are not a developer, you are highly encouraged to use the publicly available web app. Running a server is a non-trivial task which will require an intermediate background in Ruby, SQL and Linux system administration.

If you are a developer interested in contributing or would like to provision your own server, you are in the right place.

Farmbot Web API

LATEST STABLE VERSION IS HERE

This Repo is the RESTful JSON API for Farmbot. This includes things like storage of user data, plant data, authorization tokens and a variety of other resources.

The key responsibility of the API is information and permissions management. This should not be confused with device control, which is done via MQTT.

API Documentation

For a list of example API requests and responses, see our reference documentation.

Developer Setup

Prerequisites

Your machine will need the following:

  1. Ruby 2.3.3

Setup

  1. git clone https://github.com/FarmBot/Farmbot-Web-API
  2. cd Farmbot-Web-API
  3. Install libpq-dev and postgresql
  4. bundle install
  5. Copy config/database.example.yml to config/database.yml. In GNU/Linux or Mac: mv config/database.example.yml config/database.yml.
  6. Get permission to create database*
  7. rake db:create:all db:migrate db:seed
  8. (optional) Verify installation with RAILS_ENV=test rake db:create db:migrate && rspec spec.
  9. MQTT_HOST=your_mqtt_server_domain rails s
  10. (optional- REQUIRES NODE > v6) Run ./install_frontend.sh to install the latest frontend app. You may also run the frontend on a seperate server. See frontend repository for details.
  11. Open localhost:3000.
  12. Raise an issue if you hit problems with any of these steps.

*Give permission to user to create database:

sudo -u postgres createuser user
sudo -u postgres psql
ALTER USER user WITH SUPERUSER;

Provisioning Your Own with Dokku

Please see deployment.md.

Config Settings (important)

Your server won't run without setting ENV variables first.

You can accomplish this by setting the ENV variables directly from your shell / server management tool or by writing an application.yml file.

See config/application.example.yml for a list of all the variables that must be set.

Encryption keys: Encryption keys will be autogenerated if not present. They can be reset using rake keys:generate. If ENV['RSA_KEY'] is set, it will be used in place of the *.pem files. Useful for environments like Heroku, where file system access is not allowed.

We can't fix issues we don't know about. Please submit an issue if you are having trouble installing on your local machine.

Running Specs

Please run them before submitting pull requests.

  • bundle exec rspec spec

Generating an API token

You must pass a token string into most HTTP requests under the Authorization: request header.

Here's what a response looks like when you request a token:

{
    "token": {
        "unencoded": {
            "sub": "test123@test.com",
            "iat": 1459109728,
            "jti": "922a5a0d-0b3a-4767-9318-1e41ae600352",
            "iss": "http://localhost:3000/",
            "exp": 1459455328,
            "mqtt": "localhost",
            "bot": "aa7bb37f-5ba3-4654-b2e4-58ed5746508c"
        },
        "encoded":
        // THE IMPORTANT PART IS HERE!!:
         "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJ0ZXN0MTIzQHRlc3QuY29tIiwiaWF0IjoxNDU5MTA5NzI4LCJqdGkiOiI5MjJhNWEwZC0wYjNhLTQ3NjctOTMxOC0xZTQxYWU2MDAzNTIiLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjMwMDAvIiwiZXhwIjoxNDU5NDU1MzI4LCJtcXR0IjoibG9jYWxob3N0IiwiYm90IjoiYWE3YmIzN2YtNWJhMy00NjU0LWIyZTQtNThlZDU3NDY1MDhjIn0.KpkNGR9YH68AF3iHP48GormqXzspBJrDGm23aMFGyL_eRIN8iKzy4gw733SaJgFjmebJOqZkz3cly9P5ZpCKwlaxAyn9RvfjQgFcUK0mywWAAvKp5lHfOFLhBBGICTW1r4HcZBgY1zTzVBw4BqS4zM7Y0BAAsflYRdl4dDRG_236p9ETCj0MSYxFagfLLLq0W63943jSJtNwv_nzfqi3TTi0xASB14k5vYMzUDXrC-Z2iBdgmwAYUZUVTi2HsfzkIkRcTZGE7l-rF6lvYKIiKpYx23x_d7xGjnQb8hqbDmLDRXZJnSBY3zGY7oEURxncGBMUp4F_Yaf3ftg4Ry7CiA"
    }
}

Important: The response is provided as JSON for human readability. For your Authorization header, you will only be using data.token.encoded. In this example, it's the string starting with eyJ0eXAiOiJ...

Via CURL

curl -H "Content-Type: application/json" \
     -X POST \
     -d '{"user":{"email":"test123@test.com","password":"password123"}}' \
     https://my.farmbot.io/api/tokens

Via JQuery

Since the API supports CORS, you can generate your token right in the browser.

Here's an example:

$.ajax({
    url: "https://my.farmbot.io/api/tokens",
    type: "POST",
    data: JSON.stringify({user: {email: 'admin@admin.com', password: 'password123'}}),
    contentType: "application/json",
    success: function (data) {
                 // You can now use your token:
                 var MY_SHINY_TOKEN = data.token.encoded;
             }
});

Want to Help?

Low Hanging Fruit. Raise an issue if you have any questions.