Module: ContextIO::API::Resource

Included in:
ContextIO::Account, ConnectToken, Contact, File, Message, OAuthProvider, Source, Thread, Webhook
Defined in:
lib/contextio/api/resource.rb

Overview

When included into a class, this module provides some helper methods for various things a singular resource will need or find useful.

Defined Under Namespace

Modules: DeclarativeClassSyntax

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_attributes{String => Numeric, String, Hash, Array, Boolean} (readonly)

Returns The attributes returned from the API as a Hash. If it hasn't been populated, it will ask the API and populate it.

Returns:

  • ({String => Numeric, String, Hash, Array, Boolean})

    The attributes returned from the API as a Hash. If it hasn't been populated, it will ask the API and populate it.



60
61
62
# File 'lib/contextio/api/resource.rb', line 60

def api_attributes
  @api_attributes ||= fetch_attributes
end

#primary_keyString, Symbol (readonly)

Returns The name of the key used to build the resource URL.

Returns:

  • (String, Symbol)

    The name of the key used to build the resource URL.



67
68
69
# File 'lib/contextio/api/resource.rb', line 67

def primary_key
  self.class.primary_key
end

#resource_urlString (readonly)

Returns The URL that will fetch attributes from the API.

Returns:

  • (String)

    The URL that will fetch attributes from the API.



45
46
47
# File 'lib/contextio/api/resource.rb', line 45

def resource_url
  @resource_url ||= api.url_for(self)
end

Instance Method Details

#deleteBoolean

Deletes the resource.

Returns:

  • (Boolean)

    Whether the deletion worked or not.



52
53
54
# File 'lib/contextio/api/resource.rb', line 52

def delete
  api.request(:delete, resource_url)['success']
end