Class: BusinessDotGov::LoansGrants

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

Constant Summary collapse

API_URL =
'http://api.business.gov/loans_grants/STATE ABBREVIATION/for_profit/INDUSTRY/nil.FORMAT'
US_STATES =
{      
  'ALABAMA' => 'AL',
  'ALASKA' => 'AK',
  'AMERICAN SAMOA' => 'AS',
  'ARIZONA' => 'AZ',
  'ARKANSAS' => 'AR',
  'CALIFORNIA' => 'CA',
  'COLORADO' => 'CO',
  'CONNECTICUT' => 'CT',
  'DELAWARE' => 'DE',
  'DISTRICT' => 'OF',
  'COLUMBIA' => 'DC',
  'FEDERATED STATES' => 'OF',
  'MICRONESIA' => 'FM',
  'FLORIDA' => 'FL',
  'GEORGIA' => 'GA',
  'GUAM' => 'GU',
  'HAWAII' => 'HI',
  'IDAHO' => 'ID',
  'ILLINOIS' => 'IL',
  'INDIANA' => 'IN',
  'IOWA' => 'IA',
  'KANSAS' => 'KS',
  'KENTUCKY' => 'KY',
  'LOUISIANA' => 'LA',
  'MAINE' => 'ME',
  'MARSHALL ISLANDS' => 'MH',
  'MARYLAND' => 'MD',
  'MASSACHUSETTS' => 'MA',
  'MICHIGAN' => 'MI',
  'MINNESOTA' => 'MN',
  'MISSISSIPPI' => 'MS',
  'MISSOURI' => 'MO',
  'MONTANA' => 'MT',
  'NEBRASKA' => 'NE',
  'NEVADA' => 'NV',
  'NEW HAMPSHIRE' => 'NH',
  'NEW JERSEY' => 'NJ',
  'NEW MEXICO' => 'NM',
  'NEW YORK' => 'NY',
  'NORTH CAROLINA' => 'NC',
  'NORTH DAKOTA' => 'ND',
  'NORTHERN MARIANA ISLANDS' => 'MP',
  'OHIO' => 'OH',
  'OKLAHOMA' => 'OK',
  'OREGON' => 'OR',
  'PALAU' => 'PW',
  'PENNSYLVANIA' => 'PA',
  'PUERTO RICO' => 'PR',
  'RHODE ISLAND' => 'RI',
  'SOUTH CAROLINA' => 'SC',
  'SOUTH DAKOTA' => 'SD',
  'TENNESSEE' => 'TN',
  'TEXAS' => 'TX',
  'UTAH' => 'UT',
  'VERMONT' => 'VT',
  'VIRGIN ISLANDS' => 'VI',
  'VIRGINIA' => 'VA',
  'WASHINGTON' => 'WA',
  'WEST VIRGINIA' => 'WV',
  'WISCONSIN' => 'WI',
  'WYOMING' => 'WY'
}
MILITARY_STATES =
{
  'Armed Forces Africa' => 'AE',
  'Armed Forces Americas (except Canada)' => 'AA',
  'Armed Forces Canada' => 'AE',
  'Armed Forces Europe' => 'AE',
  'Armed Forces Middle East' => 'AE',
  'Armed Forces Pacific' => 'AP'
}
STATES =

MILITARY_STATES

US_STATES
INDUSTRIES =
[
  'Agriculture', 
  'Child Care', 
  'Environmental Management',
  'Health Care',
  'Manufacturing',
  'Technology',
  'Tourism'
]
DATA_FORMATS =
[:xml, :json]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format = :json) ⇒ LoansGrants

Returns a new instance of LoansGrants.



94
95
96
97
# File 'lib/businessdotgov.rb', line 94

def initialize(format = :json)
  @format = format
  @industry, @state_abbreviation = nil
end

Instance Attribute Details

#data_formatObject

Returns the value of attribute data_format.



6
7
8
# File 'lib/businessdotgov.rb', line 6

def data_format
  @data_format
end

#industryObject

Returns the value of attribute industry.



6
7
8
# File 'lib/businessdotgov.rb', line 6

def industry
  @industry
end

#state_abbreviationObject

Returns the value of attribute state_abbreviation.



6
7
8
# File 'lib/businessdotgov.rb', line 6

def state_abbreviation
  @state_abbreviation
end

Instance Method Details

#search(options = {}) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/businessdotgov.rb', line 99

def search(options = {})
  @industry ||= options[:industry]
  @state_abbreviation ||= options[:state_abbreviation]
  @format ||= options[:format]
  if @industry.nil?
    raise ArgumentError, "Oops, an industry wasn't provided.  Please provide one of the following industries: #{INDUSTRIES.join(', ')}"
  end
  if @state_abbreviation.nil?
    raise ArgumentError, "Oops, an US state wasn't provided.  Please provide one of the following US states: #{STATES.values.join(', ')}"
  end
  api_call = URI.escape(API_URL.sub(/STATE ABBREVIATION/, @state_abbreviation).sub(/INDUSTRY/, @industry).sub(/FORMAT/, @format.to_s))
  puts "api_call = #{api_call}"
  response = Weary.get(api_call).perform
  if response.success?
    return response.parse
  else
    raise "Something went wrong. Request failed with #{response.code}: #{response.message}"
  end
end