Class: DealervaultApi::Delivery

Inherits:
Object
  • Object
show all
Defined in:
lib/dealervault_api/api/delivery.rb

Constant Summary collapse

VALID_PARAMETERS =
{
  feeds: [:fileTypeCode, :compareDate],
  create: [:type, :historicalMonths, :catchupStartDate, :catchupEndDate]
}
VALID_VALUES =
{
  feeds: {
    fileTypeCode: %w[SL]
  },
  create: {
    type: %w[Sample Daily Historical Catchup],
    historicalMonths: true,
    catchupStartDate: true,
    catchupEndDate: true
  }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client) ⇒ Delivery

Returns a new instance of Delivery.



22
23
24
25
# File 'lib/dealervault_api/api/delivery.rb', line 22

def initialize(api_client)
  @api_client = api_client
  @jwt = self.jwt_token
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



3
4
5
# File 'lib/dealervault_api/api/delivery.rb', line 3

def api_client
  @api_client
end

Instance Method Details

#create(program_id, rooftop_id, file_type, delivery_type, options = {}) ⇒ Object

POST - Initiate a dealer delivery



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/dealervault_api/api/delivery.rb', line 60

def create(program_id, rooftop_id, file_type, delivery_type, options={})
  local_var_path = "delivery"
  options.merge!({type: delivery_type})
  options = whitelist_params(options, VALID_PARAMETERS, :create)

  body = {
    programId: program_id,
    rooftopId: rooftop_id,
    fileType: file_type,
    options: options
  }

  body = @api_client.call_api(:POST, local_var_path, headers: {'X-Jwt-Token' => @jwt}, body: body)
  body
end

#data_set(request_id, page_size, params = {}) ⇒ Object

GET - Retrieves a paged data set.



53
54
55
56
57
# File 'lib/dealervault_api/api/delivery.rb', line 53

def data_set(request_id, page_size, params={})
  local_var_path = "delivery"
  params.merge!({requestId: request_id, pageSize: page_size})
  @api_client.call_api(:GET, local_var_path, headers: {'X-Jwt-Token' => @jwt}, query_params: params)
end

#feeds(program_id, compare_date, file_type_code = 'SL', params = {}) ⇒ Object

GET - Retrieve feeds which DealerVault received updated data since the provided compare date.



41
42
43
44
45
46
47
48
49
50
# File 'lib/dealervault_api/api/delivery.rb', line 41

def feeds(program_id, compare_date, file_type_code='SL',params={} )
  local_var_path = "vendor/#{program_id}/feeds/updated-data"
  if compare_date.class == DateTime
    compare_date = compare_date.to_time
  end

  params.merge!({fileTypeCode: file_type_code, compareDate: compare_date.utc.strftime("%FT%T%:z")})
  params = whitelist_params(params, VALID_PARAMETERS, :feeds)
  @api_client.call_api(:GET, local_var_path, headers: {'X-Jwt-Token' => @jwt}, query_params: params)
end

#information(request_id) ⇒ Object

GET - Gets information about a delivery.



35
36
37
38
# File 'lib/dealervault_api/api/delivery.rb', line 35

def information(request_id)
  local_var_path = "delivery/#{request_id}"
  @api_client.call_api(:GET, local_var_path, headers: {'X-Jwt-Token' => @jwt})
end

#jwt_tokenObject

GET - Acquires a JWT token for authentication. Token will be valid for 30 minutes.



28
29
30
31
32
# File 'lib/dealervault_api/api/delivery.rb', line 28

def jwt_token
  local_var_path = 'token'
  body = @api_client.call_api(:GET, local_var_path)
  body['token']
end

#whitelist_params(params, valid_params, key) ⇒ Object



78
79
80
# File 'lib/dealervault_api/api/delivery.rb', line 78

def whitelist_params(params, valid_params, key)
  params.slice(*valid_params[key])
end