Skip to content

Latest commit

 

History

History
65 lines (37 loc) · 2.06 KB

README.rdoc

File metadata and controls

65 lines (37 loc) · 2.06 KB

Ruby Wrapper for the Trademe API

API documentation available at: developer.trademe.co.nz

Installation

gem "trademe"

In your Gemfile should do the trick.

Note that there is currently an issue with the Ruby OAuth library that may cause you to get 404 responses from token requests. You can fix that by adding the following to your Gemfile:

gem "oauth", :git => "git://github.com/nikz/oauth-ruby.git"

You can disable this when/if github.com/oauth/oauth-ruby/pull/65 gets applied.

Sample Usage

gateway.search “property/residential”, :search_string => “flash apartment”, :date_from => 4.hours.ago

This will return the parsed JSON response

Authentication via OAuth:

gateway                 = Trademe::Gateway.new(consumer_key, consumer_secret)
authorize_url           = gateway.generate_request_token(callback_url)
session[:request_token] = gateway.request_token
redirect_to authorize_url

Upon return to callback url (with params set):

gateway               = Trademe::Gateway.new
gateway.request_token = session[:request_token]
if gateway.get_access_token(params[:oauth_verifier])
  session[:access_token] = gateway.access_token
end

You are now verified!

Authentication allows you a rate limit of 1000 requests per hour (see developer.trademe.co.nz/api-overview/rate-limiting/ for more information)

Logging

You can specify a logger using:

gateway.logger = Trademe::Loggers::FileLogger.new(log_filename)

The bundled loggers are a FileLogger, RedisCountLogger and MultipleLogger.

FileLogger is a thin wrapper over Ruby’s Logger class.

RedisCountLogger is useful for rate limiting, it increments a Redis key for each call you make within an hour.

MultipleLogger allows you to use multiple loggers at once.

Contributions

If you want to push a patch, please fork the project, commit the patch to the fork and submit a pull request.

Original code by github.com/clarketus.

License

This code is free to use under the terms of the MIT license.