Class: Wavix::SubAccounts::Client
- Inherits:
-
Object
- Object
- Wavix::SubAccounts::Client
- Defined in:
- lib/wavix/sub_accounts/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Wavix::Types::SubOrganizationResponse
Creates a sub-account under the authenticated master account.
-
#get(request_options: {}, **params) ⇒ Wavix::Types::SubOrganizationResponse
Returns the sub-account identified by
id. - #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Wavix::Types::SubAccountsListResponse
Returns a paginated list of sub-accounts under the authenticated master account.
- #transactions ⇒ Wavix::Transactions::Client
-
#update(request_options: {}, **params) ⇒ Wavix::Types::SubOrganizationResponse
Replaces the configuration of the sub-account identified by
id.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/wavix/sub_accounts/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Wavix::Types::SubOrganizationResponse
Creates a sub-account under the authenticated master account. Returns the sub-account with its generated
api_key.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/wavix/sub_accounts/client.rb', line 63 def create(request_options: {}, **params) params = Wavix::Internal::Types::Utils.normalize_keys(params) request = Wavix::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v1/sub-organizations", body: Wavix::SubAccounts::Types::SubAccountsCreateRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Wavix::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Wavix::Types::SubOrganizationResponse.load(response.body) else error_class = Wavix::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#get(request_options: {}, **params) ⇒ Wavix::Types::SubOrganizationResponse
Returns the sub-account identified by id.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/wavix/sub_accounts/client.rb', line 98 def get(request_options: {}, **params) params = Wavix::Internal::Types::Utils.normalize_keys(params) request = Wavix::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v1/sub-organizations/#{URI.encode_uri_component(params[:id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Wavix::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Wavix::Types::SubOrganizationResponse.load(response.body) else error_class = Wavix::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list(request_options: {}, **params) ⇒ Wavix::Types::SubAccountsListResponse
Returns a paginated list of sub-accounts under the authenticated master account.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/wavix/sub_accounts/client.rb', line 25 def list(request_options: {}, **params) params = Wavix::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["status"] = params[:status] if params.key?(:status) request = Wavix::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v1/sub-organizations", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Wavix::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Wavix::Types::SubAccountsListResponse.load(response.body) else error_class = Wavix::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#transactions ⇒ Wavix::Transactions::Client
160 161 162 |
# File 'lib/wavix/sub_accounts/client.rb', line 160 def transactions @transactions ||= Wavix::SubAccounts::Transactions::Client.new(client: @client) end |
#update(request_options: {}, **params) ⇒ Wavix::Types::SubOrganizationResponse
Replaces the configuration of the sub-account identified by id. Omitted fields revert to their defaults.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/wavix/sub_accounts/client.rb', line 132 def update(request_options: {}, **params) params = Wavix::Internal::Types::Utils.normalize_keys(params) request_data = Wavix::SubAccounts::Types::SubAccountsUpdateRequest.new(params).to_h non_body_param_names = %w[id] body = request_data.except(*non_body_param_names) request = Wavix::Internal::JSON::Request.new( base_url: [:base_url], method: "PUT", path: "v1/sub-organizations/#{URI.encode_uri_component(params[:id].to_s)}", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Wavix::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Wavix::Types::SubOrganizationResponse.load(response.body) else error_class = Wavix::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |