Я пытаюсь написать API-оболочку на Ruby, и я озадачен тем, как я могу вызывать методы HTTParty из подкласса.
Я хочу, чтобы пользователь создал соединение с API, а затем мог запрашивать результаты из подклассов.
module ApiWrapper
class Connection
include HTTParty
base_uri '...'
def initialize( u, p )
...
end
def contacts
ApiWrapper::Contact
end
end
end
module ApiWrapper
class Contact
def all
# issue httparty get request here that is created from the Connection class
end
end
end
## The user would do this
conn = ApiWrapper::Connection.new( 'username', 'password' )
contacts = conn.contacts.all