module DeskApi::Resource::QueryParams

{DeskApi::Resource::QueryParams} specifies all the url query param modifiers.

@author Thomas Stachl <tstachl@salesforce.com> @copyright Copyright © 2013-2016 Salesforce.com @license BSD 3-Clause License

@example set the per page param {DeskApi::Resource}

first_page = DeskApi.cases.per_page(100)

Public Instance Methods

embed(*embedds) click to toggle source

Allows you to embed/sideload resources

@example embed customers with their cases

my_cases = client.cases.embed(:customers)

@example embed assigned_user and assigned_group

my_cases = client.cases.embed(:assigned_user, :assigned_group)

@param embedds [Symbol/String] whatever you want to embed @return [Desk::Resource] self

# File lib/desk_api/resource/query_params.rb, line 50
def embed(*embedds)
  # make sure we don't try to embed anything that's not defined
  # add it to the query
  self.tap{ |res| res.query_params = { embed: embedds.join(',') } }
end
query_params() click to toggle source

Converts the current self href query params to a hash

@return [Hash] current self href query params

# File lib/desk_api/resource/query_params.rb, line 75
def query_params
  Addressable::URI.parse(href).query_values || {}
end
query_params=(params = {}) click to toggle source

Sets the query params based on the provided hash

@param params [Hash] the query params @return [String] the generated href

# File lib/desk_api/resource/query_params.rb, line 91
def query_params=(params = {})
  return href if params.empty?

  params.keys.each{ |key| params[key] = params[key].join(',') if params[key].is_a?(Array) }

  uri = Addressable::URI.parse(href)
  params = (uri.query_values || {}).merge(params)

  @_loaded = false unless params == uri.query_values

  uri.query_values = params
  self.href = uri.to_s
end
query_params_include?(param) click to toggle source

Checks if the specified param is included

@param param [String] the param to check for @return [Boolean]

# File lib/desk_api/resource/query_params.rb, line 83
def query_params_include?(param)
  query_params.include?(param) ? query_params[param] : nil
end