Skip to content

Instantly share code, notes, and snippets.

@lulalala
Created May 31, 2013 10:13
Show Gist options
  • Save lulalala/8640d4db131ad46f8b63 to your computer and use it in GitHub Desktop.
Save lulalala/8640d4db131ad46f8b63 to your computer and use it in GitHub Desktop.
# bundle exec irb
require 'rest-more'
c = RestCore::YahooBuy.new(api_key:'api_key', secret:'secret')
c.get('getCurrTime') # nil error
require 'rest-core/middleware'
require 'rest-core/util/hmac'
class RestCore::YahooBuy::Signature
def self.members; [:secret]; end
include RestCore::Middleware
def call env, &k
sig = Hmac.sha1(secret(env), percent_encode(env[REQUEST_QUERY]))
# Move query parameters into path variable, to stop reordering
env[REQUEST_PATH] = request_uri(env)
# Add signature to the end of request
env[REQUEST_QUERY] = {'Signature'=>sig}
app.call(env, &k)
end
end
require 'rest-core'
module RestCore
module YahooBuy
autoload :Signature, 'rest-core/client/yahoo_buy/signature'
Client = Builder.client(:api_key, :secret) do
use Timeout , 10
use Signature, nil
use DefaultSite , 'http://tw.partner.buy.yahoo.com/api/v1/'
use DefaultHeaders, {'Accept' => 'application/xml'}
use CommonLogger , nil
use Cache , nil, 600 do
use ErrorHandler, lambda{ |env|
RuntimeError.new(env[RESPONSE_BODY]['message'])}
use ErrorDetectorHttp
end
end
def self.new *args, &block
Client.new args, &block
end
end
end
@godfat
Copy link

godfat commented May 31, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment