Class: Samwise::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/samwise/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, sam_status_key: Samwise::Protocol::SAM_STATUS_KEY) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
# File 'lib/samwise/client.rb', line 6

def initialize(api_key: nil, sam_status_key: Samwise::Protocol::SAM_STATUS_KEY)
  @api_key        = api_key        || ENV['DATA_DOT_GOV_API_KEY']
  @sam_status_key = sam_status_key || ENV['SAM_STATUS_KEY']
  @client = HTTPClient.new
end

Instance Method Details

#duns_is_in_sam?(duns: nil, delay: 1) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/samwise/client.rb', line 17

def duns_is_in_sam?(duns: nil, delay: 1)
  sleep(delay)
  response = lookup_duns(duns: duns)
  response.status == 200
end

#excluded?(duns: nil) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/samwise/client.rb', line 28

def excluded?(duns: nil)
  response = lookup_duns(duns: duns)
  JSON.parse(response.body)["hasKnownExclusion"] == false
end

#get_duns_info(duns: nil) ⇒ Object



12
13
14
15
# File 'lib/samwise/client.rb', line 12

def get_duns_info(duns: nil)
  response = lookup_duns(duns: duns)
  JSON.parse(response.body)
end

#get_sam_status(duns: nil) ⇒ Object



23
24
25
26
# File 'lib/samwise/client.rb', line 23

def get_sam_status(duns: nil)
  response = lookup_sam_status(duns: duns)
  JSON.parse(response.body)
end

#small_business?(duns: nil, naicsCode: nil) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/samwise/client.rb', line 33

def small_business?(duns: nil, naicsCode: nil)
  response = lookup_duns(duns: duns)
  data = JSON.parse(response.body)["sam_data"]["registration"]

  if data["certifications"] == nil
    return false
  end
  data = data["certifications"]["farResponses"]
  small_biz_array = data.find{|far|far["id"]=="FAR 52.219-1"}["answers"].find{"naics"}["naics"]

  # Allows for exact matches of a NAICS Code *or* NAICS code that starts with the argument.
  # E.g., 541511 matches, but 54151 also matches
  if small_biz_array.class == Array
    naics = small_biz_array.find{|naics|naics["naicsCode"].to_s.start_with?(naicsCode.to_s)}
  else
    naics = small_biz_array
  end

  # Check for the NAICS Code and, if found, check whether it's a small
  if naics == nil
    false
  else
    naics["isSmallBusiness"] == "Y"
  end
end