I’ve been wondering about the way to get both class and instance methods into a module, and then including that module into a model.
I’ve got it working with other examples, but I am struggling to understand where to correctly place the include HTTPparty.
Below is the details of where I am at:
module Vimeo
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
class Base
include HTTParty
base_uri 'vimeo.com/api/v2'
headers 'Content-Type' => 'application/json'
end
class VimeoUser < Base
def vimeo_account(account_name)
@id = account_name
end
end
end
def info
Vimeo::Base.get("http://vimeo.com/api/v2/#{@id}/info.json")
end
end
with the goal of attaching it to a User model using: include Vimeo
and being able to call:
User.vimeo_account("name")
as well as
user = User.new
user.info
Any advice would be greatly appreciated!
I think calling get in the following way should solve the problem.
But to me it seems like you can have a simpler setup as below:
(unless there is more which I don’t understand)