*******************************************************************************
* Licensed by AT&T under 'Software Development Kit Tools Agreement.' 
*
* 2014 TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION:
* http://developer.att.com/sdk_agreement/ 
*
* Copyright 2014 AT&T Intellectual Property. All rights reserved.  
* http://developer.att.com 
*
* For more information contact developer.support@att.com
*******************************************************************************

  AT&T API Platform Sample Apps 
 --------------------------------------

  This file describes how to set up, configure and run the Ruby sample
  applications using the AT&T API Platform services. It covers all steps
  required to register the applications on DevConnect as well as running the
  sample applications locally.
  
    1. Configuration
    2. Installation
    3. Parameters
    4. Running the application


1. Configuration

  Configuration consists of a few steps necessary to get an application
  registered on DevConnect with the proper services and endpoints, depending on
  the type of client-side application (autonomous/non-autonomous). 

  To register an application, go to https://devconnect-api.att.com/ and login
  with your valid username and password. Next, choose "My Apps" from the bar at
  the top of the page and click the "Setup a New Application" button. 

  Fill in the form, in particular all fields marked as "required". 

  Be careful while filling in the "OAuth Redirect URL" field. It should contain
  the URL that the OAuth provider will redirect users to when he/she
  successfully authenticates and authorizes your application.  The oauth
  redirect field must match the redirect specified in the app's config.yml

  NOTE: You MUST select the Sample Applications name in the list of services
  under field 'Services' in order to enable access to the cloud api. 

  After your application is registered you will receive an API and Secret key.
  They are necessary for your registered applications to access the AT&T
  Platform APIs. See 'Adjusting parameters' below to learn how to use these
  keys in your applications.

  Initially your newly registered application is restricted to the "Sandbox"
  environment only. To move it to production, you may promote it by clicking
  the "Promote to production" button. Notice that you will get a different API
  key and secret, so these values in your application should be adjusted
  accordingly.

  Depending on the kind of authentication used, an application may be based on
  either the Autonomous Client or the Web-Server Client OAuth flow; see:
    https://devconnect-api.att.com/docs/oauth20/autonomous-client-application-oauth-flow
    https://devconnect-api.att.com/docs/oauth20/web-server-client-application-oauth-flow


2. Installation

** Requirements

  To run the examples you will need ruby 1.8+ and a few ruby gems that the
  applications are built upon:
  
    - sinatra: (http://www.sinatrarb.com/) used to construct a simple web
      application and manage URLs within.
  
    - sinatra-contrib: additional set of useful helpers, including ones used to
      read settings from external files.

    - rest-client: library for making restful calls

    - json: used for encoding and decoding requests/responses

    - att-codekit: library developed around the att cloud services (see below
      to install)
      - rake: compiling tool used to make att-codekit
      - yard: documentation tool used by att-codekit
  
  The easiest way to install the required gems is to use bundler.

  First make sure you have bundler installed:
    gem install bundler

  Then inside the directory which this README resides run:
    bundle install
  
  On a *nix based system you may need to raise your access privliges, such as 
  prefixing the command with sudo or logging in as root by running su.

** Installing the att-codekit library 
Note: this is only required if you are **not** using bundler and are using ruby 1.9+

    The code kit library can be installed by using our hosted gem file.
        
        gem sources --add http://lprod.code-api-att.com:8808
        gem install att-codekit

    Note that the codekit is under heavy development and is using a semantic
    versioning scheme. Non-backwards compatible changes **will** increase the
    major version number.
    

** Setting up on a different port number

  In the case multiple applications need to be run at the same time, you need
  to use different port numbers.

  By default sinatra uses port number 4567; however only one running
  application may use this port. In the case that you want to run more than one
  sinatra-based application, you will need to update each applications' port
  number (located in config.yml). 

    eg. application 1 - port: 4567, application 2 - port: 4568 

  The alternative is to set up your webserver to use a tool such as phusion
  passenger. Setting up a webserver, however, is beyond the scope of this
  article.


3. Parameters

  Each application contains a config.yml file. It holds configurable parameters
  described in the easy to read format YAML. You are free to adjust these to
  your needs. If you introduce a change make sure to restart the application
  for it to take effect. 

  The following are short descriptions of commonly used parameters:
  
  REQUIRED -
   1) FQDN        : The main server handling requests, ex: https://api.att.com
   
   2) api_key     : set the value as per your registered application 'API
                    key' field value 
   
   3) secret_key  : set the value as per your registered application
                    'Secret key' field value

  OPTIONAL -
    4) port        : The port number which the application will run standalone
  
    5) tokens_file : The path where the oauth token will be saved. This option
                     is only usable in client credential style authentication. 
                     Must have write permissions.
  
  Note: If your application is promoted from the Sandbox environment to
  Production environment and you decide to use production application settings,
  you must update api_key and secret_key as per production application details.


4. Running the application

  To run the application, open up a terminal window in the application's
  directory and type:

      ruby (app name).rb

  Where (app name) is replaced with the current directories app name.

  Your application by default is accessible in a web browser at the url:
      http://localhost:4567/ 

  You may interrupt the application at any time by pressing ctrl-C.


