URL形式を使用するサービスにアクセスしようとしています。www.example.com/api/API_KEY/action
以下のコードは、私が達成しようとしていることの小さな例です。
require 'httparty'
class MyAPI
include HTTParty
debug_output $stdout
base_uri "example.com/api/#{@api_key}"
def initialize(api_key)
@api_key = api_key
end
def statistics
return self.class.get("/statistics")
end
end
サーバーリクエスト:
MyAPI.new('apikey').statistics
として出てきます
GET /api//statistics
楽観的であることはわかっていましたが、api_key変数をbase_uriに配置しました。URLが動的なapi_keyを使用するようにするにはどうすればよいですか?