class RelateIq::Account

Attributes

id[RW]
name[RW]

Public Class Methods

create(attrs = {}) click to toggle source
# File lib/relateiq/account.rb, line 13
def self.create(attrs = {})
  RelateIq::Account.new(attrs).save
end
find(id) click to toggle source
# File lib/relateiq/account.rb, line 9
def self.find(id)
  from_json(resource["#{id}"].get)
end
from_json(json_string) click to toggle source
# File lib/relateiq/account.rb, line 17
def self.from_json(json_string)
  account_hash = JSON.parse(json_string, symbolize_names: true)
  RelateIq::Account.new(account_hash)
end
new(attrs = {}) click to toggle source
# File lib/relateiq/account.rb, line 22
def initialize(attrs = {})
  @id = attrs.fetch(:id, nil)
  @name = attrs.fetch(:name, nil)
end
resource() click to toggle source
# File lib/relateiq/account.rb, line 5
def self.resource
  @resource ||= RelateIq::ServiceFactory.get_endpoint('accounts')
end

Public Instance Methods

save() click to toggle source
# File lib/relateiq/account.rb, line 35
def save
  if id
    RelateIq::Account.from_json(RelateIq::Account.resource["#{id}"].put(to_json))
  else
    RelateIq::Account.from_json(RelateIq::Account.resource.post(to_json))
  end
end
to_json() click to toggle source
# File lib/relateiq/account.rb, line 27
def to_json
  account_hash = {
    name: @name
  }
  account_hash[:id] = id if id
  account_hash.to_json
end