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,
  find:            "federallicense/licensenumber/%s".freeze,
  upload_document: "federallicense/%s/uploadfile".freeze,
}

Constants included from API

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

Instance Method Summary collapse

Methods included from API

#get_request, #post_file_request, #post_request

Constructor Details

#initialize(client) ⇒ FFL

Returns a new instance of FFL.



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

def initialize(client)
  @client = client
end

Instance Method Details

#create(ffl_data) ⇒ Object



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

def create(ffl_data)
  requires!(ffl_data, *CREATE_ATTRS[:required])

  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

  ffl_data = standardize_body_data(ffl_data, CREATE_ATTRS[:permitted])

  post_request(endpoint, ffl_data, headers)
end

#find(license_number) ⇒ Object



38
39
40
41
42
# File 'lib/credova/ffl.rb', line 38

def find(license_number)
  endpoint = ENDPOINTS[:find] % license_number

  get_request(endpoint, auth_header(@client.access_token))
end

#upload_document(ffl_public_id, ffl_file_data) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/credova/ffl.rb', line 44

def upload_document(ffl_public_id, ffl_file_data)
  requires!(ffl_file_data, *FILE_UPLOAD_ATTRS[:required])

  endpoint = ENDPOINTS[:upload_document] % ffl_public_id

  post_file_request(endpoint, ffl_file_data, auth_header(@client.access_token))
end