Class: GoogleApiHashtag
- Inherits:
-
Object
- Object
- GoogleApiHashtag
- Defined in:
- lib/google_api_hashtag.rb,
lib/google_api_hashtag/version.rb
Constant Summary collapse
- GOOGLE_PLACES_URL =
'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location='- VERSION =
"0.1.3"
Instance Method Summary collapse
Instance Method Details
#process(params) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/google_api_hashtag.rb', line 17 def process(params) #catching the parameters lat = params[:lat] lng = params[:lng] meters = params[:meters] google_Key = params[:google_Key] #querying google api googleTest = GOOGLE_PLACES_URL + lat + ',' + lng + '&radius=' + meters + '&key=' + google_Key response = Net::HTTP.get_response(URI.parse(googleTest)) #removing the single quote character (not needed all for the hashtag) response_body = response.body.tr('\'', '') my_json = JSON.parse(response_body) elements = [] #populating array my_json['results'].each do |steph| elements.push(steph['name']) end #decorative pattern: https://robots.thoughtbot.com/evaluating-alternative-decorator-implementations-in element_processed = Remove_blank.new #passing array to object element_processed.pass_on(elements) #removing non latin characters element_processed.extend(Remove_non_latin) #below, remove accented characters http://stackoverflow.com/questions/15686752/ruby-method-to-remove-accents-from-utf-8-international-characters element_processed.extend(Replace_accented_character) #remove special characters - http://stackoverflow.com/questions/737475/how-can-i-delete-special-characters element_processed.extend(Remove_special_character) #limit size of each item in array element_processed.extend(Limit_character) #add hashtag at begining of each item element_processed.extend(Add_hashtag) #only keep non blank items (hashtag non-considered) element_processed.extend(Keep_non_blank_in_array) #fame and glory: carl = element_processed.process() my_return = {:response => response, :my_array => carl} return my_return #via: [:get], :constraints => { :lat => /[^\/]+/, :lng => /[^\/]+/ } #response = Net::HTTP.get_response(URI.parse('https://freegeoip.net/json/')) end |