สำหรับข้อมูลเพิ่มเติมเกี่ยวกับ MailerLite API โปรดไปที่ลิงก์ต่อไปนี้:
คีย์ API เป็นวิธีที่รวดเร็วในการใช้การตรวจสอบสิทธิ์แบบเครื่องต่อเครื่องโดยไม่ต้องป้อนข้อมูลโดยตรงจากมนุษย์นอกเหนือจากการตั้งค่าเริ่มต้น
สำหรับข้อมูลเพิ่มเติมเกี่ยวกับวิธีรับคีย์ API โปรดไปที่ลิงก์ต่อไปนี้
gem install mailerlite-ruby
คุณจะต้องเริ่มต้นมันในไฟล์ Ruby ของคุณด้วย require "mailerlite-ruby"
SDK นี้กำหนดให้คุณต้องมีไฟล์ .env
ที่มีตัวแปร env MAILERLITE_API_TOKEN
หรือตัวแปรของคุณเปิดใช้งานทั่วทั้งระบบ (มีประโยชน์สำหรับ Docker/Kubernetes) ตัวอย่างของ MAILERLITE_API_TOKEN
ควรมีลักษณะอย่างไรอยู่ใน . .env.example
require "mailerlite-ruby"
# Intialize the class
subscribers = MailerLite :: Subscribers . new
subscribers . fetch ( filter : { status : 'active' } )
require "mailerlite-ruby"
# Intialize the class
subscribers = MailerLite :: Subscribers . new
subscribers . create ( email : '[email protected]' , fields : { 'name' : 'John' , 'last_name' : 'Doe' } , ip_address : '1.2.3.4' , optin_ip : '1.2.3.4' )
require "mailerlite-ruby"
# Intialize the class
subscribers = MailerLite :: Subscribers . new
subscribers . update ( email : '[email protected]' , fields : { 'name' : 'John' , 'last_name' : 'Doe' } , ip_address : '1.2.3.4' , optin_ip : '1.2.3.4' )
require "mailerlite-ruby"
# Intialize the class
subscribers = MailerLite :: Subscribers . new
subscribers . get ( '[email protected]' )
require "mailerlite-ruby"
# Intialize the class
subscribers = MailerLite :: Subscribers . new
subscriber_id = 1234567890
subscribers . delete ( subscriber_id )
require "mailerlite-ruby"
# Intialize the class
groups = MailerLite :: Groups . new
groups . list ( limit : 10 , page : 1 , filter : { 'name' : 'My' } , sort : 'name' )
require "mailerlite-ruby"
# Intialize the class
groups = MailerLite :: Groups . new
groups . create ( name : 'Group Name' )
require "mailerlite-ruby"
# Intialize the class
groups = MailerLite :: Groups . new
groups . update ( group_id : 1234567 , name : 'My New Group' )
require "mailerlite-ruby"
# Intialize the class
groups = MailerLite :: Groups . new
group_id = 1234567
groups . delete ( group_id )
require "mailerlite-ruby"
# Intialize the class
groups = MailerLite :: Groups . new
groups . get_subscribers ( group_id : 1234567 , page : 1 , limit : 10 , filter : { 'status' : 'active' } )
require "mailerlite-ruby"
# Intialize the class
groups = MailerLite :: Groups . new
groups . assign_subscriber ( subscriber : 111222 , group_id : 1234567 )
require "mailerlite-ruby"
# Intialize the class
groups = MailerLite :: Groups . new
groups . unassign_subscriber ( subscriber : 111222 , group_id : 1234567 )
require "mailerlite-ruby"
# Intialize the class
segments = MailerLite :: Segments . new
segments . list ( limit : 10 , page : 1 )
require "mailerlite-ruby"
# Intialize the class
segments = MailerLite :: Segments . new
segments . update ( segment_id : 123456 , name : 'My New Segment Name' )
require "mailerlite-ruby"
# Intialize the class
segments = MailerLite :: Segments . new
segment_id = 123456
segments . delete ( segment_id )
require "mailerlite-ruby"
# Intialize the class
segments = MailerLite :: Segments . new
segments . get_subscribers ( segment_id : 123456 , limit : 10 , filter : { 'status' : 'active' } )
require "mailerlite-ruby"
# Intialize the class
fields = MailerLite :: Fields . new
fields . get ( limit : 10 , page : 1 , sort : 'name' , filter : { 'keyword' : 'abc' , 'type' : 'text' } )
require "mailerlite-ruby"
# Intialize the class
fields = MailerLite :: Fields . new
fields . create ( name : 'My Field' , type : 'text' )
require "mailerlite-ruby"
# Intialize the class
fields = MailerLite :: Fields . new
fields . update ( field_id : 123345 , name : 'My New Field' )
require "mailerlite-ruby"
# Intialize the class
fields = MailerLite :: Fields . new
field_id = 123456
fields . delete ( field_id )
require "mailerlite-ruby"
# Intialize the class
automations = MailerLite :: Automations . new
automations . get ( limit : 10 , page : 1 , filter : { 'status' : true , 'name' : 'some name' , 'group' : 123456 } )
require "mailerlite-ruby"
# Intialize the class
automations = MailerLite :: Automations . new
automation_id = 123456
automations . fetch ( automation_id )
require "mailerlite-ruby"
# Intialize the class
automations = MailerLite :: Automations . new
automations . get_subscriber_activity ( automation_id : 123456 , page : 1 , limit : 10 , filter : { 'status' : 'active' , 'date_from' : '2022-12-20' , 'date_to' : '2022-12-31' } )
require "mailerlite-ruby"
# Intialize the class
campaigns = MailerLite :: Campaigns . new
campaigns . get ( limit : 10 , page : 1 , filter : { 'status' : 'ready' , 'type' : 'regular' } )
require "mailerlite-ruby"
# Intialize the class
campaigns = MailerLite :: Campaigns . new
campaigns . fetch ( campaign_id : 123456 )
require "mailerlite-ruby"
# Intialize the class
campaigns = MailerLite :: Campaigns . new
campaigns . create (
name : "Test Campaign" ,
language_id : 1 ,
type : "regular" ,
emails : [ {
"subject" : "This is a test campaign" ,
"from_name" : "Test Man" ,
"from" : "[email protected]" ,
"content" : "Hi there, this is a test campaign!"
} ]
)
require "mailerlite-ruby"
# Intialize the class
campaigns = MailerLite :: Campaigns . new
campaigns . update (
campaign_id : 1233455 ,
name : "New Campaign Name" ,
language_id : 2 ,
emails : [ {
"subject" : "This is a test campaign" ,
"from_name" : "Test Man" ,
"from" : "[email protected]" ,
"content" : "Hi there, this is a test campaign!"
} ]
)
require "mailerlite-ruby"
# Intialize the class
campaigns = MailerLite :: Campaigns . new
campaigns . schedule (
campaign_id : 123456 ,
delivery : "scheduled" ,
schedule : {
"date" : "2022-12-31" ,
"hours" : "22" ,
"minutes" : "00"
}
)
require "mailerlite-ruby"
# Intialize the class
campaigns = MailerLite :: Campaigns . new
campaign_id = 123456
campaigns . cancel ( campaign_id )
require "mailerlite-ruby"
# Intialize the class
campaigns = MailerLite :: Campaigns . new
campaign_id = 123456
campaigns . delete ( campaign_id )
require "mailerlite-ruby"
# Intialize the class
campaigns = MailerLite :: Campaigns . new
campaign_id = 123456
campaigns . activity ( campaign_id )
require "mailerlite-ruby"
# Intialize the class
forms = MailerLite :: Forms . new
forms . list ( limit : 10 , page : 1 , sort : 'name' , filter : { 'name' : 'form name' } )
require "mailerlite-ruby"
# Intialize the class
forms = MailerLite :: Forms . new
form_id = 123456
forms . fetch ( form_id )
require "mailerlite-ruby"
# Intialize the class
forms = MailerLite :: Forms . new
forms . update ( form_id : 123456 , name : 'My form Name' )
require "mailerlite-ruby"
# Intialize the class
forms = MailerLite :: Forms . new
form_id = 123456
forms . delete ( form_id )
require "mailerlite-ruby"
# Intialize the class
forms = MailerLite :: Forms . new
forms . fetch_subscribers ( form_id : 123345 , page : 1 , limit : 10 , filter : { 'status' : 'active' } )
require "mailerlite-ruby"
# Intialize the class
batch = MailerLite :: Batch . new
batch . request (
requests : [
{ method : 'GET' , path : 'api/subscribers/list' } ,
{ method : 'GET' , path : 'api/campaigns/list' }
]
)
require "mailerlite-ruby"
# Intialize the class
subscribers = MailerLite :: Subscribers . new
webhooks . list ( )
require "mailerlite-ruby"
# Intialize the class
subscribers = MailerLite :: Subscribers . new
webhook_id = 123456
webhooks . get ( webhook_id )
require "mailerlite-ruby"
# Intialize the class
webhooks = MailerLite :: Webhooks . new
webhooks . create (
events : [
'subscriber.created' ,
'subscriber.updated' ,
'subscriber.unsubscribed'
] ,
url : 'https://my-url.com' ,
name : 'Webhook name'
)
require "mailerlite-ruby"
# Intialize the class
webhooks = MailerLite :: Webhooks . new
webhooks . update (
webhook_id : 123456 ,
events : [
'subscriber.created' ,
'subscriber.updated' ,
'subscriber.unsubscribed'
] ,
url : 'https://my-url.com' ,
name : 'Webhook name' ,
enabled : false
)
require "mailerlite-ruby"
# Intialize the class
webhooks = MailerLite :: Webhooks . new
webhook_id = 123456
webhooks . delete ( webhook_id )
require "mailerlite-ruby"
# Intialize the class
timezones = MailerLite :: Timezones . new
timezones . list ( )
require "mailerlite-ruby"
# Intialize the class
campaigns = MailerLite :: Campaigns . new
campaigns . languages ( )
bundle i
bundle exec rspec spec/ * rspec.rb
หากต้องการรันการทดสอบ คุณจะต้องติดตั้ง Gem โดยใช้บันเดิล จากนั้นรัน rspec ผ่านบันเดิลเพื่อรันการทดสอบทั้งหมด ฟิกซ์เจอร์สำหรับการทดสอบได้รับการบันทึกโดยใช้ vcr และมีอยู่ในไดเร็กทอรี ./fixtures
bundle i
bundle exec yardoc ' lib/**/*.rb '
สิ่งนี้จะสร้างเอกสาร html ในไดเร็กทอรี doc ซึ่งสามารถเปิดได้ในเบราว์เซอร์ใดก็ได้ ไปที่ index.html แล้วเปิดขึ้นมา