Class: NftChecker::OpenSea
- Inherits:
-
Object
- Object
- NftChecker::OpenSea
- Defined in:
- lib/nft_checker/open_sea.rb
Overview
NFT Checker implementation for OpenSea
Instance Method Summary collapse
-
#initialize(testnet: false) ⇒ OpenSea
constructor
A new instance of OpenSea.
-
#list_nfts(collection_metadata, owner_address) ⇒ Object
List all NFTs in the collection owned by the given address.
-
#verify_owner(nft_metadata, owner_address) ⇒ Object
Verify that the NFT is owned by the given address.
Constructor Details
#initialize(testnet: false) ⇒ OpenSea
Returns a new instance of OpenSea.
9 10 11 |
# File 'lib/nft_checker/open_sea.rb', line 9 def initialize(testnet: false) @url_base = testnet ? "https://testnets-api.opensea.io/" : "https://api.opensea.io/" end |
Instance Method Details
#list_nfts(collection_metadata, owner_address) ⇒ Object
List all NFTs in the collection owned by the given address
30 31 32 33 34 35 |
# File 'lib/nft_checker/open_sea.rb', line 30 def list_nfts(, owner_address) rez = HTTParty.get("#{@url_base}assets", query: { owner: owner_address, collection: [:slug] }) handle_response_codes(rez, not_found: []) do rez.parsed_response["assets"] || [] end end |
#verify_owner(nft_metadata, owner_address) ⇒ Object
Verify that the NFT is owned by the given address
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/nft_checker/open_sea.rb', line 16 def verify_owner(, owner_address) contract, token = .slice(:contract_address, :token_id).values rez = HTTParty.get(@url_base + "asset/#{contract}/#{token}/", query: { account_address: owner_address }) handle_response_codes(rez, not_found: false) do ownership_data = rez.parsed_response["ownership"] return false if ownership_data.nil? ownership_data["owner"]["address"].casecmp(owner_address).zero? && ownership_data["quantity"].to_i.positive? end end |