Class: XeroKiwi::Accounting::User
- Inherits:
-
Object
- Object
- XeroKiwi::Accounting::User
- Defined in:
- lib/xero_kiwi/accounting/user.rb
Overview
Represents a Xero User returned by the Accounting API.
Constant Summary collapse
- ATTRIBUTES =
{ user_id: "UserID", email_address: "EmailAddress", first_name: "FirstName", last_name: "LastName", updated_date_utc: "UpdatedDateUTC", is_subscriber: "IsSubscriber", organisation_role: "OrganisationRole" }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(attrs) ⇒ User
constructor
A new instance of User.
- #inspect ⇒ Object
- #subscriber? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(attrs) ⇒ User
Returns a new instance of User.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/xero_kiwi/accounting/user.rb', line 32 def initialize(attrs) attrs = attrs.transform_keys(&:to_s) @user_id = attrs["UserID"] @email_address = attrs["EmailAddress"] @first_name = attrs["FirstName"] @last_name = attrs["LastName"] @updated_date_utc = parse_time(attrs["UpdatedDateUTC"]) @is_subscriber = attrs["IsSubscriber"] @organisation_role = attrs["OrganisationRole"] end |
Class Method Details
.from_response(payload) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/xero_kiwi/accounting/user.rb', line 23 def self.from_response(payload) return [] if payload.nil? items = payload["Users"] return [] if items.nil? items.map { |attrs| new(attrs) } end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
49 50 51 |
# File 'lib/xero_kiwi/accounting/user.rb', line 49 def ==(other) other.is_a?(User) && other.user_id == user_id end |
#hash ⇒ Object
54 |
# File 'lib/xero_kiwi/accounting/user.rb', line 54 def hash = [self.class, user_id].hash |
#inspect ⇒ Object
56 57 58 59 |
# File 'lib/xero_kiwi/accounting/user.rb', line 56 def inspect "#<#{self.class} user_id=#{user_id.inspect} " \ "email_address=#{email_address.inspect} organisation_role=#{organisation_role.inspect}>" end |
#subscriber? ⇒ Boolean
43 |
# File 'lib/xero_kiwi/accounting/user.rb', line 43 def subscriber? = is_subscriber == true |
#to_h ⇒ Object
45 46 47 |
# File 'lib/xero_kiwi/accounting/user.rb', line 45 def to_h ATTRIBUTES.keys.to_h { |key| [key, public_send(key)] } end |