-
-
Save godfat/91e15c625e9b7150b1f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bundle exec irb | |
require 'rest-more' | |
c = RestCore::YahooBuy.new(api_key:'api_key', secret:'secret') | |
c.get('getCurrTime') # nil error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rest-core' | |
module RestCore | |
module YahooBuy | |
autoload :Signature, 'rest-core/client/yahoo_buy/signature' | |
Client = Builder.client(:api_key) 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment