Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding all ruby code samples and updated README

  • Loading branch information...
commit 74377bdefc76f656e17bba7c2f660c8519bde3f6 1 parent db6ad33
@kinlane kinlane authored
View
9 README
@@ -0,0 +1,9 @@
+This is a CityGrid Places and Advertising Ruby Sample.
+
+CityGrid Developer Center - http://developer.citygridmedia.com/
+
+If you have questions:
+
+tweet us at @citygridapiteam
+
+email us at: support@citygridmedia.com
View
249 citygrid-api-places-api-detail-sample.rhtml
@@ -0,0 +1,249 @@
+<%
+require 'net/http'
+
+qs = ENV['QUERY_STRING']
+qf={}
+for f in qs.split("&")
+ s = f.split("=")
+ qf[s[0]] = s[1]
+end
+
+id = URI.unescape(qf['id'])
+what = URI.unescape(qf['what'])
+where = URI.unescape(qf['where'])
+
+phone=''
+customer_only=''
+placement = ''
+all_results=''
+review_count=''
+i=''
+format='json'
+callback=''
+id_type='cs'
+
+cg = CityGridPlaces.new()
+pd = cg.placesdetail(id,id_type,phone,customer_only,all_results,review_count,placement,format,callback,i,Publisher_Code)
+
+b = JSON.parse(pd)
+
+locations = b['locations'][0]
+
+public_id = locations['public_id']
+infousa_id = locations['infousa_id']
+reference_id = locations['reference_id']
+impression_id = locations['impression_id']
+name = locations['name']
+display_ad = locations['display_ad']
+teaser = locations['teaser']
+business_operation_status = locations['business_operation_status']
+
+years_in_business = locations['address']['years_in_business']
+last_update_time = locations['address']['last_update_time']
+
+city = locations['address']['city']
+state = locations['address']['state']
+street = locations['address']['street']
+postal_code = locations['address']['postal_code']
+
+cross_street = locations['address']['cross_street']
+latitude = locations['address']['latitude']
+longitude = locations['address']['longitude']
+
+display_phone = locations['contact_info']['display_phone']
+display_url = locations['contact_info']['display_url']
+
+
+customer_content = locations['customer_content']
+%>
+<p><strong>Atribution:</strong></p>
+<%
+customer_attribution_source = locations['customer_content']['customer_message']['attribution_source']
+if(customer_attribution_source != nil && customer_attribution_source != 0)
+ %>
+ <strong>Attribution Source:</strong> <%= customer_attribution_source %><br />
+ <%
+end
+customer_attribution_text = locations['customer_content']['customer_message']['attribution_text']
+if(customer_attribution_text != nil && customer_attribution_text != 0)
+ %>
+ <strong>Attribution Text:</strong> <%= customer_attribution_text %><br />
+ <%
+end
+customer_attribution_message = locations['customer_content']['customer_message']['value']
+if(customer_attribution_message != nil && customer_attribution_message != 0)
+ %>
+ <strong>Attribution Value:</strong> <%= customer_attribution_message %><br />
+ <%
+end
+customer_message_url = locations['customer_content']['customer_message_url']
+if(customer_message_url != nil && customer_message_url != 0)
+ %>
+ <strong>Customer URL:</strong> <%= customer_message_url %><br />
+ <%
+end
+%>
+
+<%
+offers = locations['offers']
+if(offers != nil && offers != 0 && offers.length > 0)
+ %>
+ <p><strong>Offers:</strong></p>
+ <ul>
+ <%
+ offers.each do|offer|
+ %>
+ <li><strong><%=offer%></strong></li>
+ <%
+ end
+ %>
+ </ul>
+ <%
+end
+%>
+
+<%
+categories = locations['categories']
+if(categories != nil && categories != 0 && categories.length > 0)
+ %>
+ <br />
+ <p><strong>Categories:</strong></p>
+ <ul>
+ <%
+ categories.each do|category|
+ %>
+ <li><strong><%=category['name']%></strong></li>
+ <%
+ end
+ %>
+ </ul>
+ <%
+end
+%>
+
+<%
+attributes = locations['attributes']
+if(attributes != nil && attributes != 0 && attributes.length > 0)
+ %>
+ <p><strong>Attributes:</strong></p>
+ <ul>
+ <%
+ attributes.each do|attribute|
+ %>
+ <li><strong><%=attribute['name']%> - <%=attribute['value']%></strong></li>
+ <%
+ end
+ %>
+ </ul>
+ <%
+end
+%>
+
+<%
+tips = locations['tips']
+if(tips != nil && tips != 0 && tips.length > 0)
+ %>
+ <p><strong>Tips:</strong></p>
+ <ul>
+ <%
+ tips.each do|tip|
+ %>
+ <li><strong><%=attribute['tip_name']%> - <%=attribute['tip_text']%></strong></li>
+ <%
+ end
+ %>
+ </ul>
+ <%
+end
+%>
+
+<%
+images = locations['images']
+if(images != nil && images != 0 && images.length > 0)
+ %>
+ <p><strong>Images:</strong></p>
+ <ul>
+ <%
+ images.each do|image|
+
+ type = image['type']
+ height = image['height']
+ width = image['width']
+ image_url = image['image_url']
+ primary = image['primary']
+
+ %>
+ <li><strong><%=image_url%></strong></li>
+ <%
+ end
+ %>
+ </ul>
+ <%
+end
+%>
+
+<%
+editorials = locations['editorials']
+if(editorials != nil && editorials != 0 && editorials.length > 0)
+ %>
+ <p><strong>Editorials:</strong></p>
+ <ul>
+ <%
+ editorials.each do|editorial|
+
+ attribution_source = editorial['attribution_source']
+ attribution_logo = editorial['attribution_logo']
+ editorial_review = editorial['editorial_review']
+ editorial_id = editorial['editorial_id']
+ editorial_url = editorial['editorial_url']
+ editorial_title = editorial['editorial_title']
+ editorial_author = editorial['editorial_author']
+
+ %>
+ <li><strong><%=editorial_title%> - <%=editorial_review%></strong></li>
+ <%
+ end
+ %>
+ </ul>
+ <%
+end
+%>
+
+<%
+review_info = locations['review_info']
+if(review_info != nil && review_info != 0 && review_info.length > 0)
+
+ total_user_reviews = review_info['total_user_reviews']
+ total_user_reviews_shown = review_info['total_user_reviews_shown']
+ overall_review_rating = review_info['overall_review_rating']
+
+ reviews = review_info['reviews']
+
+ if(reviews != nil && reviews != 0 && reviews.length > 0)
+
+ %>
+ <p><strong>Reviews:</strong></p>
+ <ul>
+ <%
+
+ reviews.each do|review|
+
+ attribution_source = review['attribution_source']
+ attribution_logo = review['attribution_logo']
+ attribution_text = review['attribution_text']
+ review_id = review['review_id']
+ review_url = review['review_url']
+ review_title = review['review_title']
+ review_author = review['review_author']
+ review_text = review['review_text']
+
+ %>
+ <li><%= review_title %></a></li>
+ <%
+ end
+ end
+ %>
+ </ul>
+ <%
+end
+%>
View
94 citygrid-api-places-api-search-sample.rhtml
@@ -0,0 +1,94 @@
+<%
+require 'net/http'
+
+qs = ENV['QUERY_STRING']
+qf={}
+for f in qs.split("&")
+ s = f.split("=")
+ qf[s[0]] = s[1]
+end
+
+if(qf['what'] != nil && qf['what'] != 0)
+ what = URI.unescape(qf['what'])
+end
+
+if(qf['type'] != nil && qf['type'] != 0)
+ type = URI.unescape(qf['type'])
+else
+ type = ""
+end
+
+if(qf['where'] != nil && qf['where'] != 0)
+ where = URI.unescape(qf['where'])
+else
+ where = Site_Where
+end
+
+if(qf['page'] != nil && qf['page'] != 0)
+ page = URI.unescape(qf['page'])
+else
+ page = "1"
+end
+
+if(qf['rpp'] != nil && qf['rpp'] != 0)
+ rpp = URI.unescape(qf['rpp'])
+else
+ rpp = "20"
+end
+
+if(qf['sort'] != nil && qf['sort'] != 0)
+ sort = URI.unescape(qf['sort'])
+else
+ sort = "dist"
+end
+
+rformat='json'
+placement=''
+hasoffers=''
+histograms=''
+i=''
+
+cg = CityGridPlaces.new()
+pl = cg.srchplaceswhere(what,type,where,page,rpp,sort,rformat,placement,hasoffers,histograms,i,Publisher_Code)
+
+h = JSON.parse(pl)
+
+l = h['results']['locations']
+
+l.each do|location|
+
+ rating = location['rating']
+
+ id = location['id']
+
+ featured = location['featured']
+ featured = location['featured']
+ public_id = location['public_id']
+ name = location['name']
+
+ city = location['address']['city']
+ state = location['address']['state']
+ street = location['address']['street']
+ postal_code = location['address']['postal_code']
+
+ neighborhood = location['neighborhood']
+ latitude = location['latitude']
+ longitude = location['longitude']
+ distance = location['distance']
+ image = location['image']
+ phone_number = location['phone_number']
+ fax_number = location['fax_number']
+ rating = location['rating']
+ tagline = location['tagline']
+ profile = location['profile']
+ website = location['website']
+ has_video = location['has_video']
+ has_offers = location['has_offers']
+ offers = location['offers']
+
+ sample_categories = location['sample_categories']
+ impression_id = location['impression_id']
+ expansion = location['expansion']
+
+end
+%>
View
45 class-citygrid-ad-api.rhtml
@@ -0,0 +1,45 @@
+<%
+class CityGridAdvertising
+
+ def initialize()
+
+ end
+
+ def displaywebad300x250(adid,publisher,what,where)
+
+ @returnAd = '<div id="sidebar_ad_slot_' + adid + '"></div>' + "\n"
+ @returnAd = @returnAd + '<script type="text/javascript">' + "\n"
+ @returnAd = @returnAd + "new CityGrid.Ads('sidebar_ad_slot_" + adid + "', {" + "\n"
+ @returnAd = @returnAd + " collection_id: 'web-002-300x250'," + "\n"
+ @returnAd = @returnAd + " publisher: '" + publisher + "'," + "\n"
+ @returnAd = @returnAd + " what:'" + what + "'," + "\n"
+ @returnAd = @returnAd + " where: '" + where + "'," + "\n"
+ @returnAd = @returnAd + " width: 300," + "\n"
+ @returnAd = @returnAd + " height: 250" + "\n"
+ @returnAd = @returnAd + " })" + "\n"
+ @returnAd = @returnAd + "</script>" + "\n"
+
+ return @returnAd
+
+ end
+
+ def displaywebad630x100(adid,publisher,what,where)
+
+ @returnAd = '<div id="sidebar_ad_slot_' + adid + '"></div>' + "\n"
+ @returnAd = @returnAd + '<script type="text/javascript">' + "\n"
+ @returnAd = @returnAd + "new CityGrid.Ads('sidebar_ad_slot_" + adid + "', {" + "\n"
+ @returnAd = @returnAd + " collection_id: 'web-001-630x100'," + "\n"
+ @returnAd = @returnAd + " publisher: '" + publisher + "'," + "\n"
+ @returnAd = @returnAd + " what:'" + what + "'," + "\n"
+ @returnAd = @returnAd + " where: '" + where + "'," + "\n"
+ @returnAd = @returnAd + " width: 630," + "\n"
+ @returnAd = @returnAd + " height: 100" + "\n"
+ @returnAd = @returnAd + " })" + "\n"
+ @returnAd = @returnAd + "</script>" + "\n"
+
+ return @returnAd
+
+ end
+
+end
+%>
View
122 class-citygrid-places-api.rhtml
@@ -0,0 +1,122 @@
+<%
+class CityGridPlaces
+
+ def initialize()
+
+ end
+
+ def srchplaceswhere(what,type,where,page,rpp,sort,rformat,placement,hasoffers,histograms,i,publishercode)
+
+ @rooturl = "http://api.citygridmedia.com/content/places/v2/search/where?"
+
+ @url = 'publisher=' + publishercode
+ @url = @url + '&sort=' + sort
+ @url = @url + '&page=' + page
+ @url = @url + '&rpp=' + rpp
+
+ if what.length > 0 then
+ @url = @url + '&what=' + what
+ end
+ if type.length > 0 then
+ @url = @url + '&type=' + type
+ end
+ if where.length > 0 then
+ @url = @url + '&where=' + where
+ end
+
+ if placement.length > 0 then
+ @url = @url + '&placement=' + placement
+ end
+ if hasoffers.length > 0 then
+ @url = @url + '&has_offers=' + hasoffers
+ end
+ if histograms.length > 0 then
+ @url = @url + '&histograms=' + histograms
+ end
+
+ if i.length > 0 then
+ @url = @url + '&i=' + i
+ end
+
+ @url = @url + '&format=' + rformat
+
+ begin
+
+ @url = URI.escape(@url)
+ @url = @rooturl + @url
+
+ @uri = URI.parse(@url)
+
+ request = Net::HTTP::Get.new(@uri.path+'?'+@uri.query)
+
+ http = Net::HTTP.new(@uri.host,@uri.port)
+
+ response = http.start {|http| http.request(request) }
+
+ @response = response.body
+
+ rescue Exception => ex
+ @response = "An error of type #{ex.class} happened, message is #{ex.message}"
+ end
+
+ return @response
+ end
+
+ def placesdetail(id,id_type,phone,customer_only,all_results,review_count,placement,format,callback,i,publishercode)
+
+ @client_ip = ENV['REMOTE_ADDR']
+
+ @rooturl = "http://api.citygridmedia.com/content/places/v2/detail?"
+
+ @url = 'publisher=' + publishercode
+ @url = @url + '&id=' + id
+ @url = @url + '&id_type=' + id_type
+ @url = @url + '&client_ip=' + @client_ip
+
+ if phone.length > 0 then
+ @url = @url + '&phone=' + phone
+ end
+ if customer_only.length > 0 then
+ @url = @url + '&customer_only=' + customer_only
+ end
+ if all_results.length > 0 then
+ @url = @url + '&all_results=' + all_results
+ end
+
+ if review_count.length > 0 then
+ @url = @url + '&review_count=' + review_count
+ end
+ if placement.length > 0 then
+ @url = @url + '&placement=' + placement
+ end
+ if format.length > 0 then
+ @url = @url + '&format=' + format
+ end
+ if callback.length > 0 then
+ @url = @url + '&callback=' + callback
+ end
+
+ if i.length > 0 then
+ @url = @url + '&i=' + i
+ end
+
+ @url = URI.escape(@url)
+ @url = @rooturl + @url
+
+ @uri = URI.parse(@url)
+
+ request = Net::HTTP::Get.new(@uri.path+'?'+@uri.query)
+
+ http = Net::HTTP.new(@uri.host,@uri.port)
+
+ response = http.start {|http| http.request(request) }
+
+ @response = response.body
+
+ return @response
+
+ end
+
+end
+
+%>
Please sign in to comment.
Something went wrong with that request. Please try again.