Class: RelateIq::Account
- Inherits:
-
Object
- Object
- RelateIq::Account
- Defined in:
- lib/relateiq/account.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Account
constructor
A new instance of Account.
- #save ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Account
Returns a new instance of Account.
22 23 24 25 |
# File 'lib/relateiq/account.rb', line 22 def initialize(attrs = {}) @id = attrs.fetch(:id, nil) @name = attrs.fetch(:name, nil) end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/relateiq/account.rb', line 3 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/relateiq/account.rb', line 3 def name @name end |
Class Method Details
.create(attrs = {}) ⇒ Object
13 14 15 |
# File 'lib/relateiq/account.rb', line 13 def self.create(attrs = {}) RelateIq::Account.new(attrs).save end |
.find(id) ⇒ Object
9 10 11 |
# File 'lib/relateiq/account.rb', line 9 def self.find(id) from_json(resource["#{id}"].get) end |
.from_json(json_string) ⇒ Object
17 18 19 20 |
# 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 |
.resource ⇒ Object
5 6 7 |
# File 'lib/relateiq/account.rb', line 5 def self.resource @resource ||= RelateIq::ServiceFactory.get_endpoint('accounts') end |
Instance Method Details
#save ⇒ Object
35 36 37 38 39 40 41 |
# 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 ⇒ Object
27 28 29 30 31 32 33 |
# 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 |