Class: UsersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/users_controller.rb

Overview

Users

Constant Summary

Constant Summary

Constants inherited from ApplicationController

ApplicationController::SupportedClients

Instance Method Summary (collapse)

Methods inherited from ApplicationController

#absolutize_path, #clean_summary

Methods included from Authorization

included, ri?, #role_included?, #set_promotion_for_public_request

Instance Method Details

- (User) show

Get program information for the user including the promotion settings. Should be called for each new session.

URL

/users/:id [GET]

Response Codes
200 OK

Successfully retrieved User object

# Example response
 {
     "user": {
         "needs_to_complete_evaluation": true,
         "row_id": "96.user",
         "car_image_path": "http://example.getfitonroute66.com/images/route66/newconvertable.png",
         "promotion": {
             "row_id": "65.promotion.25",
             "exercise_limit": 90,
             "has_recipes": true,
             "id": 25,
             "user_id": 65,
             "has_team_competition": true,
             "subdomain": "example",
             "exercise_multiplier": 1,
             "minimum_minutes_to_earn_roadsign": 30,
             "promotion_name": "API",
             "program_name": "API"
         },
         "id": 65,
         "last_name": "Doe",
         "team_id": 196,
         "email": "john@doe.com",
         "first_name": "John"
     }
 }

Returns:

  • (User)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/users_controller.rb', line 40

def show
  promotion = @user.promotion
  contact = @user.contact
  has_team_competition = promotion.detail.is_team_link_displayed && !promotion.current_competition.nil?
  path = Constant::Cars.detect{|x| x[0] == "#{@user.trip.profile.car}"}[1]
  item = {
    :user => {
      :row_id => "#{@user.id}.user",
      :id => @user.id,
      :first_name => contact.first_name,
      :last_name => contact.last_name,
      :email => contact.email,
      :needs_to_complete_evaluation => @user.needs_to_complete_evaluation?,
      :team_id => @user.team ? @user.team.id : nil,
      :car_image_path => absolutize_path(path),
      :promotion => {
        :row_id => unique_id_for_item('promotion',promotion.id),
        :id => promotion.id,
        :user_id => @user.id,
        :exercise_limit => promotion.detail.single_day_exercise_limit,
        :exercise_multiplier => promotion.detail.exercise_multiplier,
        :subdomain => promotion.subdomain,
        :program_name => promotion.program_name,
        :promotion_name => promotion.name,
        :has_team_competition => has_team_competition,
        :has_recipes => promotion.detail.is_recipe_link_displayed,
        :minimum_minutes_to_earn_roadsign => 30
      }
    }
  }
  respond_with(item)
end