Class: EasyPost::Services::User
- Defined in:
- lib/easypost/services/user.rb
Constant Summary collapse
Instance Method Summary collapse
-
#all_api_keys ⇒ Object
Retrieve a list of all ApiKey objects.
-
#api_keys(id) ⇒ Object
Retrieve a list of ApiKey objects (works for the authenticated user or a child user).
-
#create(params = {}) ⇒ Object
Create a child User.
-
#delete(id) ⇒ Object
Delete a User.
-
#retrieve(id) ⇒ Object
Retrieve a user.
-
#retrieve_me ⇒ Object
Retrieve the authenticated User.
-
#update(id, params = {}) ⇒ Object
Update a User.
-
#update_brand(id, params = {}) ⇒ Object
Update the Brand of a User.
Methods inherited from Service
Constructor Details
This class inherits a constructor from EasyPost::Services::Service
Instance Method Details
#all_api_keys ⇒ Object
Retrieve a list of all ApiKey objects.
35 36 37 |
# File 'lib/easypost/services/user.rb', line 35 def all_api_keys @client.make_request(:get, 'api_keys', EasyPost::Models::ApiKey) end |
#api_keys(id) ⇒ Object
Retrieve a list of ApiKey objects (works for the authenticated user or a child user).
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/easypost/services/user.rb', line 40 def api_keys(id) api_keys = all_api_keys if api_keys.id == id # This function was called on the authenticated user my_api_keys = api_keys.keys else # This function was called on a child user (authenticated as parent, only return this child user's details). my_api_keys = [] api_keys.children.each do |child| if child.id == id my_api_keys = child.keys break end end end my_api_keys end |
#create(params = {}) ⇒ Object
Create a child User.
7 8 9 |
# File 'lib/easypost/services/user.rb', line 7 def create(params = {}) @client.make_request(:post, 'users', MODEL_CLASS, params) end |
#delete(id) ⇒ Object
Delete a User
27 28 29 30 31 32 |
# File 'lib/easypost/services/user.rb', line 27 def delete(id) @client.make_request(:delete, "users/#{id}") # Return true if succeeds, an error will be thrown if it fails true end |
#retrieve(id) ⇒ Object
Retrieve a user
12 13 14 |
# File 'lib/easypost/services/user.rb', line 12 def retrieve(id) @client.make_request(:get, "users/#{id}", MODEL_CLASS) end |
#retrieve_me ⇒ Object
Retrieve the authenticated User.
17 18 19 |
# File 'lib/easypost/services/user.rb', line 17 def retrieve_me @client.make_request(:get, 'users', MODEL_CLASS) end |
#update(id, params = {}) ⇒ Object
Update a User
22 23 24 |
# File 'lib/easypost/services/user.rb', line 22 def update(id, params = {}) @client.make_request(:put, "users/#{id}", MODEL_CLASS, params) end |