Class: Credova::FFL

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

Constant Summary collapse

REQUIRED_CREATE_ATTRS =
i( license_number expiration address_one city state zip )
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



14
15
16
# File 'lib/credova/ffl.rb', line 14

def initialize(client)
  @client = client
end

Instance Method Details

#create(options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/credova/ffl.rb', line 18

def create(options = {})
  requires!(options, REQUIRED_CREATE_ATTRS)

  endpoint = ENDPOINTS[:create]
  data = format_data_for_create(options)
  headers  = [
    *auth_header(@client.access_token),
    *content_type_header('application/json'),
  ].to_h

  post_request(endpoint, data, headers)
end

#upload_document(ffl_public_id, ffl_document_url) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/credova/ffl.rb', line 31

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