module Opensea

Constants

BASE

Public Class Methods

assets( collection:, offset: 0 ) click to toggle source

todo/check: rename to query or search or such - why? why not?

add self.collect( collection, offset: 0 ) helper or such - why? why not?
# File lib/artbase/opensea.rb, line 93
def self.assets( collection:, offset: 0 )
  src = BASE.sub( '{collection}', collection ).
             sub( '{offset}',     offset.to_s )

  call( src )
end
call( src ) click to toggle source
# File lib/artbase/opensea.rb, line 101
def self.call( src )   ## get response as (parsed) json (hash table)
  uri = URI.parse( src )

  http = Net::HTTP.new( uri.host, uri.port )

  puts "[debug] GET #{uri.request_uri} uri=#{uri}"

  headers = {
    'User-Agent' => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36",
    #'User-Agent' => "ruby v#{RUBY_VERSION}",
   }


  request = Net::HTTP::Get.new( uri.request_uri, headers )
  if uri.instance_of? URI::HTTPS
      http.use_ssl = true
      http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end

  response   = http.request( request )

  if response.code == '200'
    puts "#{response.code} #{response.message} -  content_type: #{response.content_type}, content_length: #{response.content_length}"

    text = response.body.to_s
    text = text.force_encoding( Encoding::UTF_8 )

    data = JSON.parse( text )
    data
  else
    puts "!! ERROR:"
    puts "#{response.code} #{response.message}"
    exit 1
  end
end