Class: Bitly::API::User
Overview
A User represents the authorized user
Defined Under Namespace
Classes: Email
Instance Attribute Summary collapse
-
#emails ⇒ Object
readonly
Returns the value of attribute emails.
Attributes included from Base
Class Method Summary collapse
-
.attributes ⇒ Array<Symbol>
The attributes the API returns for a user.
-
.fetch(client:) ⇒ Bitly::API::User
Gets the authorized user from the API.
-
.time_attributes ⇒ Array<Symbol>
converted to ‘Time` objects.
Instance Method Summary collapse
-
#default_group ⇒ Object
Returns the default group for the user from the default group guid.
-
#initialize(data:, client:, response: nil) ⇒ Bitly::API::User
constructor
Creates a Bitly::API::User object.
-
#update(name: nil, default_group_guid: nil) ⇒ Bitly::API::User
Allows you to update the authorized user’s name or default group guid.
Methods included from Base
Constructor Details
#initialize(data:, client:, response: nil) ⇒ Bitly::API::User
Creates a Bitly::API::User object.
58 59 60 61 62 63 64 65 |
# File 'lib/bitly/api/user.rb', line 58 def initialize(data:, client:, response: nil) assign_attributes(data) @client = client @response = response if data["emails"] @emails = data["emails"].map { |e| Email.new(e) } end end |
Instance Attribute Details
#emails ⇒ Object (readonly)
Returns the value of attribute emails.
45 46 47 |
# File 'lib/bitly/api/user.rb', line 45 def emails @emails end |
Class Method Details
.attributes ⇒ Array<Symbol>
Returns The attributes the API returns for a user.
35 36 37 |
# File 'lib/bitly/api/user.rb', line 35 def self.attributes [:login, :is_active, :is_2fa_enabled, :name, :is_sso_user, :default_group_guid] end |
.fetch(client:) ⇒ Bitly::API::User
Gets the authorized user from the API. [‘GET /v4/user`](dev.bitly.com/api-reference/#getUser)
29 30 31 32 |
# File 'lib/bitly/api/user.rb', line 29 def self.fetch(client:) response = client.request(path: "/user") new(data: response.body, client: client, response: response) end |
.time_attributes ⇒ Array<Symbol>
converted to ‘Time` objects.
40 41 42 |
# File 'lib/bitly/api/user.rb', line 40 def self.time_attributes [:created, :modified] end |
Instance Method Details
#default_group ⇒ Object
Returns the default group for the user from the default group guid
74 75 76 |
# File 'lib/bitly/api/user.rb', line 74 def default_group @default_group ||= Group.fetch(client: @client, guid: default_group_guid) end |
#update(name: nil, default_group_guid: nil) ⇒ Bitly::API::User
Allows you to update the authorized user’s name or default group guid. If you update the default group ID and have already loaded the default group, it is nilled out so it can be reloaded with the correct ID. [‘PATCH /v4/user`](dev.bitly.com/api-reference/#updateUser).
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/bitly/api/user.rb', line 91 def update(name: nil, default_group_guid: nil) params = { "name" => name } if default_group_guid params["default_group_guid"] = default_group_guid @default_group = nil end @response = @client.request( path: "/user", method: "PATCH", params: params ) assign_attributes(@response.body) self end |