$ bundle gem foo-api-wrapper
$ cd foo-api-wrapper
s.add_dependency 'http'
$ bundle install
For example, for the Jupiter Swap API (https://station.jup.ag/docs/apis/swap-api)
I created a jupiter.rb
with the base URL
module Jupiter
class Error < StandardError; end
BASE_URL = "https://quote-api.jup.ag/v6"
end
I created a quote.rb
module Jupiter
class Quote
def self.get(**params)
HTTP.get(BASE_URL + "/quote", params: params).parse(:json)
end
end
end
I created a swap.rb
module Jupiter
class Swap
def self.post(**params)
HTTP.post(BASE_URL + "/swap", json: params).parse(:json)
end
end
end
quote = Jupiter::Quote.get(inputMint: "123", outputMint: "321", amount: "1")
swap = Jupiter::Swap.post(quoteResponse: quote, userPublicKey: "f8a7df871...")
Use the get
and post
class methods to instantiate the Quote
and Swap
classes with both your request and response params.
You can decide if you want to use a strict schema or something like Hashie.
thank you! @mculp