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.
-
#all_children(params = {}) ⇒ Object
Retrieve all child Users.
-
#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.
-
#get_next_page_of_children(collection, page_size = nil) ⇒ Object
Get the next page of child users.
-
#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.
43 44 45 46 47 48 |
# File 'lib/easypost/services/user.rb', line 43 def all_api_keys warn '[DEPRECATION] `all_api_keys` is deprecated. Please use `all` in the `api_key` service instead.' response = @client.make_request(:get, 'api_keys') EasyPost::InternalUtilities::Json.convert_json_to_object(response, EasyPost::Models::ApiKey) end |
#all_children(params = {}) ⇒ Object
Retrieve all child Users.
83 84 85 86 87 |
# File 'lib/easypost/services/user.rb', line 83 def all_children(params = {}) filters = { key: 'children' } get_all_helper('users/children', EasyPost::Models::User, params, filters) end |
#api_keys(id) ⇒ Object
Retrieve a list of ApiKey objects (works for the authenticated user or a child user).
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/easypost/services/user.rb', line 51 def api_keys(id) warn '[DEPRECATION] `api_keys` is deprecated. Please use `retrieve_api_keys_for_user` in the `api_key` service instead.' 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 10 11 |
# File 'lib/easypost/services/user.rb', line 7 def create(params = {}) response = @client.make_request(:post, 'users', params) EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS) end |
#delete(id) ⇒ Object
Delete a User
35 36 37 38 39 40 |
# File 'lib/easypost/services/user.rb', line 35 def delete(id) @client.make_request(:delete, "users/#{id}") # Return true if succeeds, an error will be thrown if it fails true end |
#get_next_page_of_children(collection, page_size = nil) ⇒ Object
Get the next page of child users.
90 91 92 93 94 95 96 97 |
# File 'lib/easypost/services/user.rb', line 90 def get_next_page_of_children(collection, page_size = nil) raise EasyPost::Errors::EndOfPaginationError.new unless more_pages?(collection) params = { after_id: collection.children.last.id } params[:page_size] = page_size unless page_size.nil? all_children(params) end |
#retrieve(id) ⇒ Object
Retrieve a user
14 15 16 17 18 |
# File 'lib/easypost/services/user.rb', line 14 def retrieve(id) response = @client.make_request(:get, "users/#{id}") EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS) end |
#retrieve_me ⇒ Object
Retrieve the authenticated User.
21 22 23 24 25 |
# File 'lib/easypost/services/user.rb', line 21 def retrieve_me response = @client.make_request(:get, 'users') EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS) end |
#update(id, params = {}) ⇒ Object
Update a User
28 29 30 31 32 |
# File 'lib/easypost/services/user.rb', line 28 def update(id, params = {}) response = @client.make_request(:put, "users/#{id}", params) EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS) end |
#update_brand(id, params = {}) ⇒ Object
Update the Brand of a User.
75 76 77 78 79 80 |
# File 'lib/easypost/services/user.rb', line 75 def update_brand(id, params = {}) wrapped_params = { brand: params } response = @client.make_request(:get, "users/#{id}/brand", wrapped_params) EasyPost::InternalUtilities::Json.convert_json_to_object(response, EasyPost::Models::Brand) end |