kapso-client-ruby 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -2
- data/RAILS_INTEGRATION.md +478 -0
- data/README.md +33 -15
- data/examples/rails/jobs.rb +388 -0
- data/examples/rails/models.rb +240 -0
- data/examples/rails/notifications_controller.rb +227 -0
- data/examples/template_management.rb +10 -10
- data/lib/kapso_client_ruby/client.rb +2 -2
- data/lib/kapso_client_ruby/rails/generators/install_generator.rb +76 -0
- data/lib/kapso_client_ruby/rails/generators/templates/env.erb +21 -0
- data/lib/kapso_client_ruby/rails/generators/templates/initializer.rb.erb +33 -0
- data/lib/kapso_client_ruby/rails/generators/templates/message_service.rb.erb +138 -0
- data/lib/kapso_client_ruby/rails/generators/templates/webhook_controller.rb.erb +62 -0
- data/lib/kapso_client_ruby/rails/railtie.rb +55 -0
- data/lib/kapso_client_ruby/rails/service.rb +189 -0
- data/lib/kapso_client_ruby/rails/tasks.rake +167 -0
- data/lib/kapso_client_ruby/version.rb +1 -1
- data/lib/kapso_client_ruby.rb +6 -0
- data/scripts/kapso_template_finder.rb +2 -2
- data/scripts/sdk_setup.rb +15 -15
- metadata +13 -1
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/railtie'
|
4
|
+
|
5
|
+
module KapsoClientRuby
|
6
|
+
module Rails
|
7
|
+
# Rails integration for KapsoClientRuby
|
8
|
+
class Railtie < ::Rails::Railtie
|
9
|
+
railtie_name :kapso_client_ruby
|
10
|
+
|
11
|
+
# Add kapso configuration to Rails application config
|
12
|
+
config.kapso = ActiveSupport::OrderedOptions.new
|
13
|
+
|
14
|
+
# Set default configuration values
|
15
|
+
config.before_configuration do |app|
|
16
|
+
app.config.kapso.api_key = nil
|
17
|
+
app.config.kapso.phone_number_id = nil
|
18
|
+
app.config.kapso.business_account_id = nil
|
19
|
+
app.config.kapso.api_host = 'https://graph.facebook.com'
|
20
|
+
app.config.kapso.api_version = 'v23.0'
|
21
|
+
app.config.kapso.timeout = 30
|
22
|
+
app.config.kapso.debug = false
|
23
|
+
app.config.kapso.logger = nil
|
24
|
+
app.config.kapso.retry_on_failure = true
|
25
|
+
app.config.kapso.max_retries = 3
|
26
|
+
end
|
27
|
+
|
28
|
+
# Initialize Kapso client after Rails application initialization
|
29
|
+
initializer 'kapso_client_ruby.configure' do |app|
|
30
|
+
KapsoClientRuby.configure do |config|
|
31
|
+
config.api_key = app.config.kapso.api_key || ENV['KAPSO_API_KEY']
|
32
|
+
config.phone_number_id = app.config.kapso.phone_number_id || ENV['KAPSO_PHONE_NUMBER_ID']
|
33
|
+
config.business_account_id = app.config.kapso.business_account_id || ENV['KAPSO_BUSINESS_ACCOUNT_ID']
|
34
|
+
config.api_host = app.config.kapso.api_host || ENV.fetch('KAPSO_API_HOST', 'https://graph.facebook.com')
|
35
|
+
config.api_version = app.config.kapso.api_version || ENV.fetch('KAPSO_API_VERSION', 'v23.0')
|
36
|
+
config.timeout = app.config.kapso.timeout || ENV.fetch('KAPSO_TIMEOUT', 30).to_i
|
37
|
+
config.debug = app.config.kapso.debug || ENV.fetch('KAPSO_DEBUG', 'false') == 'true'
|
38
|
+
config.logger = app.config.kapso.logger || ::Rails.logger
|
39
|
+
config.retry_on_failure = app.config.kapso.retry_on_failure
|
40
|
+
config.max_retries = app.config.kapso.max_retries || ENV.fetch('KAPSO_MAX_RETRIES', 3).to_i
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Add rake tasks
|
45
|
+
rake_tasks do
|
46
|
+
load 'kapso_client_ruby/rails/tasks.rake'
|
47
|
+
end
|
48
|
+
|
49
|
+
# Add generators
|
50
|
+
generators do
|
51
|
+
require 'kapso_client_ruby/rails/generators/install_generator'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KapsoClientRuby
|
4
|
+
module Rails
|
5
|
+
# Service class for Rails integration with KapsoClientRuby
|
6
|
+
# Provides a convenient interface for Rails applications to interact with the Kapso API
|
7
|
+
class Service
|
8
|
+
include ActiveSupport::Configurable
|
9
|
+
|
10
|
+
# @return [KapsoClientRuby::Client] The configured Kapso client
|
11
|
+
attr_reader :client
|
12
|
+
|
13
|
+
def initialize(client = nil)
|
14
|
+
@client = client || KapsoClientRuby::Client.new
|
15
|
+
end
|
16
|
+
|
17
|
+
# Send a text message
|
18
|
+
# @param to [String] The recipient's phone number
|
19
|
+
# @param text [String] The message text
|
20
|
+
# @param options [Hash] Additional options
|
21
|
+
# @return [Hash] API response
|
22
|
+
def send_text_message(to:, text:, **options)
|
23
|
+
Rails.logger.info "Sending text message to #{to}: #{text.truncate(50)}"
|
24
|
+
|
25
|
+
result = client.messages.send_text(
|
26
|
+
to: to,
|
27
|
+
text: text,
|
28
|
+
**options
|
29
|
+
)
|
30
|
+
|
31
|
+
Rails.logger.info "Message sent successfully. ID: #{result.dig('messages', 0, 'id')}"
|
32
|
+
result
|
33
|
+
rescue KapsoClientRuby::Error => e
|
34
|
+
Rails.logger.error "Failed to send text message: #{e.message}"
|
35
|
+
raise
|
36
|
+
end
|
37
|
+
|
38
|
+
# Send a template message
|
39
|
+
# @param to [String] The recipient's phone number
|
40
|
+
# @param template_name [String] The template name
|
41
|
+
# @param language [String] The language code (default: 'en')
|
42
|
+
# @param components [Array] Template components
|
43
|
+
# @return [Hash] API response
|
44
|
+
def send_template_message(to:, template_name:, language: 'en', components: [])
|
45
|
+
Rails.logger.info "Sending template message '#{template_name}' to #{to}"
|
46
|
+
|
47
|
+
result = client.messages.send_template(
|
48
|
+
to: to,
|
49
|
+
name: template_name,
|
50
|
+
language: language,
|
51
|
+
components: components
|
52
|
+
)
|
53
|
+
|
54
|
+
Rails.logger.info "Template message sent successfully. ID: #{result.dig('messages', 0, 'id')}"
|
55
|
+
result
|
56
|
+
rescue KapsoClientRuby::Error => e
|
57
|
+
Rails.logger.error "Failed to send template message: #{e.message}"
|
58
|
+
raise
|
59
|
+
end
|
60
|
+
|
61
|
+
# Send a media message
|
62
|
+
# @param to [String] The recipient's phone number
|
63
|
+
# @param media_type [String] Type of media ('image', 'document', 'video', 'audio')
|
64
|
+
# @param media_url [String] URL of the media file
|
65
|
+
# @param options [Hash] Additional options
|
66
|
+
# @return [Hash] API response
|
67
|
+
def send_media_message(to:, media_type:, media_url:, **options)
|
68
|
+
Rails.logger.info "Sending #{media_type} message to #{to}: #{media_url}"
|
69
|
+
|
70
|
+
result = client.messages.send_media(
|
71
|
+
to: to,
|
72
|
+
type: media_type,
|
73
|
+
media_url: media_url,
|
74
|
+
**options
|
75
|
+
)
|
76
|
+
|
77
|
+
Rails.logger.info "Media message sent successfully. ID: #{result.dig('messages', 0, 'id')}"
|
78
|
+
result
|
79
|
+
rescue KapsoClientRuby::Error => e
|
80
|
+
Rails.logger.error "Failed to send media message: #{e.message}"
|
81
|
+
raise
|
82
|
+
end
|
83
|
+
|
84
|
+
# Upload media file
|
85
|
+
# @param file_path [String] Path to the media file
|
86
|
+
# @param media_type [String] Type of media
|
87
|
+
# @return [Hash] Upload response with media ID
|
88
|
+
def upload_media(file_path:, media_type:)
|
89
|
+
Rails.logger.info "Uploading media file: #{file_path}"
|
90
|
+
|
91
|
+
result = client.media.upload(
|
92
|
+
file_path: file_path,
|
93
|
+
type: media_type
|
94
|
+
)
|
95
|
+
|
96
|
+
Rails.logger.info "Media uploaded successfully. ID: #{result['id']}"
|
97
|
+
result
|
98
|
+
rescue KapsoClientRuby::Error => e
|
99
|
+
Rails.logger.error "Failed to upload media: #{e.message}"
|
100
|
+
raise
|
101
|
+
end
|
102
|
+
|
103
|
+
# Get message status
|
104
|
+
# @param message_id [String] The message ID
|
105
|
+
# @return [Hash] Message status
|
106
|
+
def get_message_status(message_id)
|
107
|
+
Rails.logger.debug "Getting status for message: #{message_id}"
|
108
|
+
|
109
|
+
result = client.messages.get_status(message_id)
|
110
|
+
|
111
|
+
Rails.logger.debug "Message status: #{result['status']}"
|
112
|
+
result
|
113
|
+
rescue KapsoClientRuby::Error => e
|
114
|
+
Rails.logger.error "Failed to get message status: #{e.message}"
|
115
|
+
raise
|
116
|
+
end
|
117
|
+
|
118
|
+
# Get templates
|
119
|
+
# @param options [Hash] Query options
|
120
|
+
# @return [Array] List of templates
|
121
|
+
def get_templates(**options)
|
122
|
+
Rails.logger.debug "Fetching templates with options: #{options}"
|
123
|
+
|
124
|
+
result = client.templates.list(**options)
|
125
|
+
|
126
|
+
Rails.logger.debug "Found #{result['data']&.length || 0} templates"
|
127
|
+
result
|
128
|
+
rescue KapsoClientRuby::Error => e
|
129
|
+
Rails.logger.error "Failed to fetch templates: #{e.message}"
|
130
|
+
raise
|
131
|
+
end
|
132
|
+
|
133
|
+
# Process incoming webhook
|
134
|
+
# @param webhook_data [Hash] The webhook payload
|
135
|
+
# @return [Hash] Processed webhook data
|
136
|
+
def process_webhook(webhook_data)
|
137
|
+
Rails.logger.info "Processing webhook: #{webhook_data}"
|
138
|
+
|
139
|
+
# Process webhook data based on type
|
140
|
+
entries = webhook_data['entry'] || []
|
141
|
+
|
142
|
+
entries.each do |entry|
|
143
|
+
changes = entry['changes'] || []
|
144
|
+
|
145
|
+
changes.each do |change|
|
146
|
+
case change['field']
|
147
|
+
when 'messages'
|
148
|
+
process_message_webhook(change['value'])
|
149
|
+
when 'message_template_status_update'
|
150
|
+
process_template_status_webhook(change['value'])
|
151
|
+
else
|
152
|
+
Rails.logger.warn "Unknown webhook field: #{change['field']}"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
{ status: 'processed' }
|
158
|
+
rescue => e
|
159
|
+
Rails.logger.error "Failed to process webhook: #{e.message}"
|
160
|
+
raise
|
161
|
+
end
|
162
|
+
|
163
|
+
private
|
164
|
+
|
165
|
+
def process_message_webhook(value)
|
166
|
+
messages = value['messages'] || []
|
167
|
+
statuses = value['statuses'] || []
|
168
|
+
|
169
|
+
messages.each do |message|
|
170
|
+
Rails.logger.info "Received message: #{message['id']} from #{message['from']}"
|
171
|
+
# Trigger Rails callback or event
|
172
|
+
ActiveSupport::Notifications.instrument('kapso.message_received', message: message)
|
173
|
+
end
|
174
|
+
|
175
|
+
statuses.each do |status|
|
176
|
+
Rails.logger.info "Message status update: #{status['id']} -> #{status['status']}"
|
177
|
+
# Trigger Rails callback or event
|
178
|
+
ActiveSupport::Notifications.instrument('kapso.message_status_updated', status: status)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def process_template_status_webhook(value)
|
183
|
+
Rails.logger.info "Template status update: #{value}"
|
184
|
+
# Trigger Rails callback or event
|
185
|
+
ActiveSupport::Notifications.instrument('kapso.template_status_updated', template_status: value)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
namespace :kapso do
|
4
|
+
desc 'Test Kapso configuration and send a test message'
|
5
|
+
task test: :environment do
|
6
|
+
puts "🔧 Testing Kapso configuration..."
|
7
|
+
|
8
|
+
# Check configuration
|
9
|
+
client = KapsoClientRuby::Client.new
|
10
|
+
puts "✅ Kapso client initialized"
|
11
|
+
puts "📱 Phone Number ID: #{client.phone_number_id}"
|
12
|
+
puts "🏢 Business Account ID: #{client.business_account_id}"
|
13
|
+
|
14
|
+
# Test API connection
|
15
|
+
begin
|
16
|
+
templates = client.templates.list(limit: 1)
|
17
|
+
puts "✅ API connection successful"
|
18
|
+
puts "📋 Found #{templates.dig('data')&.length || 0} templates"
|
19
|
+
rescue => e
|
20
|
+
puts "❌ API connection failed: #{e.message}"
|
21
|
+
exit 1
|
22
|
+
end
|
23
|
+
|
24
|
+
# Send test message if phone number is provided
|
25
|
+
test_number = ENV['KAPSO_TEST_PHONE_NUMBER']
|
26
|
+
if test_number
|
27
|
+
puts "\n📤 Sending test message to #{test_number}..."
|
28
|
+
service = KapsoMessageService.new
|
29
|
+
service.send_test_message
|
30
|
+
else
|
31
|
+
puts "\n💡 Set KAPSO_TEST_PHONE_NUMBER to test messaging"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'List available WhatsApp message templates'
|
36
|
+
task templates: :environment do
|
37
|
+
puts "📋 Fetching WhatsApp templates..."
|
38
|
+
|
39
|
+
service = KapsoMessageService.new
|
40
|
+
templates_response = service.list_templates
|
41
|
+
|
42
|
+
if templates_response && templates_response['data']
|
43
|
+
templates = templates_response['data']
|
44
|
+
puts "Found #{templates.length} templates:\n\n"
|
45
|
+
|
46
|
+
templates.each do |template|
|
47
|
+
puts "📄 #{template['name']}"
|
48
|
+
puts " Status: #{template['status']}"
|
49
|
+
puts " Language: #{template['language']}"
|
50
|
+
puts " Category: #{template['category']}"
|
51
|
+
puts " Created: #{Time.at(template['created_time']).to_s}" if template['created_time']
|
52
|
+
puts ""
|
53
|
+
end
|
54
|
+
else
|
55
|
+
puts "❌ Failed to fetch templates or no templates found"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
desc 'Check message status'
|
60
|
+
task :message_status, [:message_id] => :environment do |task, args|
|
61
|
+
message_id = args[:message_id]
|
62
|
+
|
63
|
+
unless message_id
|
64
|
+
puts "❌ Please provide a message ID: rake kapso:message_status[message_id]"
|
65
|
+
exit 1
|
66
|
+
end
|
67
|
+
|
68
|
+
puts "🔍 Checking status for message: #{message_id}"
|
69
|
+
|
70
|
+
service = KapsoMessageService.new
|
71
|
+
status = service.get_message_status(message_id)
|
72
|
+
|
73
|
+
if status
|
74
|
+
puts "📊 Message Status:"
|
75
|
+
puts " ID: #{status['id']}"
|
76
|
+
puts " Status: #{status['status']}"
|
77
|
+
puts " Timestamp: #{Time.at(status['timestamp']).to_s}" if status['timestamp']
|
78
|
+
puts " Recipient: #{status['recipient_id']}" if status['recipient_id']
|
79
|
+
|
80
|
+
if status['errors']
|
81
|
+
puts " Errors: #{status['errors']}"
|
82
|
+
end
|
83
|
+
else
|
84
|
+
puts "❌ Failed to get message status"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
desc 'Validate webhook configuration'
|
89
|
+
task validate_webhook: :environment do
|
90
|
+
puts "🔗 Validating webhook configuration..."
|
91
|
+
|
92
|
+
# Check required environment variables
|
93
|
+
required_vars = %w[KAPSO_WEBHOOK_VERIFY_TOKEN]
|
94
|
+
optional_vars = %w[KAPSO_WEBHOOK_SECRET]
|
95
|
+
|
96
|
+
required_vars.each do |var|
|
97
|
+
if ENV[var].present?
|
98
|
+
puts "✅ #{var} is set"
|
99
|
+
else
|
100
|
+
puts "❌ #{var} is not set (required)"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
optional_vars.each do |var|
|
105
|
+
if ENV[var].present?
|
106
|
+
puts "✅ #{var} is set (recommended for security)"
|
107
|
+
else
|
108
|
+
puts "⚠️ #{var} is not set (optional but recommended)"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Check if routes are properly configured
|
113
|
+
begin
|
114
|
+
webhook_path = Rails.application.routes.url_helpers.kapso_webhooks_path rescue nil
|
115
|
+
if webhook_path
|
116
|
+
puts "✅ Webhook routes are configured"
|
117
|
+
puts " Webhook URL: #{Rails.application.config.force_ssl ? 'https' : 'http'}://yourapp.com#{webhook_path}"
|
118
|
+
else
|
119
|
+
puts "⚠️ Webhook routes may not be configured. Make sure to add:"
|
120
|
+
puts " post '/webhooks/kapso', to: 'kapso_webhooks#create'"
|
121
|
+
puts " get '/webhooks/kapso', to: 'kapso_webhooks#verify'"
|
122
|
+
end
|
123
|
+
rescue => e
|
124
|
+
puts "⚠️ Could not check webhook routes: #{e.message}"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
desc 'Generate sample environment file'
|
129
|
+
task :sample_env do
|
130
|
+
puts "📝 Generating .env.kapso.sample file..."
|
131
|
+
|
132
|
+
env_content = <<~ENV
|
133
|
+
# Kapso API Configuration
|
134
|
+
# Copy this to your .env file and fill in your actual values
|
135
|
+
|
136
|
+
# Required: Your Kapso API access token
|
137
|
+
KAPSO_API_KEY=your_api_key_here
|
138
|
+
|
139
|
+
# Required: Your WhatsApp Business phone number ID
|
140
|
+
KAPSO_PHONE_NUMBER_ID=your_phone_number_id_here
|
141
|
+
|
142
|
+
# Required: Your WhatsApp Business account ID
|
143
|
+
KAPSO_BUSINESS_ACCOUNT_ID=your_business_account_id_here
|
144
|
+
|
145
|
+
# Optional: API configuration
|
146
|
+
KAPSO_API_HOST=https://graph.facebook.com
|
147
|
+
KAPSO_API_VERSION=v18.0
|
148
|
+
KAPSO_TIMEOUT=30
|
149
|
+
|
150
|
+
# Optional: Debug and retry settings
|
151
|
+
KAPSO_DEBUG=false
|
152
|
+
KAPSO_RETRY_ON_FAILURE=true
|
153
|
+
KAPSO_MAX_RETRIES=3
|
154
|
+
|
155
|
+
# Webhook configuration
|
156
|
+
KAPSO_WEBHOOK_VERIFY_TOKEN=your_webhook_verify_token_here
|
157
|
+
KAPSO_WEBHOOK_SECRET=your_webhook_secret_here
|
158
|
+
|
159
|
+
# Testing
|
160
|
+
KAPSO_TEST_PHONE_NUMBER=+1234567890
|
161
|
+
ENV
|
162
|
+
|
163
|
+
File.write('.env.kapso.sample', env_content)
|
164
|
+
puts "✅ Created .env.kapso.sample"
|
165
|
+
puts "💡 Copy this to .env and update with your actual credentials"
|
166
|
+
end
|
167
|
+
end
|
data/lib/kapso_client_ruby.rb
CHANGED
@@ -12,6 +12,12 @@ require_relative 'kapso_client_ruby/resources/calls'
|
|
12
12
|
require_relative 'kapso_client_ruby/resources/conversations'
|
13
13
|
require_relative 'kapso_client_ruby/resources/contacts'
|
14
14
|
|
15
|
+
# Load Rails integration if Rails is available
|
16
|
+
if defined?(Rails)
|
17
|
+
require_relative 'kapso_client_ruby/rails/railtie'
|
18
|
+
require_relative 'kapso_client_ruby/rails/service'
|
19
|
+
end
|
20
|
+
|
15
21
|
module KapsoClientRuby
|
16
22
|
class << self
|
17
23
|
# Configure default logging
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'dotenv/load' rescue nil
|
5
|
-
require_relative '../lib/
|
5
|
+
require_relative '../lib/kapso_client_ruby'
|
6
6
|
|
7
7
|
puts "🔍 Kapso Template Finder"
|
8
8
|
puts "=" * 30
|
@@ -16,7 +16,7 @@ unless kapso_api_key && phone_number_id
|
|
16
16
|
exit 1
|
17
17
|
end
|
18
18
|
|
19
|
-
client =
|
19
|
+
client = KapsoClientRuby::Client.new(
|
20
20
|
kapso_api_key: kapso_api_key,
|
21
21
|
base_url: ENV['WHATSAPP_BASE_URL'] || 'https://app.kapso.ai/api/meta'
|
22
22
|
)
|
data/scripts/sdk_setup.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require_relative '../lib/
|
4
|
+
require_relative '../lib/kapso_client_ruby'
|
5
5
|
|
6
6
|
puts "=== Kapso.ai and WhatsApp Cloud API Ruby SDK Setup ==="
|
7
7
|
puts
|
@@ -106,7 +106,7 @@ puts "-" * 40
|
|
106
106
|
begin
|
107
107
|
# Initialize client based on configured environment
|
108
108
|
if ENV['KAPSO_API_KEY']
|
109
|
-
client =
|
109
|
+
client = KapsoClientRuby::Client.new(
|
110
110
|
kapso_api_key: ENV['KAPSO_API_KEY'],
|
111
111
|
base_url: 'https://app.kapso.ai/api/meta',
|
112
112
|
debug: true
|
@@ -114,7 +114,7 @@ begin
|
|
114
114
|
puts "✅ Kapso client initialized"
|
115
115
|
puts " Kapso proxy: #{client.kapso_proxy?}"
|
116
116
|
else
|
117
|
-
client =
|
117
|
+
client = KapsoClientRuby::Client.new(
|
118
118
|
access_token: ENV['WHATSAPP_ACCESS_TOKEN'],
|
119
119
|
debug: true
|
120
120
|
)
|
@@ -135,7 +135,7 @@ puts "2. Testing Resource Access"
|
|
135
135
|
puts "-" * 40
|
136
136
|
|
137
137
|
begin
|
138
|
-
client =
|
138
|
+
client = KapsoClientRuby::Client.new(access_token: 'test_token')
|
139
139
|
|
140
140
|
# Test all resource accessors
|
141
141
|
resources = {
|
@@ -168,16 +168,16 @@ puts "-" * 40
|
|
168
168
|
|
169
169
|
begin
|
170
170
|
# Test global configuration
|
171
|
-
|
171
|
+
KapsoClientRuby.configure do |config|
|
172
172
|
config.debug = true
|
173
173
|
config.timeout = 45
|
174
174
|
config.access_token = 'global_test_token'
|
175
175
|
end
|
176
176
|
|
177
177
|
puts "✅ Global configuration set"
|
178
|
-
puts " Debug: #{
|
179
|
-
puts " Timeout: #{
|
180
|
-
puts " Access token present: #{!
|
178
|
+
puts " Debug: #{KapsoClientRuby.configuration.debug}"
|
179
|
+
puts " Timeout: #{KapsoClientRuby.configuration.timeout}"
|
180
|
+
puts " Access token present: #{!KapsoClientRuby.configuration.access_token.nil?}"
|
181
181
|
|
182
182
|
rescue => e
|
183
183
|
puts "❌ Configuration failed: #{e.message}"
|
@@ -191,7 +191,7 @@ puts "-" * 40
|
|
191
191
|
|
192
192
|
begin
|
193
193
|
# Test creating different error types
|
194
|
-
rate_limit_error =
|
194
|
+
rate_limit_error = KapsoClientRuby::Errors::GraphApiError.new(
|
195
195
|
message: 'Rate limit exceeded',
|
196
196
|
code: 4,
|
197
197
|
http_status: 429,
|
@@ -204,7 +204,7 @@ begin
|
|
204
204
|
puts " Retry after: #{rate_limit_error.retry_after}s"
|
205
205
|
puts " Retry hint: #{rate_limit_error.retry_hint}"
|
206
206
|
|
207
|
-
auth_error =
|
207
|
+
auth_error = KapsoClientRuby::Errors::GraphApiError.new(
|
208
208
|
message: 'Invalid access token',
|
209
209
|
code: 190,
|
210
210
|
http_status: 401
|
@@ -234,11 +234,11 @@ begin
|
|
234
234
|
puts " Available methods: send_text, send_image, send_template, etc."
|
235
235
|
|
236
236
|
# Test media types validation
|
237
|
-
media_types =
|
237
|
+
media_types = KapsoClientRuby::Types::MEDIA_TYPES
|
238
238
|
puts "✅ Media types supported: #{media_types.join(', ')}"
|
239
239
|
|
240
240
|
# Test template statuses
|
241
|
-
template_statuses =
|
241
|
+
template_statuses = KapsoClientRuby::Types::TEMPLATE_STATUSES
|
242
242
|
puts "✅ Template statuses: #{template_statuses.join(', ')}"
|
243
243
|
|
244
244
|
rescue => e
|
@@ -252,12 +252,12 @@ puts "6. Testing Logger System"
|
|
252
252
|
puts "-" * 40
|
253
253
|
|
254
254
|
begin
|
255
|
-
logger =
|
255
|
+
logger = KapsoClientRuby.logger
|
256
256
|
puts "✅ Logger accessible"
|
257
257
|
puts " Logger class: #{logger.class}"
|
258
258
|
|
259
259
|
# Test logging (will show in console if debug enabled)
|
260
|
-
|
260
|
+
KapsoClientRuby.logger.info("SDK test completed successfully!")
|
261
261
|
|
262
262
|
rescue => e
|
263
263
|
puts "❌ Logger test failed: #{e.message}"
|
@@ -310,7 +310,7 @@ if test_real_api
|
|
310
310
|
puts " Message Status: #{response.messages.first.message_status}"
|
311
311
|
end
|
312
312
|
|
313
|
-
rescue
|
313
|
+
rescue KapsoClientRuby::Errors::GraphApiError => e
|
314
314
|
puts "❌ API Error: #{e.message}"
|
315
315
|
puts " Category: #{e.category}"
|
316
316
|
puts " HTTP Status: #{e.http_status}"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kapso-client-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PabloB07
|
@@ -203,6 +203,7 @@ files:
|
|
203
203
|
- ".rubocop.yml"
|
204
204
|
- CHANGELOG.md
|
205
205
|
- Gemfile
|
206
|
+
- RAILS_INTEGRATION.md
|
206
207
|
- README.md
|
207
208
|
- Rakefile
|
208
209
|
- TEMPLATE_TOOLS_GUIDE.md
|
@@ -210,10 +211,21 @@ files:
|
|
210
211
|
- examples/advanced_features.rb
|
211
212
|
- examples/basic_messaging.rb
|
212
213
|
- examples/media_management.rb
|
214
|
+
- examples/rails/jobs.rb
|
215
|
+
- examples/rails/models.rb
|
216
|
+
- examples/rails/notifications_controller.rb
|
213
217
|
- examples/template_management.rb
|
214
218
|
- lib/kapso_client_ruby.rb
|
215
219
|
- lib/kapso_client_ruby/client.rb
|
216
220
|
- lib/kapso_client_ruby/errors.rb
|
221
|
+
- lib/kapso_client_ruby/rails/generators/install_generator.rb
|
222
|
+
- lib/kapso_client_ruby/rails/generators/templates/env.erb
|
223
|
+
- lib/kapso_client_ruby/rails/generators/templates/initializer.rb.erb
|
224
|
+
- lib/kapso_client_ruby/rails/generators/templates/message_service.rb.erb
|
225
|
+
- lib/kapso_client_ruby/rails/generators/templates/webhook_controller.rb.erb
|
226
|
+
- lib/kapso_client_ruby/rails/railtie.rb
|
227
|
+
- lib/kapso_client_ruby/rails/service.rb
|
228
|
+
- lib/kapso_client_ruby/rails/tasks.rake
|
217
229
|
- lib/kapso_client_ruby/resources/calls.rb
|
218
230
|
- lib/kapso_client_ruby/resources/contacts.rb
|
219
231
|
- lib/kapso_client_ruby/resources/conversations.rb
|