Class: Credova::FFL

Inherits:
Base
  • Object
show all
Includes:
API
Defined in:
lib/credova/ffl.rb

Constant Summary collapse

CREATE_ATTRS =
{
  permitted: i( license_number expiration address address_2 city state zip ).freeze,
  required:  i( license_number expiration address city state zip ).freeze,
}
ENDPOINTS =
{
  create:          "federallicense".freeze,
  upload_document: "federallicense/%s/uploadfile".freeze,
}

Constants included from API

API::API_VERSION, API::DEVELOPMENT_URL, API::PRODUCTION_URL, API::USER_AGENT

Instance Method Summary collapse

Methods included from API

#get_request, #post_request

Constructor Details

#initialize(client) ⇒ FFL

Returns a new instance of FFL.



18
19
20
# File 'lib/credova/ffl.rb', line 18

def initialize(client)
  @client = client
end

Instance Method Details

#create(ffl_data) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/credova/ffl.rb', line 22

def create(ffl_data)
  requires!(options, *REQUIRED_CREATE_ATTRS)

  ffl_data[:expiration] = ffl_data[:expiration].strftime('%Y/%m/%d')
  endpoint = ENDPOINTS[:create]
  headers  = [
    *auth_header(@client.access_token),
    *content_type_header('application/json'),
  ].to_h

  standardize_body_data!(ffl_data, CREATE_ATTRS[:permitted])

  post_request(endpoint, ffl_data, headers)
end

#upload_document(ffl_public_id, ffl_document_url) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/credova/ffl.rb', line 37

def upload_document(ffl_public_id, ffl_document_url)
  endpoint = ENDPOINTS[:upload_document] % ffl_public_id
  data     = { form_data: ['file=@', ffl_document_url, '; type=application/', extract_file_extension(ffl_document_url)].join }
  headers  = [
    *auth_header(@client.access_token),
    *content_type_header('multipart/form-data'),
  ].to_h

  post_request(endpoint, data, headers)
end