title: Rails: how to save a gem's class as a model in my database?
body: <p>I've been building a Google Tasks integration app and just switched to using the Google API Client (<code>gem 'google-api-client', '~&gt; 0.34'</code>)</p>
  
  <p>This gives me some classes that I'm really starting to like:</p>
  
  <pre class="lang-rb prettyprint-override"><code>Google::Apis::TasksV1::Task
  Google::Apis::TasksV1::TaskList
  Google::Apis::TasksV1::Tasks # (for multiple records)
  Google::Apis::TasksV1::TaskLists # (for multiple records)
  </code></pre>
  
  <p>These classes come with all the attributes I want and I'm thinking it would be nice to actually have these records in my database instead of what I'm doing now, which is HTTP requests with OAuth (using methods provided by the gem)</p>
  
  <p>With their gem integrated into a custom class, I can do things like:</p>
  
  <pre class="lang-rb prettyprint-override"><code>&gt; ts = TaskService.new(user)
  =&gt; #&lt;TasksService:0x00007f973be03bc8 @user=#&lt;User #userstuff&gt;, @service=#&lt;Google::Apis::TasksV1::TasksService:0x00007f973be03b28 @root_url="https://www.googleapis.com/", @base_path="tasks/v1/", @upload_path="upload/tasks/v1/", @batch_path="batch/tasks/v1", @client_options=#&lt;struct Google::Apis::ClientOptions #morestuff&gt;, @request_options=#&lt;struct Google::Apis::RequestOptions authorization=#&lt;Signet::OAuth2::Client:0x00007f973be02020 @authorization_uri=#&lt;Addressable::URI:0x3fcb9df05304 URI:https://accounts.google.com/o/oauth2/auth&gt;, @token_credential_uri=#&lt;Addressable::URI:0x3fcb9db99f08 URI:https://accounts.google.com/o/oauth2/token&gt;, @client_id="secret", @client_secret="secret", @code=nil, @expires_at=nil, @issued_at=nil, @issuer=nil, @password=nil, @principal=nil, @redirect_uri=nil, @scope=nil, @state=nil, @username=nil, @access_type=:offline, @expiry=60, @extension_parameters={}, @additional_parameters={}, @access_token="secret", @id_token=nil&gt;, retries=0, header=nil, normalize_unicode=false, skip_serialization=false, skip_deserialization=false, api_format_version=nil, use_opencensus=true&gt;&gt;&gt;
  
  &gt; ts.service.list_tasklists
  Sending HTTP get https://www.googleapis.com/tasks/v1/users/@me/lists?
  200
  #&lt;HTTP::Message:0x00007f973b79ceb0 #all the stuff&gt;
  Success - #&lt;Google::Apis::TasksV1::TaskLists:0x00007f973e032168
   @etag="\"LTY2NzExNzU1Mg\"",
   @items=
    [#&lt;Google::Apis::TasksV1::TaskList:0x00007f973e0a2a58
      @etag="\"Mzk0NzU3MDky\"",
      @id="MDc1MjQ5ODU0NzUwMjI4NDkwMTM6MDow",
      @kind="tasks#taskList",
      @self_link=
       "https://www.googleapis.com/tasks/v1/users/@me/lists/MDc1MjQ5ODU0NzUwMjI4NDkwMTM6MDow",
      @title="My list",
      @updated=Wed, 18 Dec 2019 05:42:34 +0000&gt;,
     #&lt;Google::Apis::TasksV1::TaskList:0x00007f973bf298b8
      @etag="\"Mzk0OTEzMTI0\"",
      @id="eHFkTG9UUkl3d1ZQcTdCOA",
      @kind="tasks#taskList",
      @self_link=
       "https://www.googleapis.com/tasks/v1/users/@me/lists/eHFkTG9UUkl3d1ZQcTdCOA",
      @title="Another List",
      @updated=Wed, 18 Dec 2019 05:45:10 +0000&gt;,
     ... # brevity is the soul of ...
  
  =&gt; #&lt;Google::Apis::TasksV1::TaskLists:0x00007f973e032168 @etag="\"LTY2NzExNzU1Mg\"", @items=[#&lt;Google::Apis::TasksV1::TaskList:0x00007f973e0a2a58 @etag="\"Mzk0NzU3MDky\"", @id="MDc1MjQ5ODU0NzUwMjI4NDkwMTM6MDow", @kind="tasks#taskList", @self_link="https://www.googleapis.com/tasks/v1/users/@me/lists/MDc1MjQ5ODU0NzUwMjI4NDkwMTM6MDow", @title="FamilyPromiseGR's list", @updated=Wed, 18 Dec 2019 05:42:34 +0000&gt;, #&lt;Google::Apis::TasksV1::TaskList:0x00007f973bf298b8 @etag="\"Mzk0OTEzMTI0\"", @id="eHFkTG9UUkl3d1ZQcTdCOA", @kind="tasks#taskList", @self_link="https://www.googleapis.com/tasks/v1/users/@me/lists/eHFkTG9UUkl3d1ZQcTdCOA", @title="Vinewood Ave NE", @updated=Wed, 18 Dec 2019 05:45:10 +0000&gt;, ... # brevity is the soul of ...
  </code></pre>
  
  <p>The items come back as structured classes! It's great!</p>
  
  <p>However, there's a good amount of latency with every call. </p>
  
  <p>I'm running these commands in jobs, but I'm also thinking about saving these to my database (postgresql) and just comparing <code>updated</code> timestamps instead of pulling the information every single time I need it.</p>
  
  <p>So, here's my question:</p>
  
  <h1>How can I take the class as-is and make it a model in my database?</h1>
  
  <p>I want to be able to call <code>Google::Apis::TasksV1::Task.create(tasklist_attrs)</code> and other such model-type methods.</p>
  
  <p>I have noticed that they don't respond exactly like my own classes (that inherit from <code>ActiveRecord::Base</code>):</p>
  
  <pre class="lang-rb prettyprint-override"><code>2.6.3 :008 &gt; User.new
   =&gt; #&lt;User id: nil, name: nil, title: nil, phone: nil, admin: false, staff: false, client: false, volunteer: false, contractor: false, email: "", oauth_provider: nil, oauth_id: nil, oauth_image_link: nil, oauth_token: nil, oauth_refresh_token: nil, oauth_expires_at: nil, created_at: nil, updated_at: nil, discarded_at: nil&gt;
  
  2.6.3 :009 &gt; Google::Apis::TasksV1::Task.new
   =&gt; #&lt;Google::Apis::TasksV1::Task:0x00007f973e2d8908&gt; # no nil attributes by default?
  </code></pre>