Class: Sendly::EnterpriseResource

Inherits:
Object
  • Object
show all
Defined in:
lib/sendly/enterprise.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ EnterpriseResource

Returns a new instance of EnterpriseResource.



363
364
365
366
367
368
369
370
371
# File 'lib/sendly/enterprise.rb', line 363

def initialize(client)
  @client = client
  @workspaces = EnterpriseWorkspacesSubResource.new(client)
  @webhooks = EnterpriseWebhooksSubResource.new(client)
  @analytics = EnterpriseAnalyticsSubResource.new(client)
  @settings = EnterpriseSettingsSubResource.new(client)
  @billing = EnterpriseBillingSubResource.new(client)
  @credits = EnterpriseCreditsSubResource.new(client)
end

Instance Attribute Details

#analyticsObject (readonly)

Returns the value of attribute analytics.



361
362
363
# File 'lib/sendly/enterprise.rb', line 361

def analytics
  @analytics
end

#billingObject (readonly)

Returns the value of attribute billing.



361
362
363
# File 'lib/sendly/enterprise.rb', line 361

def billing
  @billing
end

#creditsObject (readonly)

Returns the value of attribute credits.



361
362
363
# File 'lib/sendly/enterprise.rb', line 361

def credits
  @credits
end

#settingsObject (readonly)

Returns the value of attribute settings.



361
362
363
# File 'lib/sendly/enterprise.rb', line 361

def settings
  @settings
end

#webhooksObject (readonly)

Returns the value of attribute webhooks.



361
362
363
# File 'lib/sendly/enterprise.rb', line 361

def webhooks
  @webhooks
end

#workspacesObject (readonly)

Returns the value of attribute workspaces.



361
362
363
# File 'lib/sendly/enterprise.rb', line 361

def workspaces
  @workspaces
end

Instance Method Details

#generate_business_page(business_name:, use_case: nil, use_case_summary: nil, contact_email: nil, contact_phone: nil, business_address: nil, social_url: nil) ⇒ Object

Raises:

  • (ArgumentError)


394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/sendly/enterprise.rb', line 394

def generate_business_page(business_name:, use_case: nil, use_case_summary: nil, contact_email: nil, contact_phone: nil, business_address: nil, social_url: nil)
  raise ArgumentError, "Business name is required" if business_name.nil? || business_name.strip.empty?

  body = { businessName: business_name }
  body[:useCase] = use_case if use_case
  body[:useCaseSummary] = use_case_summary if use_case_summary
  body[:contactEmail] = contact_email if contact_email
  body[:contactPhone] = contact_phone if contact_phone
  body[:businessAddress] = business_address if business_address
  body[:socialUrl] = social_url if social_url

  @client.post("/enterprise/business-page/generate", body)
end

#get_accountObject



373
374
375
# File 'lib/sendly/enterprise.rb', line 373

def 
  @client.get("/enterprise/account")
end

#provision(name:, source_workspace_id: nil, inherit_with_new_number: nil, verification: nil, credit_amount: nil, credit_source_workspace_id: nil, key_name: nil, key_type: nil, webhook_url: nil, generate_opt_in_page: nil) ⇒ Object

Raises:

  • (ArgumentError)


377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/sendly/enterprise.rb', line 377

def provision(name:, source_workspace_id: nil, inherit_with_new_number: nil, verification: nil, credit_amount: nil, credit_source_workspace_id: nil, key_name: nil, key_type: nil, webhook_url: nil, generate_opt_in_page: nil)
  raise ArgumentError, "Workspace name is required" if name.nil? || name.strip.empty?

  body = { name: name }
  body[:sourceWorkspaceId] = source_workspace_id if source_workspace_id
  body[:inheritWithNewNumber] = true if inherit_with_new_number
  body[:verification] = verification if verification
  body[:creditAmount] = credit_amount if credit_amount
  body[:creditSourceWorkspaceId] = credit_source_workspace_id if credit_source_workspace_id
  body[:keyName] = key_name if key_name
  body[:keyType] = key_type if key_type
  body[:webhookUrl] = webhook_url if webhook_url
  body[:generateOptInPage] = generate_opt_in_page unless generate_opt_in_page.nil?

  @client.post("/enterprise/workspaces/provision", body)
end

#upload_verification_document(file_path, workspace_id: nil, verification_id: nil) ⇒ Object

Raises:

  • (ArgumentError)


408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# File 'lib/sendly/enterprise.rb', line 408

def upload_verification_document(file_path, workspace_id: nil, verification_id: nil)
  raise ArgumentError, "File path is required" if file_path.nil? || file_path.empty?
  raise ArgumentError, "File not found: #{file_path}" unless File.exist?(file_path)

  content_type = case File.extname(file_path).downcase
                 when ".jpg", ".jpeg" then "image/jpeg"
                 when ".png" then "image/png"
                 when ".gif" then "image/gif"
                 when ".pdf" then "application/pdf"
                 when ".webp" then "image/webp"
                 else "application/octet-stream"
                 end

  filename = File.basename(file_path)

  boundary = "SendlyRuby#{SecureRandom.hex(16)}"
  body_parts = []
  body_parts << "--#{boundary}\r\n"
  body_parts << "Content-Disposition: form-data; name=\"file\"; filename=\"#{filename}\"\r\n"
  body_parts << "Content-Type: #{content_type}\r\n\r\n"
  body_parts << File.binread(file_path)

  if workspace_id
    body_parts << "\r\n--#{boundary}\r\n"
    body_parts << "Content-Disposition: form-data; name=\"workspaceId\"\r\n\r\n"
    body_parts << workspace_id
  end

  if verification_id
    body_parts << "\r\n--#{boundary}\r\n"
    body_parts << "Content-Disposition: form-data; name=\"verificationId\"\r\n\r\n"
    body_parts << verification_id
  end

  body_parts << "\r\n--#{boundary}--\r\n"

  uri = URI.parse("#{@client.base_url}/enterprise/verification-document/upload")
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = uri.scheme == "https"
  http.open_timeout = 10
  http.read_timeout = @client.timeout

  req = Net::HTTP::Post.new(uri)
  req["Authorization"] = "Bearer #{@client.api_key}"
  req["Accept"] = "application/json"
  req["User-Agent"] = "sendly-ruby/#{Sendly::VERSION}"
  req["Content-Type"] = "multipart/form-data; boundary=#{boundary}"
  req["X-Organization-Id"] = @client.organization_id if @client.organization_id
  req.body = body_parts.join

  response = http.request(req)
  body = response.body.nil? || response.body.empty? ? {} : JSON.parse(response.body)
  status = response.code.to_i

  return body if status >= 200 && status < 300

  raise Sendly::ErrorFactory.from_response(status, body)
end