Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'net/http'
require 'json'
#hamilton RegionId
hamilton = 16
waikato = 14
# make a query to the Residential endpoiint of the trademe search api
#
# @param argument_hash Hash
#
# The keys are query string parameter values, check the trademe documentation to find
# supported parameters. The value for a hashes key is the same as the value for its parameter
#
# Documentation of trademe residential search api:
# http://developer.trademe.co.nz/api-reference/search-methods/residential-search/
#
# @returns Hash with the json response.
def trademeGet(argument_hash)
base_uri = "http://api.trademe.co.nz/v1/Search/Property/Residential.json?"
# add the region/district to the argument_hash
argument_hash.each do |key, value|
base_uri += "&#{key}=#{value}"
end
uri = URI(base_uri)
res = Net::HTTP.get(uri)
JSON.parse(res)
end
puts trademeGet region: waikato, district: hamilton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment