usaspending 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.textile +3 -0
- data/README.textile +18 -0
- data/lib/usaspending/base.rb +51 -0
- data/lib/usaspending.rb +9 -0
- data/usaspending.gemspec +11 -0
- metadata +66 -0
data/CHANGES.textile
ADDED
data/README.textile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
h1. USA Spending API Wrapper
|
2
|
+
|
3
|
+
NOTE: This is an unofficial ruby gem. The developer is not connected to USASpending.gov
|
4
|
+
|
5
|
+
h2. Usage
|
6
|
+
|
7
|
+
*Initialize the search*
|
8
|
+
s = USA::Procurement.new
|
9
|
+
|
10
|
+
*Add the qualifiers*
|
11
|
+
s.detail("b").max_records(69).years(2009).state("MO")
|
12
|
+
|
13
|
+
*Fetch the contracts, returns an array of contract objects*
|
14
|
+
s.fetch_contracts
|
15
|
+
|
16
|
+
*Access a contract's attributes*
|
17
|
+
contract = s.fetch_contracts.first
|
18
|
+
contract.dollarsobligated
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module USA
|
2
|
+
|
3
|
+
class Base
|
4
|
+
API_URL = "http://www.usaspending.gov"
|
5
|
+
|
6
|
+
#construct the url. Requires a database name, currently FAADS or FPDS
|
7
|
+
def construct_url(database, params)
|
8
|
+
if database == nil or database == ''
|
9
|
+
raise "Failed to provide a Federal Database such as FAADS or FPDS"
|
10
|
+
else
|
11
|
+
"#{API_URL}/#{database.downcase}/#{database.downcase}.php?datype=X#{hash2get(params)}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Converts a hash to a GET string
|
16
|
+
def hash2get(h)
|
17
|
+
get_string = ""
|
18
|
+
h.each_pair do |key, value|
|
19
|
+
get_string += "&#{key.to_s}=#{CGI::escape(value.to_s)}"
|
20
|
+
end
|
21
|
+
|
22
|
+
get_string
|
23
|
+
|
24
|
+
end # def hash2get
|
25
|
+
|
26
|
+
# Use the Open URI and NokoGiri libraries to make the API call
|
27
|
+
#
|
28
|
+
# Usage:
|
29
|
+
# Class::Instance.get_data("http://someurl.com") # returns Hash of data or nil
|
30
|
+
def get_data(url)
|
31
|
+
response = Net::HTTP.get_response(URI.parse(url))
|
32
|
+
if response.class == Net::HTTPOK
|
33
|
+
result = XmlSimple.xml_in(response.body)
|
34
|
+
else
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
end # self.get_data
|
38
|
+
|
39
|
+
|
40
|
+
# Sets attr_accessor methods for sub classes to keys in xml hashes
|
41
|
+
def set_instance_methods(params)
|
42
|
+
|
43
|
+
params.each do |key, value|
|
44
|
+
instance_variable_set("@#{key.downcase}", value) if self.methods.include? key.downcase and !value.empty?
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/lib/usaspending.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'cgi'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'xmlsimple'
|
5
|
+
require 'net/http'
|
6
|
+
require 'net/https'
|
7
|
+
|
8
|
+
require "#{File.dirname(__FILE__)}/usaspending/base.rb"
|
9
|
+
Dir["#{File.dirname(__FILE__)}/usaspending/*.rb"].each { |source_file| require source_file }
|
data/usaspending.gemspec
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "usaspending"
|
3
|
+
s.version = "0.1.0"
|
4
|
+
s.date = "2010-5-17"
|
5
|
+
s.summary = "Ruby gem wrapper for USAspending.gov"
|
6
|
+
s.rubyforge_project = "usaspending"
|
7
|
+
s.email = "melton.dan@gmail.com"
|
8
|
+
s.homepage = "http://github.com/danmelton/usaspending"
|
9
|
+
s.authors = ["Dan Melton"]
|
10
|
+
s.files = ['usaspending.gemspec','README.textile', 'CHANGES.textile', 'lib/usaspending.rb','lib/usaspending/base.rb' ]
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: usaspending
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Dan Melton
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-05-17 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description:
|
22
|
+
email: melton.dan@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- usaspending.gemspec
|
31
|
+
- README.textile
|
32
|
+
- CHANGES.textile
|
33
|
+
- lib/usaspending.rb
|
34
|
+
- lib/usaspending/base.rb
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://github.com/danmelton/usaspending
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
segments:
|
49
|
+
- 0
|
50
|
+
version: "0"
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project: usaspending
|
61
|
+
rubygems_version: 1.3.6
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Ruby gem wrapper for USAspending.gov
|
65
|
+
test_files: []
|
66
|
+
|