tyrauber / census_api

A Ruby Gem for querying the US Census Bureau API
MIT License
30 stars 9 forks source link

ACS5 Field Name rejected, but works on simple GET #21

Closed mistergibson closed 6 years ago

mistergibson commented 6 years ago

Not sure why, but a field name is rejected via your gem, but NOT rejected with a simple http get query.

Ruby behaves like this: data = client.where({ fields: 'B25104_016E', level: 'COUNTY:51', within: 'STATE:41'}) => {:code=>400, :location=>nil, :body=>#<HTTP::Response::Body:2acba4b8a138 @streaming=false>} data[:body].to_s => "error: error: unknown variable 'B25104_016E'

Where as GET behaves like this:

https://api.census.gov/data/2015/acs5?get=NAME,B25104_016E&for=county:051&in=state:41

JSON Result: [["NAME","B25104_016E","state","county"], ["Multnomah County, Oregon","12837","41","051"]]

Any ideas on why it was rejected one way and not the other way? Thanks

tyrauber commented 6 years ago

Hi @mistergibson, Looks like B25104_016E was a new variable introduced in the 2015 ACS5. Unless the vintage is specified the gem utilizes the 2010 data. I will update the gem to default to the most recent data available. In the meantime, this will work:

client = CensusApi::Client.new(api_key, dataset: 'acs5', vintage: 2015)
client.where({ fields: 'B25104_016E', level: 'COUNTY:51', within: 'STATE:41'})

Let me know if you run into any other issues. Thanks for letting me know.