Skip to main content

Doing sinatra basic api

15.Apr.2017
> Creating RVM file
- cd projects\2017\ruby\doctor-is-in
- rvm use --create --rvmrc 2.4.1@doctor-is-in
> Create .GemFile
-subl GemFile
> Add item to GemFile
***
source 'http://rubygems.org'
ruby "2.4.1"
gem 'sinatra'
gem "activerecord"
gem "sinatra-activerecord"

#Tells your Mac to use sqlite locally during development
group :development do
    gem 'sqlite3'
    gem "tux"
end

#Tells heroku to use postgreSQL in production/live
group :production do
    gem 'pg'
end
***

> Install bundler
- gem install bundler
> Run bundler
- bundle install

> Clone viz project
- git clone https://baliwme@bitbucket.org/baliwme/viz.git

> Create config.ru
***
# config.ru

require './myapp'
run Sinatra::Application
***

> Open my good old reference
- https://www.kylembrown.com/programming/sinatra-and-postgresql-perform-on-a-heroku-stage-tutorial

> Create database-config.rb
***
# database-config.rb

#Sets development database to sqlite
configure :development do
  ActiveRecord::Base.establish_connection(
    :adapter => 'sqlite3',
    :database => 'db/DevDb.sqlite3',
    :show_exceptions => true,
    :connect_timeout => 30,
    :pool => 10
  )
end

#Sets production database to postgreSQL
configure :production do
  db = URI.parse(ENV['DATABASE_URL'] || 'postgres:///localhost/mydb')

  ActiveRecord::Base.establish_connection(
    :adapter  => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
    :host     => db.host,
    :username => db.user,
    :password => db.password,
    :database => db.path[1..-1],
    :encoding => 'utf8'
  )
end
***

> Create myapi.rb
***
# myapi.rb

require 'sinatra'
require 'sinatra/activerecord'
require './config/database-config'


class Doctor < ActiveRecord::Base
end
***

> Create Rakefile file
***
# Rakefile
#<a href="http://guides.rubyonrails.org/command_line.html#rake" target="_blank">Rake</a> is a build tool, written in Ruby, using Ruby as a build language. Rake is similar to make in scope and purpose. Rake a simple ruby build program with capabilities similar to make.
#ActiveRecord with be used for <a href="http://guides.rubyonrails.org/migrations.html" target="_blank">migrations</a>.

require './myapi'
require 'sinatra/activerecord/rake'
***

> Create Doctors table
- rake db:create_migration NAME=create_doctors

> Update db\migrate\20170415153551_create_doctors.rb
***
class CreateDoctors < ActiveRecord::Migration[5.0]
    def self.up
        create_table :doctors do |t|
        t.string :first_name
        t.string :middle_name
        t.string :last_name
        t.string :gender
        t.string :email

        t.text :bio
        t.timestamps
        end
    end

    def self.down
        drop_table :doctors
    end
end
***

> Start migration
- rake db:migrate

> Install gem shotgun
- gem install shotgun
- shotgun myapi.rb


14.Apr.2018
* Setup doctor-is-in ruby project
> Create project folder
- MkDir project\2017\doctor-is-in
> Initialize a git repo
- git init
> Clone heroku git repo
- heroku git:remote -a doctor-is-in

* Apply rvm
> Download latest stable ruby version 2.4.1
- rvm install 2.4.1


Comments

Popular posts from this blog

Ubuntu 16.04 LT - Installing Chromium browser

> Type these commands about this PPA : $ sudo add-apt-repository ppa:canonical-chromium-builds/stage $ sudo apt-get update $ sudo apt-get install chromium-browser > Terminal: mccrazy@Lenovo-N22:~$ sudo add-apt-repository ppa:canonical-chromium-builds/stage [sudo] password for mccrazy:  Testing site just before upload to Ubuntu main. Things here are either broken and not ready to use, or landing in the distro anyway very soon. You shouldn't use this.  More info: https://launchpad.net/~canonical-chromium-builds/+archive/ubuntu/stage Press [ENTER] to continue or ctrl-c to cancel adding it gpg: keyring `/tmp/tmp6cfppy_r/secring.gpg' created gpg: keyring `/tmp/tmp6cfppy_r/pubring.gpg' created gpg: requesting key 5B393194 from hkp server keyserver.ubuntu.com gpg: /tmp/tmp6cfppy_r/trustdb.gpg: trustdb created gpg: key 5B393194: public key "Launchpad PPA for Canonical Chromium Build Team" imported gpg: Total number processed: 1 gpg:               imported: 1  (RSA

Moodlerooms Webservice - How to insert a user using function core_user_create_users

https://our-sandbox.mrooms.net/webservice/rest/server.php?wstoken=OUT_TOKEN_HERE&wsfunction=core_user_create_users&moodlewsrestformat=xml&users [0][username]= biboyatienza@gmail.com &users[0][password]=00.00.0000&users[0][firstname]=biboy&users[0][lastname]=atienza&users[0][email]= biboyatienza@gmail.com &users[0][city]=Manila&users[0][country]=Philippines &users[0][customfields][0][type]= customer &users[0][customfields][0][value]=Customer1 &users[0][customfields][1][type]= customeremail &users[0][customfields][1][value]= customer@email.com &users[0][customfields][2][type]= customerphone &users[0][customfields][2][value]=+6325217788