class Motivosity::Client

Public Class Methods

new() click to toggle source
# File lib/mvclient/client.rb, line 7
def initialize
  @auth = Auth.new
end

Public Instance Methods

feed(scope = :team, page = 0, comment = true) click to toggle source

returns feed scope is one of :team, :extended_team, :department, or :company

# File lib/mvclient/client.rb, line 67
def feed(scope = :team, page = 0, comment = true)
  scope_param = case scope
    when :team
      "TEAM"
    when :extended_team
      "EXTM"
    when :department
      "DEPT"
    when :company
      "CMPY"
    else
      scope.to_s
  end
  get "/api/v1/feed", scope: scope_param, page: page, comment: comment
end
get_announcements(page = 0) click to toggle source

returns recent announcements

# File lib/mvclient/client.rb, line 61
def get_announcements(page = 0)
  get "/api/v1/announcement", pageNo: page
end
get_balance() click to toggle source

returns balances {

"cashReceiving" : 39, # money received
"cashGiving"    : 10  # money available to give

}

# File lib/mvclient/client.rb, line 45
def get_balance
  get "/api/v1/usercash"
end
get_values() click to toggle source

returns a list of Values [{

"id" : "39602196-7348-cval-aa03-4f8ef9ce45b8",
"name":  "Customer Experience",
"description": "We aspire to create an awesome customer experience in every interaction with our product and people.",

…}, …]

# File lib/mvclient/client.rb, line 36
def get_values
  get "/api/v1/companyvalue"
end
login!(username, password) click to toggle source
# File lib/mvclient/client.rb, line 11
def login!(username, password)
  @auth.login! username, password
end
logout!() click to toggle source
# File lib/mvclient/client.rb, line 15
def logout!
  @auth.logout!
end
search_for_user(search_term, ignore_self = true) click to toggle source

supply a name or part of a name returns a list of matching users [{

"id" => "00000000-0000-user-0000-000000000000",
"fullName" => "Jane Doe",
"avatarUrl" => "user-placeholder.png",
}, ...]
# File lib/mvclient/client.rb, line 26
def search_for_user(search_term, ignore_self = true)
  get "/api/v1/usertypeahead", name: search_term, ignoreSelf: ignore_self
end
send_appreciation!(user_id, opts = {}) click to toggle source

sends appreciation to another User raises BalanceError if insufficient funds exist

# File lib/mvclient/client.rb, line 51
def send_appreciation!(user_id, opts = {})
  params = { "toUserID" => user_id }
  params["companyValueID"] = opts[:company_value_id] if opts[:company_value_id]
  params["amount"] = opts[:amount] if opts[:amount]
  params["note"] = opts[:note] if opts[:note]
  params["privateAppreciation"] = opts[:private] || false
  put "/api/v1/user/#{user_id}/appreciation", {}, params
end

Private Instance Methods

get(path, url_params = {}) click to toggle source
# File lib/mvclient/client.rb, line 95
def get(path, url_params = {})
  process_response(Request.get(path, request_options(path, url_params)))
end
process_response(response) click to toggle source
# File lib/mvclient/client.rb, line 103
def process_response(response)
  @auth.process_response_headers(response) if response.headers['Set-Cookie']
  response_body = JSON.parse(response.body)
  if response.code != 200
    error = case response.code
      when 401
        UnauthorizedError.new(response.message)
      else
        if response.code == 500 && response_body["type"] == "UnbalanceCashGivingBalanceException"
          BalanceError.new("Insufficient funds")
        else
          Error.new(response.message)
        end
    end
    error.response = response
    error.response_body = response_body
    raise error
  end
  response_body
end
put(path, url_params = {}, form_data = {}) click to toggle source
# File lib/mvclient/client.rb, line 99
def put(path, url_params = {}, form_data = {})
  process_response(Request.put(path, request_options(path, url_params, form_data.to_json)))
end
request_options(path, url_params = {}, body = nil) click to toggle source
# File lib/mvclient/client.rb, line 91
def request_options(path, url_params = {}, body = nil)
  { headers: @auth.auth_headers.merge({'Content-Type' => 'application/json'}), query: url_params, body: body }
end