module LolcationClient::NearIn
Public Instance Methods
near_in(options = {})
click to toggle source
# File lib/lolcation_client/near_in.rb, line 8 def near_in(options = {}) raise ArgumentError, 'Latitude and Longitude is required' unless options[:latitude].present? || options[:longitude].present? raise ArgumentError, 'Distance must be grater than 0' if options[:distance] =~ /\A0/ process(do_post(options.merge(sandbox: sandbox?)), options) end
process(response, options)
click to toggle source
# File lib/lolcation_client/near_in.rb, line 15 def process(response, options) json = JSON.parse(response.body, object_class: OpenStruct) list = json['localizations'] return list.map{|item| item.id.to_i} if options[:only_ids] list end
Private Instance Methods
do_post(options = {})
click to toggle source
# File lib/lolcation_client/near_in.rb, line 27 def do_post(options = {}) conn = Faraday.new(url: "#{service_url}/near-me") conn.post do |r| r.headers["X-Token"] = token r.headers["Content-Type"] = "application/json" r.body = options.to_json end end