Class: Sendly::EnterpriseResource
- Inherits:
-
Object
- Object
- Sendly::EnterpriseResource
- Defined in:
- lib/sendly/enterprise.rb
Instance Attribute Summary collapse
-
#analytics ⇒ Object
readonly
Returns the value of attribute analytics.
-
#billing ⇒ Object
readonly
Returns the value of attribute billing.
-
#credits ⇒ Object
readonly
Returns the value of attribute credits.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
-
#webhooks ⇒ Object
readonly
Returns the value of attribute webhooks.
-
#workspaces ⇒ Object
readonly
Returns the value of attribute workspaces.
Instance Method Summary collapse
- #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
- #get_account ⇒ Object
-
#initialize(client) ⇒ EnterpriseResource
constructor
A new instance of EnterpriseResource.
- #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
- #upload_verification_document(file_path, workspace_id: nil, verification_id: nil) ⇒ Object
Constructor Details
#initialize(client) ⇒ EnterpriseResource
Returns a new instance of EnterpriseResource.
415 416 417 418 419 420 421 422 423 |
# File 'lib/sendly/enterprise.rb', line 415 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
#analytics ⇒ Object (readonly)
Returns the value of attribute analytics.
413 414 415 |
# File 'lib/sendly/enterprise.rb', line 413 def analytics @analytics end |
#billing ⇒ Object (readonly)
Returns the value of attribute billing.
413 414 415 |
# File 'lib/sendly/enterprise.rb', line 413 def billing @billing end |
#credits ⇒ Object (readonly)
Returns the value of attribute credits.
413 414 415 |
# File 'lib/sendly/enterprise.rb', line 413 def credits @credits end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
413 414 415 |
# File 'lib/sendly/enterprise.rb', line 413 def settings @settings end |
#webhooks ⇒ Object (readonly)
Returns the value of attribute webhooks.
413 414 415 |
# File 'lib/sendly/enterprise.rb', line 413 def webhooks @webhooks end |
#workspaces ⇒ Object (readonly)
Returns the value of attribute workspaces.
413 414 415 |
# File 'lib/sendly/enterprise.rb', line 413 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
446 447 448 449 450 451 452 453 454 455 456 457 458 |
# File 'lib/sendly/enterprise.rb', line 446 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] = if @client.post("/enterprise/business-page/generate", body) end |
#get_account ⇒ Object
425 426 427 |
# File 'lib/sendly/enterprise.rb', line 425 def get_account @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
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
# File 'lib/sendly/enterprise.rb', line 429 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
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
# File 'lib/sendly/enterprise.rb', line 460 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 |