require 'google_api_hashtag/version' require 'json' require 'net/http' require 'Remove_non_latin' require 'Limit_character' require 'Remove_blank' require 'Add_hashtag' require 'Keep_non_blank_in_array' require 'replace_accented_character' require 'remove_special_character' class GoogleApiHashtag GOOGLE_PLACES_URL = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=' #'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=' 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 end