Changeset 1477

Show
Ignore:
Timestamp:
09/08/07 17:45:53 (1 year ago)
Author:
jm3
Message:

parsing JSON reponses back from Yelp API working

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • where-you-app/site/app/controllers/hood_controller.rb

    r1475 r1477  
    1414 
    1515    yelp_url = 'http://api.yelp.com/neighborhood_search?lat=' + @lat + '&long=' + @long + '&ywsid=' + YELP_WS_ID 
    16     @y = YELP_WS_ID 
    1716    url = URI.parse( yelp_url) 
    1817    req = Net::HTTP::Get.new(yelp_url) 
     
    2019 
    2120    # FIXME: check well-formedness of response 
    22     # TODO: parse response 
    2321     
    24     @json_reponse = JSON.parse(res.body).to_json 
    25  
    26     # to dump back to the browser: 
    27     #send_data res.body, :type => res.header.content_type 
     22    @json = JSON.parse(res.body) 
     23    @neighborhood = @json["neighborhoods"][0]["name"] 
     24    return 
     25     if @json.has_key? 'neighborhoods' 
     26      @json = "fuckballs" 
     27     else 
     28      @json = "shitballs" 
     29     end 
    2830 
    2931  end 
  • where-you-app/site/app/views/hood/index.rhtml

    r1475 r1477  
    99 
    1010  <pre> 
    11     @static_fake_response: <%= @static_fake_response %> 
    12     @json_reponse: <%= @json_reponse %> 
    13     @y: <%= @y %> 
    14  
    15     h @lat : <%= h @lat %> 
    16     h @long : <%= h @long %> 
    1711  </pre> 
    1812 
     
    2923  </form> 
    3024 
    31   <% if @result %> 
     25  <% if @neighborhood %> 
    3226  <div class="response"> 
    33     <h1>nice reponse:</h1> 
     27    <h1>neighborhood:</h1> 
     28    @neighborhood: <%= @neighborhood %> 
    3429  </div> 
    3530  <% end %>