Class: Schematic::Plangroups::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/schematic/plangroups/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



9
10
11
# File 'lib/schematic/plangroups/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#create_plan_group(request_options: {}, **params) ⇒ Schematic::Plangroups::Types::CreatePlanGroupResponse

Examples:

client.plangroups.create_plan_group(
  add_on_ids: ["add_on_ids"],
  checkout_collect_address: true,
  checkout_collect_email: true,
  checkout_collect_phone: true,
  checkout_collect_tax_id: true,
  enable_tax_collection: true,
  opt_in_enabled: true,
  ordered_add_ons: [{
    plan_id: "plan_id"
  }],
  ordered_bundle_list: [{
    bundle_id: "bundleId"
  }],
  ordered_plans: [{
    plan_id: "plan_id"
  }],
  prevent_downgrades_when_over_limit: true,
  prevent_self_service_downgrade: true,
  proration_behavior: "create_prorations",
  show_as_monthly_prices: true,
  show_credits: true,
  show_feature_description: true,
  show_hard_limit: true,
  show_period_toggle: true,
  show_zero_price_as_free: true,
  sync_customer_billing_details: true
)

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/schematic/plangroups/client.rb', line 91

def create_plan_group(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "plan-groups",
    body: Schematic::Plangroups::Types::CreatePlanGroupRequestBody.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Plangroups::Types::CreatePlanGroupResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_plan_group(request_options: {}, **params) ⇒ Schematic::Plangroups::Types::GetPlanGroupResponse

Examples:

client.plangroups.get_plan_group(include_company_counts: true)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :include_company_counts (Boolean, nil)

Returns:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/schematic/plangroups/client.rb', line 26

def get_plan_group(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["include_company_counts"] = params[:include_company_counts] if params.key?(:include_company_counts)

  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "plan-groups",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Plangroups::Types::GetPlanGroupResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#update_plan_group(request_options: {}, **params) ⇒ Schematic::Plangroups::Types::UpdatePlanGroupResponse

Examples:

client.plangroups.update_plan_group(
  plan_group_id: "plan_group_id",
  add_on_ids: ["add_on_ids"],
  checkout_collect_address: true,
  checkout_collect_email: true,
  checkout_collect_phone: true,
  checkout_collect_tax_id: true,
  enable_tax_collection: true,
  opt_in_enabled: true,
  ordered_add_ons: [{
    plan_id: "plan_id"
  }],
  ordered_bundle_list: [{
    bundle_id: "bundleId"
  }],
  ordered_plans: [{
    plan_id: "plan_id"
  }],
  prevent_downgrades_when_over_limit: true,
  prevent_self_service_downgrade: true,
  proration_behavior: "create_prorations",
  show_as_monthly_prices: true,
  show_credits: true,
  show_feature_description: true,
  show_hard_limit: true,
  show_period_toggle: true,
  show_zero_price_as_free: true,
  sync_customer_billing_details: true
)

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :plan_group_id (String)

Returns:



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/schematic/plangroups/client.rb', line 155

def update_plan_group(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  request_data = Schematic::Plangroups::Types::UpdatePlanGroupRequestBody.new(params).to_h
  non_body_param_names = %w[plan_group_id]
  body = request_data.except(*non_body_param_names)

  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PUT",
    path: "plan-groups/#{URI.encode_uri_component(params[:plan_group_id].to_s)}",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Plangroups::Types::UpdatePlanGroupResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end