R/endpoints.R

Defines functions translate sell_users recurring_rev get_terms quote_tabs get_quotes get_items get_customer

Documented in get_customer get_items get_quotes get_terms quote_tabs recurring_rev sell_users translate

# endpoints.R


#' Quote Customer
#'
#' Detailed quote information.
#'
#' @param quote_id NULL
#' @param customer_id NULL
#' @param ... Arguments to pass to `get_sell()`
#'
#' @return Detailed quote information.
#' @export
#'
#' @examples \dontrun{
#'     quote_customer(quote_id = )
#' }
get_customer <- function(
  quote_id = NULL,
  customer_id = NULL, ...
) {

  endpoint <- paste0('/api/quotes/', as.character(quote_id), '/customers')
  if (!is.null(customer_id)) {
    endpoint <- paste0(endpoint, '/', customer_id)
  }

  get_sell(endpoint)

}


#' Quote items
#'
#' Product information related to quotes.
#'
#'
#' @param fields Which fields to include.
#' @param conditions Some conditions
#' @param page Which page?
#' @param pageSize How many rows.
#' @param ... ...
#'
#' @return Product list associated with quotes.
#' @export
#'
#' @examples \dontrun{
#'
#' get_items()
#'
#' }
get_items <- function(
  quote_id = NULL,
  fields = NULL,
  conditions = NULL,
  page = NULL,
  pageSize = NULL, ...
) {

  endpoint <- paste0('/api/quoteItems', quote_id)
  get_sell(endpoint,
           includeFields = fields, conditions = conditions,
           page = page, pageSize = pageSize)

}


#' Quotes
#'
#' Returns a list of quotes.
#'
#' Search quotes by crmOpportunityID in ordert to return the
#' quote number.
#'
#' TO return specific fields, set `trunc = FALSE`.
#'
#' @inheritParams get_items
#' @param trunc TRUE returns a dataframe with fewer columns.
#'
#' @return List of quotes.
#' @export
#'
#' @examples \dontrun{
#'
#'     get_quotes()
#'
#' }
get_quotes <- function(
  fields = NULL,
  conditions = NULL,

  page = NULL,
  pageSize = NULL,
  trunc = TRUE, ...) {

  if (trunc == TRUE | is.null(fields)) {
    fields <- short_fields()
  }

  #print(fields)
  endpoint <- '/api/quotes'
  get_sell(endpoint, page = page, pageSize = pageSize,
           includeFields = fields, conditions = conditions
  )

}



#' Quote Tabs
#'
#' Specific quote information.
#'
#' Include the quote id to return product information.
#'
#' @param quote_id Quote id number
#' @inheritParams get_items
#'
#' @return List of quotes.
#' @export
#'
#' @examples \dontrun{
#'
#'     quote_tabs()
#'
#' }
quote_tabs <- function(
  quote_id = NULL,
  fields = NULL,
  conditions = NULL,
  page = NULL,
  pageSize = NULL,
  ...) {

  endpoint <- '/api/quoteTabs'

  if (!is.null(quote_id)) {
    endpoint <- paste0(endpoint, '/', quote_id, '/quoteItems')
  }

  get_sell(endpoint, includeFields = fields,
           conditions = conditions, page = page, pageSize = pageSize)

}




#' Quote Terms
#'
#' Payment schedule associated with a quote.
#'
#' @param quote_id Quote id number
#' @inheritParams get_items
#'
#' @return dataframe
#' @export
#'
#' @examples \dontrun{
#'
#'     get_terms()
#'
#' }
get_terms <- function(
  quote_id = NULL,
  fields = NULL,
  conditions = NULL,
  page = NULL,
  pageSize = NULL,
  ...) {

  endpoint <- paste0('/api/quotes/', quote_id, '/quoteTerms')

  get_sell(endpoint, includeFields = fields,
           conditions = conditions, page = page, pageSize = pageSize)

}




#' Recurring revenue
#'
#' Recurring revenue
#'
#' @inheritParams get_items
#'
#' @return dataframe
#' @export
#'
#' @examples \dontrun{
#'
#'     get_terms()
#'
#' }
recurring_rev <- function(conditions = NULL,
                          page = NULL, pageSize = NULL, ...) {

  endpoint <- '/api/recurringRevenues'

  get_sell(endpoint, conditions = conditions, page = page, pageSize = pageSize)

}



#' Me
#'
#' Users
#'
#' @return dataframe
#' @export
#'
#' @examples \dontrun{
#'
#'     sell_users()
#'
#' }
sell_users <- function() {

  endpoint <- '/settings/user'
  get_sell(endpoint)

}



#' Translate CW to Sell
#'
#' Takes an opp_id and converts to Sell id.
#'
#' @param cw_opp
#'
#' @export
translate <- function(cw_opp = NULL) {
  sell_resp <- get_quotes(
    conditions = paste0('crmOpportunityID = ', cw_opp),
    fields = 'name,id,accountName,quoteNumber',
    trunc = FALSE
  )

  sell_resp[c('id', 'accountName', 'name', 'quoteNumber')]

}
Cloud9Smart/sell documentation built on Nov. 12, 2020, 9:44 p.m.