I'm trying to integrate an API into a class but can't work out how I put the modules in place.
class PlivoNumber < ActiveRecord::Base
require 'plivo'
include Plivo
def initialize_plivo
@p = RestAPI.new(ENV['PLIVO_AUTH_ID'], ENV['PLIVO_AUTH_TOKEN'])
end
def delete_number
self.initialize_plivo
params = {
'number' => self.number
}
response = @p.unrent_number(params)
end
I've tried both include and Extend
if I use in initialize
self.RestAPI.new(ENV['PLIVO_AUTH_ID'], ENV['PLIVO_AUTH_TOKEN'])
NoMethodError: undefined method `RestAPI' for #<PlivoNumber:0x007f8eca9523f0>
if I use
RestAPI.new(ENV['PLIVO_AUTH_ID'], ENV['PLIVO_AUTH_TOKEN'])
NameError: uninitialized constant PlivoNumber::RestAPI
Basically I want to be able to run @plivo_number.delete_number and have the app hit the api and perform the action. I appreciate that the initialize step not really doing anything with the class, but I can't do the next step without it.
Hope that makes some kind of sense, I get the impression that what I'm doing is probably a bit confused....