Servicios REST - lacoderia/iuvare GitHub Wiki

#General ##Response
The response for all services is a JSON object with the following structure:

  • success = true or false
  • result = if success is true, this contains the result object
  • error = if success is false, this contains the error message
    Examples:
    {"success":true, "result":{}}
    {"success":false, "error": "Some error"}

#Services

Authentication

Login

POST /users/sign_in.json
http://localhost:3000/users/sign_in.json
Logins a user
Parameters:

  • user = a user object
    • email (string)
    • password (string)

Logout

GET /logout
http://localhost:3000/logout
Logs out a user

Session

GET /session.json
http://localhost:3000/session.json
Obtains the logged user's session, if there's any
UPDATE: It now includes test_scores, downline_count properties and access_level object
Result data structure:

  • user object
  • test_scores (object array)
  • downline_count (integer)
  • access_level object
    • valid account (boolean)
    • message (string)
    • payment_options object
      • item_name (string)
      • custom (string)
      • amount (integer)

Users

Get by xango id

GET /users/by_xango_id.json
http://localhost:3000/users/by_xango_id.json
Gets a user by xango_id
Parameters:

  • xango_id (string, required)

Result data structure:

  • user object
    • id (integer)
    • first_name (string)
    • last_name (string)
    • email (required, string)
    • xango_id (string)
    • iuvare_id (string)
    • sponsor_xango_id (string)
    • sponsor_iuvare_id (string)
    • placement_xango_id (string)
    • placement_iuvare_id (string)
    • active (boolean)
    • payment_expiration (datetime)
    • xango_rank (string)

Update user

PUT /users/ID.json
http://localhost:3000/users/ID.json
Updates user's attributes Parameters:

  • id = the user's ID (required, obtained from query param)
  • user = a user object
    • first_name (string)
    • last_name (string)
    • email (string)
    • xango_id (string)
    • iuvare_id (string)
    • sponsor_xango_id (string)
    • placement_xango_id (string)
    • picture (image type)
    • password (string)
    • password_confirmation (string)

Result data structure:

  • user object
    • first_name (string)
    • last_name (string)
    • email (string)
    • xango_id (string)
    • iuvare_id (string)
    • sponsor_xango_id (string)
    • sponsor_iuvare_id (string)
    • placement_xango_id (string)
    • placement_iuvare_id (string)
    • active (boolean)
    • payment_expiration (datetime)
    • xango_rank (string)
    • picture (url)

Get funnel progress

GET /users/progress.json
http://localhost:3000/users/progress.json
Gets the funnel progress numbers for the actual user's contact list activity

Result data structure:

  • to_invite (integer)
  • contacted (integer)
  • to_close (integer)
  • to_register (integer)
  • registered (integer)

Password recovery

POST /users/password.json
http://localhost:3000/users/password.json
Sends the request for password recovery
Parameters:

  • utf8 = with value "V" (string)
  • user = a user object
    • email (string)

Password change

PUT /users/password.json
http://localhost:3000/users/password.json
Changes the password
Parameters:

  • utf8 = with value "V" (string)
  • user = a user object
    • reset_password_token (string)
    • password (string)
    • password_confirmation (string)

###Register POST /users.json
http://localhost:3000/users.json
Registers a new user
Parameters:

  • token = a valid register token (obtained from query param)
  • user = a user object
    • first_name (string)
    • last_name (string)
    • email (required, string)
    • password (required, string)
    • password_confirmation (required, string)
    • xango_id (string)
    • iuvare_id (string)
    • sponsor_xango_id (string)
    • placement_xango_id (string)
    • upline_id (integer)

Collages

Create by user_id

POST /collage_images/create_by_user_id.json http://localhost:3000/collage_images/create_by_user_id.json
Creates a collage picture

Parameters:

  • user_id (integer, required)
  • picture (picture 'image type', required)
  • order (integer, required)

Result data structure:

  • collage_image object
    • id (integer)
    • picture (string url)
    • order (integer)

Get collages by user_id

GET /collages/by_user.json?user_id=ID http://localhost:3000/collages/by_user.json?user_id=ID
Gets the user's collage

Result data structure:

  • collages (collage object array) At this time, it only contains one collage object.
    • id (integer)
    • user_id (integer)
    • name (string)
    • order (integer)
    • collage_images (collage_image object array)
      • id (integer)
      • picture (string url)
      • order (integer)

Delete collage_image

DELETE /collage_images/ID.json
http://localhost:3000/collage_images/ID.json
Deletes collage_image

This one returns only a status 204, with no body and response object.

##Events

Get current

GET /events/current.json
http://localhost:3000/events/current.json
Gets the current's month event, nil if there's no event for this month

UPDATE: it can receive event_type param. If not specified, default is 'seminar'.

EVENT_TYPES = ['seminar', 'convention']  

Result data structure:

  • event object array
    • title (string)
    • date (datetime)
    • description (string)
    • picture (url string)

##Contacts

Create

POST /contacts.json
http://localhost:3000/contacts.json
Creates a contact

Parameters:

  • contact = a contact object
    • user_id (integer, required)
    • name (string, required)
    • email (string, required)
    • phone (string, required)
    • description (string, required)

(initial status assigned implicitly: 'to_invite')

Update contact

PUT /contacts/ID.json
http://localhost:3000/contacts/ID.json
Updates a contact

Parameters:

  • contact = a contact object
    • user_id (integer)
    • name (string)
    • email (string)
    • phone (string)
    • description (string)
    • status (string, possible status to update: 'ruled_out' and 'registered' when the contact has status: 'to_close')

Delete contact

DELETE /contacts/ID.json
http://localhost:3000/contacts/ID.json
Deletes contact

This one returns only a status 204, with no body and response object.

Get contact transitions

GET /contacts/transitions.json
http://localhost:3000/contacts/transitions.json
Gets the valid transitions status

Result data structure:
{"transitions":{"to_invite":{"previous":null,"next":["contacted"]},"contacted":{"previous":["to_invite"],"next":["to_close"]},"to_close":{"previous":["contacted"],"next":["ruled_out","registered"]},"ruled_out":{"previous":["to_close"],"next":null},"registered":{"previous":["to_close"],"next":null}}}

### Get contacts by user
GET /contacts/by_user.json
http://localhost:3000/contacts/by_user.json
Gets all the contacts per user

Parameters:

  • user_id (integer, required)

Result data structure:

  • contacts (contact object array)
    • id (integer)
    • user_id (integer)
    • name (string)
    • email (string)
    • phone (string)
    • description (string)
    • status (string)
    • test_score object (if the contact has completed the 'multiple' test_type test)
      • id (integer)
      • user_id (integer)
      • score (float - percentage)
      • description (string)

##Assets

Get by asset_type

GET /assets/by_asset_type.json
http://localhost:3000/assets/by_asset_type.json
Gets all the assets by asset_type

ASSET_TYPES = ['audio', 'seminar', 'convention', 'training', 'document']

Parameters:

  • asset_type (string, required)

Result data structure:

  • assets (asset object array)
    • id (integer)
    • title (string)
    • description (string)
    • author (string)
    • source (string)
    • purchasable (boolean)
    • price (float)
    • asset_type (string)
    • test object
      (if asset has associated a test, null otherwise)
      • id (integer)
      • name (string)
      • test_type (string)

Get by keyword and asset_type

GET /assets/by_keyword_and_asset_type.json
http://localhost:3000/assets/by_keyword_and_asset_type.json
Gets all the assets by asset_type and keyword, that will be used to search in the asset's fields: description, title, and author

ASSET_TYPES = ['audio', 'seminar', 'convention', 'training', 'document']

Parameters:

  • asset_type (string, required)
  • keyword (string, required)

Result data structure:

  • assets (asset object array)
    • id (integer)
    • title (string)
    • description (string)
    • author (string)
    • source (string)
    • purchasable (boolean)
    • price (float)
    • asset_type (string)
    • test object
      (if asset has associated a test, null otherwise)
      • id (integer)
      • name (string)
      • test_type (string)

##Plans

Send video

POST /plans/send_video.json
http://localhost:3000/plans/send_video.json
Sends a video to a contact in the user's contact list

Parameters:

  • contact_id (integer, required)
  • user_id (integer, required)
  • asset_id (integer, required)

Result data structure:

  • plan object
    • id (integer)
    • asset_id (integer)
    • token (integer)
    • expiration (datetime)
    • description (integer)
    • contact object
      • id (integer)
      • user_id (integer)
      • name (string)
      • email (string)
      • phone (string)
      • description (string)
      • status (string)

Can watch video

POST /plans/watch_video.json
http://localhost:3000/plans/watch_video.json
Service to know if the video can be played or not

Parameters:

  • token (string, required)

Result data structure:

  • plan object
    • id (integer)
    • token (integer)
    • expiration (datetime)
    • description (integer)
    • contact object
      • id (integer)
      • user_id (integer)
      • name (string)
      • email (string)
      • phone (string)
      • description (string)
      • status (string)
    • asset object
      • id (integer)
      • title (string)
      • description (string)
      • author (string)
      • source (string)
      • purchasable (boolean)
      • price (float)
      • asset_type (string)
      • test object
        • id (integer)
        • name (string)
        • test_type (string)
        • questions (question object array)
          • id (integer)
          • test_id (integer)
          • text (string)
          • answers (answer object array)
            • id (integer)
            • question_id (integer)
            • text (string)

Finish watching video

GET /plans/ID/finish_video.json
http://localhost:3000/plans/ID/finish_video.json
Service to call when the user finishes watching the video

Parameters:

  • id (integer, required)

Result data structure:

  • plan object
    • id (integer)
    • asset_id (integer)
    • token (integer)
    • expiration (datetime)
    • description (integer)
    • contact object
      • id (integer)
      • user_id (integer)
      • name (string)
      • email (string)
      • phone (string)
      • description (string)
      • status (string)

##Tests

Get

GET /tests/by_code.json
http://localhost:3000/tests/by_code.json?code=CODE
Test with questions and answers

CODES = ['color', 'module_1', 'module_2', 'module_3', 'basics']

Parameters:

  • code (string, required)

Result data structure:

  • test object
    • id (integer)
    • name (string)
    • test_type (string)
    • code (string)
    • instructions (text)
    • questions (question object array)
      • id (integer)
      • test_id (integer)
      • text (string)
      • answers (answer object array)
        • id (integer)
        • question_id (integer)
        • text (string)

Grade

POST /test_scores/grade_test.json
http://localhost:3000/tests/grade_test.json
Grade test answers

Parameters:

  • user_id (integer, optional - required for all except 'percentage' test_type)
  • test_code (string, required)
  • answers (answer object array, required)
    • id (integer, required)
  • contact_id (integer, optional - required IF grading 'multiple' test_type)

Result data structure:

  • test object
    • id (integer)
    • name (string)
    • test_type (string)
    • code (string)
    • instructions (text)
    • test_scores (test_score object array) (One result for 'correct_incorrect' and 'multiple' test_type, multiple results for 'percentage' test_type)
      • id (integer)
      • user_id (integer)
      • score (float - percentage)
      • description (string)

Get Results by code and user

GET /tests/by_code_and_user.json
http://localhost:3000/tests/by_code_and_user.json?user_id=USER_ID&test_code=TEST_CODE
Gets test results for user and test_code

Parameters:

  • user_id (integer, required)
  • test_code (string, required)

Result data structure:

  • test object
    • id (integer)
    • name (string)
    • test_type (string)
    • code (string)
    • instructions (text)
    • test_scores (test_score object array)
      • id (integer)
      • user_id (integer)
      • score (float - percentage)
      • description (string)
      • description_spanish (string)

Get Results by user

GET /tests/by_user.json
http://localhost:3000/tests/by_user.json?user_id=USER_ID
Gets test results for user

Parameters:

  • user_id (integer, required)

Result data structure:

  • tests (test object array)
    • id (integer)
    • name (string)
    • test_type (string)
    • code (string)
    • test_scores (test_score object array)
      • id (integer)
      • user_id (integer)
      • score (float - percentage)
      • description (string)
      • description_spanish (string)

##Invitations

Create

POST /invitations.json
http://localhost:3000/invitations.json
Creates an invitation
Parameters:

  • invitation = an invitation object
    • user_id (integer, required)
    • recipient_name (string, required)
    • recipient_email (string, required)

##Requests

Create

POST /requests.json
http://localhost:3000/requests.json
Creates a request
Parameters:

  • request = a request object
    • user_id (integer, required)
    • source_name (string, required)
    • source_email (string, required)
    • source_text (string, optional)

Accept

POST /requests/ID/accept.json
http://localhost:3000/requests/ID/accept.json
Accepts a request
Parameters:

  • ID = request's id

Reject

POST /requests/ID/reject.json
http://localhost:3000/requests/ID/reject.json
Rejects a request
Parameters:

  • ID = request's id

Downlines (Network)

All

GET /downline/all.json
http://localhost:3000/downlines/all.json
Gets all the logged user's downlines (whole network)
Returns an array with downlines. Each downline is a user object
UPDATE: Each downline now includes test_scores and downline_count properties

Cycle

GET /downline/cycle.json
http://localhost:3000/downlines/cycle.json
Gets the logged user's cycle downlines
Returns an array with downlines. Each downline is a user object

Change Position

POST /downline/change_position.json http://localhost:3000/downlines/ID/change_position.json
Changes a downline's position
URL Parameters:

  • ID = the downline's ID
    Body Parameters:
  • position = downline´s new position. Values allowed: 1 to 4 (integer)

Returns the updated downline object

Goals

Obtain by user

GET /goals/by_user.json http://localhost:3000/goals/by_user.json?user_id=ID
Gets goals by user ID
Parameters:

  • user_id

Create

POST /goals.json
http://localhost:3000/goals.json
Creates a goal

GOAL TYPES = ['be', 'que quiero ser'], ['do', 'que quiero hacer'], ['have', 'que quiero tener'], ['travel', 'a donde quiero viajar'], ['share', 'que quiero compartir'], ['worry_not', 'de que no me quiero preocupar']

Parameters:

  • goal = a goal object
    • dream (text, required)
    • goal (text, required)
    • date (string in the format 'YYYY-MM-DD', required)
    • user_id (integer, required)
    • goal_type (string, required)

Update

PUT /goals/ID.json
http://localhost:3000/goals/id.json
Updates a goal. It will only update the parameters sent.
Parameters:

  • id = the goal id
  • goal = a goal object
    • dream (text, optional)
    • goal (text, optional)
    • date (string in the format 'YYYY-MM-DD', optional)
    • user_id (integer, required)
    • goal_type (string, optional)

Offices

GET /offices/ordered_by_name.json
http://localhost:3000/offices/ordered_by_name.json
Obtains all the offices ordered by name.

Historic Assets

GET /historic_assets/by_type.json
http://localhost:3000/historic_assets/by_type.json?historic_asset_type=[historic_asset_type]
Gets historic assets by type, nil if there are no assets of that type

Parameters:

  • historic_asset_type

    HISTORIC_ASSET_TYPES = ['audio', 'book']

Result data structure:

  • historic asset array
    • id (integer)
    • description (text)
    • historic_asset_type (string)