Class: Schematic::Planbundle::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



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

def initialize(client:)
  @client = client
end

Instance Method Details

#create_custom_plan_bundle(request_options: {}, **params) ⇒ Schematic::Planbundle::Types::CreateCustomPlanBundleResponse

Examples:

client.planbundle.create_custom_plan_bundle(
  billing_product: {
    charge_type: "free",
    is_trialable: true
  },
  entitlements: [{
    action: "create"
  }],
  plan: {
    company_id: "company_id",
    name: "name"
  }
)

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:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/schematic/planbundle/client.rb', line 37

def create_custom_plan_bundle(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: "custom-plan-bundles",
    body: Schematic::Planbundle::Types::CreateCustomPlanBundleRequestBody.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::Planbundle::Types::CreateCustomPlanBundleResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#create_plan_bundle(request_options: {}, **params) ⇒ Schematic::Planbundle::Types::CreatePlanBundleResponse

Examples:

client.planbundle.create_plan_bundle(
  entitlements: [{
    action: "create"
  }],
  plan: {
    name: "name",
    plan_type: "plan"
  }
)

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:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/schematic/planbundle/client.rb', line 80

def create_plan_bundle(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-bundles",
    body: Schematic::Planbundle::Types::CreatePlanBundleRequestBody.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::Planbundle::Types::CreatePlanBundleResponse.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_bundle(request_options: {}, **params) ⇒ Schematic::Planbundle::Types::UpdatePlanBundleResponse

Examples:

client.planbundle.update_plan_bundle(
  plan_id: "plan_id",
  entitlements: [{
    action: "create"
  }],
  plan: {
    name: "name"
  }
)

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_id (String)

Returns:



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/schematic/planbundle/client.rb', line 124

def update_plan_bundle(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  request_data = Schematic::Planbundle::Types::UpdatePlanBundleRequestBody.new(params).to_h
  non_body_param_names = %w[plan_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-bundles/#{URI.encode_uri_component(params[:plan_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::Planbundle::Types::UpdatePlanBundleResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end