usaspending 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ module USA
2
+
3
+ class Contract < Base
4
+
5
+ attr_accessor :transactionnumber, :programsourcedescription, :programsource, :majorfundingagency, :facevalue, :dollarsobligated, :competitioncategory, :vendorname, :typeofspending, :recipientzipcode, :datesigned, :typeoftransaction, :placeofperformancestate, :psccategorycode, :contractpricing, :idvprocurementinstrumentid, :awardtype, :record_count, :recipientstate, :parentrecipientorcompanyname, :idvagency, :fundingagency, :recipientcountyname, :recipientaddressline123, :projectdescription, :principalnaicscode, :modificationnumber, :recipientorcontractorname, :recipientcity, :programsourceagencycode, :programsourceaccountcode, :federalawardid, :fiscalyear, :majoragency, :contractororrecipientid, :recipientcongressionaldistrict, :productorservicecode, :procurementinstrumentid, :placeofperformancecongdistrict, :extentcompeted, :dunsnumber, :recipientname, :principalplacecountyorcity, :placeofperformancezipcode, :contractingagency
6
+
7
+ def initialize(params)
8
+ if params
9
+ self.set_instance_methods(params)
10
+ end
11
+ end
12
+
13
+
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,280 @@
1
+ module USA
2
+
3
+ class Procurement < Base
4
+
5
+ def initialize
6
+ @database = 'fpds'
7
+ @query = {}
8
+ @errors = {}
9
+ end
10
+
11
+ #returns current database
12
+ def database
13
+ @database
14
+ end
15
+
16
+ def errors
17
+ @errors
18
+ end
19
+
20
+ # city The city within a contractor's address
21
+ def city(city_value)
22
+ @query[:city] = city_value unless city_value == ""
23
+ self
24
+ end
25
+
26
+ #accepts abbreviate country letters and vendor or performance for place of performance, defaults to vendor
27
+ def country(country_abbr_value, location_type='vendor')
28
+ require "../lib/codes/countries.rb"
29
+ if country_codes["#{country_abbr_value}"]
30
+ location_type != 'vendor' ? @query[:placeOfPerformanceCountryCode] = country_abbr_value : @query[:vendorCountryCode] = country_abbr_value
31
+ else
32
+ @errors[:country] = "Couldn't find the country code."
33
+ end
34
+ self
35
+ end
36
+
37
+ #accepts abbreviated list of congressional districts and vendor or performance, defaults to vendor
38
+ def congress_district(congress_value, location_type='vendor')
39
+ require '../lib/codes/congress_districts.rb'
40
+ if congress_districts["#{congress_value}"]
41
+ location_type != 'vendor' ? @query[:pop_cd] = congress_value : @query[:vendor_cd] = congress_value
42
+ else
43
+ @errors[:congress_district] = "Couldn't find that congressional district code."
44
+ end
45
+ self
46
+ end
47
+
48
+ def piid(piid_value)
49
+ @query[:PIID] = piid_value
50
+ self
51
+ end
52
+
53
+ def contract_requirement(description)
54
+ @query[:descriptionOfContractRequirement] = description
55
+ self
56
+ end
57
+
58
+ #he contractor duns number.
59
+ def duns_number(duns_value)
60
+ @query[:duns_number] = duns_value
61
+ self
62
+ end
63
+
64
+ #Full text search of program source description.
65
+ def program_description(description)
66
+ @query[:program_source_desc] = description
67
+ self
68
+ end
69
+
70
+ # Determines the Business Fund Indicator:
71
+ # r = funds provided by Recovery Act
72
+ def business_fund(fund_value)
73
+ @query[:busn_indctr] = fund_value
74
+ self
75
+ end
76
+
77
+ #The program source agency code.
78
+ def program_code(code_value)
79
+ @query[:program_source_agency_code] = code_value
80
+ self
81
+ end
82
+
83
+ #The program source account code.
84
+ def program_account(account_value)
85
+ @query[:program_source_account_code] = account_value
86
+ self
87
+ end
88
+
89
+ #The 4-digit code for a specific governmental agency issuing contracts. See here http://www.usaspending.gov/apidocsmore.html#FPDS_AGENCY.
90
+ def agency(code)
91
+ require '../lib/codes/fpds_agencies.rb'
92
+ if agency_codes["#{code}"]
93
+ @query[:mod_agency] = code
94
+ else
95
+ @errors[:agency] = "Couldn't find that agency specific code."
96
+ end
97
+ self
98
+ end
99
+
100
+ #The 2-character code for a major governmental agency issuing contracts. See here http://www.usaspending.gov/apidocsmore.html#FPDS_MAJAGENCY for list.
101
+ def major_agency(code)
102
+ require '../lib/codes/fpds_agencies.rb'
103
+ if major_codes["#{code}"]
104
+ @query[:maj_agency_cat] = code
105
+ else
106
+ @errors[:major_agency] = "Couldn't find that major agency category code."
107
+ end
108
+ self
109
+ end
110
+
111
+ # The 2-character code for a major product or service category. See here http://www.usaspending.gov/apidocsmore.html#PSCCAT for list.
112
+ def product_category(code)
113
+ require '../lib/codes/products_services.rb'
114
+ if product_category_codes["#{code}"]
115
+ @query[:psc_cat] = code
116
+ else
117
+ @errors[:product_category] = "Couldn't find that major product category code."
118
+ end
119
+ self
120
+ end
121
+
122
+ # The 4-character code for a product or service. See here http://www.usaspending.gov/apidocsmore.html#PSC for list.
123
+ def product(code)
124
+ require '../lib/codes/products_services.rb'
125
+ if product_codes["#{code}"]
126
+ @query[:psc_sub] = code
127
+ else
128
+ @errors[:product] = "Couldn't find that product code."
129
+ end
130
+ self
131
+ end
132
+
133
+ # The competition status of a contract. Values are:
134
+ # everyone or c = Available for everyone for competition
135
+ # one offer or o = Everyone could compete, but only one bid or offer was recieved
136
+ # pool p = Competition within a limited pool
137
+ # no n = Not competed for an allowable reason
138
+ # groups a = Available only for groups such as disabled persons, prisoners, and regulated utilities
139
+ # actions f = Actions necessary to continue existing competitive contracts for continuity (until the next one could be competed)
140
+ # unknown u = Not identified, soon to be addressed
141
+ # compete_cat
142
+
143
+ def competition_status(cat_value)
144
+ @query[:complete_cat] = case cat_value
145
+ when "everyone", "c" then "c"
146
+ when "One offer", "o" then "o"
147
+ when "pool", "p" then "p"
148
+ when "no", "n" then "n"
149
+ when "groups", "a" then "a"
150
+ when "actions", "f" then "f"
151
+ else "u"
152
+ end
153
+ self
154
+ end
155
+
156
+ # state The state abbreviation within a contractor's address.
157
+ def state(state_value, location_type='vendor')
158
+ location_type != 'vendor' ? @query[:stateCode] = state_value : @query[:state] = state_value
159
+ self
160
+ end
161
+
162
+ # ZIPCode The ZIP code within a contractor's address.
163
+ def zip(zip_value, location_type='vendor')
164
+ location_type != 'vendor' ? @query[:placeOfPerformanceZIPCode] = zip_value : @query[:ZIPCode] = zip_value
165
+ self
166
+ end
167
+
168
+ #Specify a company name
169
+ def company_name(company_name_value = nil)
170
+ @query[:company_name] = company_name_value unless company_name_value == ""
171
+ self
172
+ end
173
+
174
+ # Determines how records are sorted. Valid values are:
175
+ # name or r = by contractor or recipient name
176
+ # dollars or f = by dollars of awards (in descending order)
177
+ # major or g = by major contracting agency
178
+ # category or p = by Product or Service Category
179
+ # date or d = by date of award
180
+ # Defaults to sort by dollars if not provided.
181
+ def sort_by(sortby_number)
182
+ @query[:sortby] = case sortby_number
183
+ when "name", "r" then "r"
184
+ when "dollars", "f" then "f"
185
+ when "major agency", "g" then "g"
186
+ when "category", "p" then "p"
187
+ when "date", "d" then "d"
188
+ else "f"
189
+ end
190
+ self
191
+ end
192
+
193
+ #specify time frame in years. Requires start value if specified, otherwise, leaving this function will default to all fiscal years
194
+ #entering a wrong year will default to the current year
195
+ def years(s_year, end_year = nil )
196
+ start_year = s_year.to_i
197
+ end_year = end_year.to_i unless end_year.nil?
198
+ if end_year
199
+ if start_year < 2000 || start_year > Time.now.year.to_i + 1
200
+ @errors[:years] = "Problem with Start Year"
201
+ else
202
+ if end_year > start_year && end_year < Time.now.year.to_i + 1
203
+ @query[:first_year_range] = start_year
204
+ @query[:last_year_range] = end_year
205
+ else
206
+ @errors[:years] = "Problem with End Year"
207
+ end
208
+ end
209
+ elsif start_year < 2000 or start_year > Time.now.year.to_i + 1
210
+ @errors[:years] = "Problem with Start Year"
211
+ else
212
+ @query[:fiscal_year] = start_year
213
+ end
214
+ self
215
+ end
216
+
217
+ # Allows you to set the starting position of the records to be retrieved, defaults to 1 if less than 0
218
+ def start_from(start_number)
219
+ @query[:records_from] = start_number > 0 ? start_number : 1
220
+ self
221
+ end
222
+
223
+ #Allows you to set the maximum number of records retrieved to fewer than 1000
224
+ # defaults to 1000 when over a 1000
225
+ def max_records(max_number)
226
+ @query[:max_records] = max_number.to_i < 1000 ? max_number : 1000
227
+ self
228
+ end
229
+
230
+ def record(record_number)
231
+ #set the detail to c
232
+ self.detail("c")
233
+ @query[:record_id] = record_number
234
+ self
235
+ end
236
+
237
+ # accepts values b or c, defaults to b
238
+ def detail(detail_number)
239
+ if ["b", "c"].include?(detail_number.downcase)
240
+ detail_value = detail_number
241
+ else
242
+ detail_value = "b"
243
+ end
244
+ @query[:detail] = detail_value
245
+ self
246
+ end
247
+
248
+ #return current query
249
+ def query
250
+ @query
251
+ end
252
+
253
+ # Clears all the query filters to make a new search
254
+ def clear
255
+ @fetch = nil
256
+ @query = {}
257
+ self
258
+ end
259
+
260
+ def url
261
+ construct_url(database, @query)
262
+ end
263
+
264
+ # Fetch the Procurement Search returning parsed xml
265
+ def fetch
266
+ get_data(url)
267
+ end
268
+
269
+ # Fetch the Procurement Search returning array of contract objects
270
+ def fetch_contracts
271
+ contracts = []
272
+ self.fetch["result"].first.first[1].each do |contract|
273
+ contracts << USA::Contract.new(contract)
274
+ end
275
+ return contracts
276
+ end
277
+
278
+ end # class Procurement
279
+
280
+ end # module USA
data/usaspending.gemspec CHANGED
@@ -1,11 +1,11 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "usaspending"
3
- s.version = "0.1.0"
3
+ s.version = "0.1.1"
4
4
  s.date = "2010-5-17"
5
5
  s.summary = "Ruby gem wrapper for USAspending.gov"
6
6
  s.rubyforge_project = "usaspending"
7
7
  s.email = "melton.dan@gmail.com"
8
8
  s.homepage = "http://github.com/danmelton/usaspending"
9
9
  s.authors = ["Dan Melton"]
10
- s.files = ['usaspending.gemspec','README.textile', 'CHANGES.textile', 'lib/usaspending.rb','lib/usaspending/base.rb' ]
10
+ s.files = ['usaspending.gemspec','README.textile', 'CHANGES.textile', 'lib/usaspending.rb','lib/usaspending/base.rb','lib/usaspending/contract.rb', 'lib/usaspending/procurement.rb' ]
11
11
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dan Melton
@@ -32,6 +32,8 @@ files:
32
32
  - CHANGES.textile
33
33
  - lib/usaspending.rb
34
34
  - lib/usaspending/base.rb
35
+ - lib/usaspending/contract.rb
36
+ - lib/usaspending/procurement.rb
35
37
  has_rdoc: true
36
38
  homepage: http://github.com/danmelton/usaspending
37
39
  licenses: []