samwise 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/lib/samwise/client.rb +4 -26
- data/lib/samwise/duns_lookup.rb +67 -0
- data/lib/samwise/version.rb +1 -1
- data/spec/client_spec.rb +9 -16
- data/spec/vcr/Samwise_Client.yml +55 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60a8b81ebade127d133b53d61ee74274c3eb302e
|
4
|
+
data.tar.gz: 5446af496a94bf610574b4e973bb29687904a8a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6039c73c495aa7d9c2d5bb1367068f3c4945a9ce283f654cd152c31789557089a6670215241508048241cee97744ae4b46203185a2fdefdf70bde267d4847f14
|
7
|
+
data.tar.gz: e76cf4eadaf53d229bb9cb2d45437ad70178b19f1ec9b4dd3caa0c84f974b5f25a46b95a2c834e4fa0f6086f83f6ca905c3175b5c837eb2be60085e2b851fa06
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.0
|
data/lib/samwise/client.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'httpclient'
|
3
|
+
require_relative './duns_lookup'
|
3
4
|
|
4
5
|
module Samwise
|
5
6
|
class Client
|
@@ -19,7 +20,7 @@ module Samwise
|
|
19
20
|
|
20
21
|
{
|
21
22
|
in_sam: parse_response_for_sam_status(response),
|
22
|
-
small_business:
|
23
|
+
small_business: small_business?(response)
|
23
24
|
}
|
24
25
|
end
|
25
26
|
|
@@ -38,37 +39,14 @@ module Samwise
|
|
38
39
|
JSON.parse(response.body)["hasKnownExclusion"] == false
|
39
40
|
end
|
40
41
|
|
41
|
-
def small_business?(duns: nil)
|
42
|
-
response = lookup_duns(duns: duns)
|
43
|
-
parse_response_for_small_business(response)
|
44
|
-
end
|
45
|
-
|
46
42
|
private
|
47
43
|
|
48
44
|
def parse_response_for_sam_status(response)
|
49
45
|
response.status == 200
|
50
46
|
end
|
51
47
|
|
52
|
-
def
|
53
|
-
|
54
|
-
|
55
|
-
data = JSON.parse(response.body)["sam_data"]["registration"]
|
56
|
-
|
57
|
-
far_responses = data['certifications']['farResponses']
|
58
|
-
response_to_small_biz = far_responses.find do |response|
|
59
|
-
response['id'] == Samwise::Protocol::FAR_SMALL_BIZ_CITATION
|
60
|
-
end
|
61
|
-
|
62
|
-
answers = response_to_small_biz['answers']
|
63
|
-
|
64
|
-
naics_answers = answers.find {|answer| answer.has_key?('naics')}['naics']
|
65
|
-
small_business_naics_answers = naics_answers.select do |answer|
|
66
|
-
Samwise::Protocol::NAICS_WHITELIST.include?(answer['naicsCode'])
|
67
|
-
end
|
68
|
-
|
69
|
-
!small_business_naics_answers.detect do |answer|
|
70
|
-
answer['isSmallBusiness'] == 'Y'
|
71
|
-
end.nil?
|
48
|
+
def small_business?(response)
|
49
|
+
Samwise::DunsLookup.new(response).small_business?
|
72
50
|
end
|
73
51
|
|
74
52
|
def lookup_duns(duns: nil)
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Samwise
|
2
|
+
class DunsLookup
|
3
|
+
attr_reader :response
|
4
|
+
|
5
|
+
def initialize(response)
|
6
|
+
@response = response
|
7
|
+
end
|
8
|
+
|
9
|
+
def small_business?
|
10
|
+
if response.status == 200
|
11
|
+
small_business_response
|
12
|
+
else
|
13
|
+
false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def small_business_response
|
20
|
+
if registration_data && certifications && far_responses
|
21
|
+
small_business_response?
|
22
|
+
else
|
23
|
+
false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def small_business_response?
|
28
|
+
!small_business_naics_answers.detect do |answer|
|
29
|
+
answer['isSmallBusiness'] == 'Y'
|
30
|
+
end.nil?
|
31
|
+
end
|
32
|
+
|
33
|
+
def small_business_naics_answers
|
34
|
+
naics_answers.select do |answer|
|
35
|
+
Samwise::Protocol::NAICS_WHITELIST.include?(answer['naicsCode'])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def naics_answers
|
40
|
+
small_business_answers.find do |answer|
|
41
|
+
answer.has_key?('naics')
|
42
|
+
end['naics']
|
43
|
+
end
|
44
|
+
|
45
|
+
def small_business_answers
|
46
|
+
response_to_small_business_questions['answers']
|
47
|
+
end
|
48
|
+
|
49
|
+
def response_to_small_business_questions
|
50
|
+
far_responses.find do |far_response|
|
51
|
+
far_response['id'] == Samwise::Protocol::FAR_SMALL_BIZ_CITATION
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def far_responses
|
56
|
+
certifications['farResponses']
|
57
|
+
end
|
58
|
+
|
59
|
+
def certifications
|
60
|
+
registration_data['certifications']
|
61
|
+
end
|
62
|
+
|
63
|
+
def registration_data
|
64
|
+
@_data ||= JSON.parse(response.body)["sam_data"]["registration"]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/samwise/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -49,6 +49,15 @@ describe Samwise::Client, vcr: { cassette_name: "Samwise::Client", record: :new_
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
context 'when API response does not certification data' do
|
53
|
+
it 'set small_business to false' do
|
54
|
+
incomplete_data_duns = '506163962'
|
55
|
+
response = client.get_vendor_summary(duns: incomplete_data_duns)
|
56
|
+
|
57
|
+
expect(response[:small_business]).to eq(false)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
52
61
|
context 'when the DUNS is in SAM' do
|
53
62
|
it 'has in_sam set to true' do
|
54
63
|
response = client.get_vendor_summary(duns: nine_duns)
|
@@ -165,20 +174,4 @@ describe Samwise::Client, vcr: { cassette_name: "Samwise::Client", record: :new_
|
|
165
174
|
expect(response).to be(false)
|
166
175
|
end
|
167
176
|
end
|
168
|
-
|
169
|
-
context '#small_business?' do
|
170
|
-
context 'the DUNS belongs to a big business' do
|
171
|
-
it 'should return false' do
|
172
|
-
response = client.small_business?(duns: big_biz_duns)
|
173
|
-
expect(response).to be(false)
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
context 'the DUNS belongs to a small business' do
|
178
|
-
it 'should return true' do
|
179
|
-
response = client.small_business?(duns: nine_duns)
|
180
|
-
expect(response).to be(true)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
177
|
end
|
data/spec/vcr/Samwise_Client.yml
CHANGED
@@ -915,4 +915,58 @@ http_interactions:
|
|
915
915
|
FAIR LAKES CIRCLE","stateorProvince":"VA","line2":"GWAC SOLUTIONS CENTER","city":"FAIRFAX"},"purposeOfRegistration":"ALL_AWARDS"}}}'
|
916
916
|
http_version:
|
917
917
|
recorded_at: Tue, 24 May 2016 20:30:30 GMT
|
918
|
-
|
918
|
+
- request:
|
919
|
+
method: get
|
920
|
+
uri: https://api.data.gov/sam/v4/registrations/5061639620000?api_key=<data_dot_gov_api_key>
|
921
|
+
body:
|
922
|
+
encoding: UTF-8
|
923
|
+
string: ''
|
924
|
+
headers:
|
925
|
+
User-Agent:
|
926
|
+
- HTTPClient/1.0 (2.8.0, ruby 2.3.0 (2015-12-25))
|
927
|
+
Accept:
|
928
|
+
- "*/*"
|
929
|
+
Date:
|
930
|
+
- Tue, 07 Jun 2016 00:09:45 GMT
|
931
|
+
response:
|
932
|
+
status:
|
933
|
+
code: 200
|
934
|
+
message: OK
|
935
|
+
headers:
|
936
|
+
Server:
|
937
|
+
- openresty
|
938
|
+
Date:
|
939
|
+
- Tue, 07 Jun 2016 00:09:45 GMT
|
940
|
+
Content-Type:
|
941
|
+
- application/json
|
942
|
+
Transfer-Encoding:
|
943
|
+
- chunked
|
944
|
+
Connection:
|
945
|
+
- keep-alive
|
946
|
+
Vary:
|
947
|
+
- Accept-Encoding
|
948
|
+
- Accept-Encoding
|
949
|
+
X-Ratelimit-Limit:
|
950
|
+
- '25'
|
951
|
+
X-Ratelimit-Remaining:
|
952
|
+
- '24'
|
953
|
+
Age:
|
954
|
+
- '0'
|
955
|
+
Via:
|
956
|
+
- http/1.1 api-umbrella (ApacheTrafficServer [cMsSf ])
|
957
|
+
X-Cache:
|
958
|
+
- MISS
|
959
|
+
body:
|
960
|
+
encoding: UTF-8
|
961
|
+
string: '{"sam_data":{"registration":{"govtBusinessPoc":{"lastName":"RAKIC","address":{"zip":"11111","countryCode":"SRB","line1":"Molerova
|
962
|
+
12/2","stateorProvince":"AA","city":"Belgrade"},"email":"GRAKIC@DEVBASE.NET","nonUsPhone":"381-637074291","firstName":"GORAN"},"hasKnownExclusion":false,"publicDisplay":true,"status":"WIP","corporateStructureCode":"2J","corporateStructureName":"Sole
|
963
|
+
Proprietorship","ncage":"A0C7S","legalBusinessName":"GORAN RAKIC PR DEVBASE","dunsPlus4":"0000","congressionalDistrict":"
|
964
|
+
","bondingInformation":{},"fiscalYearEndCloseDate":"12/31","businessStartDate":"2015-10-28","businessTypes":["VW","2X"],"lastUpdateDate":"2016-03-16
|
965
|
+
17:29:25.0","samAddress":{"zip":"11111","countryCode":"SRB","line1":"MOLEROVA
|
966
|
+
12","city":"Belgrade"},"naics":[{"isPrimary":true,"naicsCode":"541511","naicsName":"CUSTOM
|
967
|
+
COMPUTER PROGRAMMING SERVICES"}],"registrationDate":"2016-03-16 00:00:00.0","creditCardUsage":true,"duns":"506163962","countryOfIncorporation":"SRB","electronicBusinessPoc":{"lastName":"RAKIC","address":{"zip":"11111","countryCode":"SRB","line1":"Molerova
|
968
|
+
12/2","stateorProvince":"AA","city":"Belgrade"},"email":"GRAKIC@DEVBASE.NET","nonUsPhone":"381-637074291","firstName":"GORAN"},"mailingAddress":{"zip":"11111","countryCode":"SRB","line1":"MOLEROVA
|
969
|
+
12/2","city":"Belgrade"},"purposeOfRegistration":"ALL_AWARDS"}}}'
|
970
|
+
http_version:
|
971
|
+
recorded_at: Tue, 07 Jun 2016 00:09:45 GMT
|
972
|
+
recorded_with: VCR 3.0.3
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: samwise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alan deLevie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codeclimate-test-reporter
|
@@ -161,6 +161,7 @@ files:
|
|
161
161
|
- ".gitignore"
|
162
162
|
- ".rdoc_options"
|
163
163
|
- ".rspec"
|
164
|
+
- ".ruby-version"
|
164
165
|
- ".travis.yml"
|
165
166
|
- CONTRIBUTING.md
|
166
167
|
- ChangeLog.md
|
@@ -172,6 +173,7 @@ files:
|
|
172
173
|
- lib/samwise.rb
|
173
174
|
- lib/samwise/cli.rb
|
174
175
|
- lib/samwise/client.rb
|
176
|
+
- lib/samwise/duns_lookup.rb
|
175
177
|
- lib/samwise/error.rb
|
176
178
|
- lib/samwise/protocol.rb
|
177
179
|
- lib/samwise/util.rb
|
@@ -208,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
210
|
version: '0'
|
209
211
|
requirements: []
|
210
212
|
rubyforge_project:
|
211
|
-
rubygems_version: 2.
|
213
|
+
rubygems_version: 2.5.1
|
212
214
|
signing_key:
|
213
215
|
specification_version: 4
|
214
216
|
summary: Ruby access to the SAM.gov API
|