Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languageruby
def request_bpm_backend(path, method=:get, parameters={})
  request_params = {
      method:   method,
      url:      build_bpm_widget_path(path),
      user:     bpm_config.login,
      password: bpm_config.password
  }

  if method == :get
    request_params.merge!({headers: {params: parameters.merge(bpm_parameters)}})
  else
    request_params.merge!({payload: parameters.merge(bpm_parameters)})
  end

  response(params)
end

private

def response(params)
  response = RestClient::Request.execute(params)

  {
    code: response.code,
    headers: response.headers,
    body: response.body
  }
end

def request_params(path)
  {
    url:      build_bpm_widget_path(path),
    user:     configuration[:login],
    password: configuration[:password],
    headers: {
      'Content-Type': 'application/json'
    }
  }
end

def build_bpm_widget_path(path = '')
  URI.join(configuration[:url], '/widget/', path)
end

def configuration
  {
    url:      "http://homs:3000", # hbw_url
    login:    "user@example.com",      # hbw_login
    password: "renewmeplease"          # hbw_token
  }
end

def with_user_identifier(parameters)
  parameters.merge(
    user_identifier: session[:email] # email of current user
  )
end     
  
def allow_params(*allowed_params)
  with_user_identifier(params.slice(*allowed_params))
end

...