Class: MessagebusReportsClient
Constant Summary
collapse
- FORMAT_JSON =
"json"
- FORMAT_CSV =
"csv"
- REPORT_TYPE_STATS =
"stats"
- REPORT_TYPE_FEEDBACK =
"feedback"
- REPORT_TYPE_BLOCKLIST =
"blocklist"
- SCOPE_BOUNCES =
"bounces"
- SCOPE_UNSUBSCRIBES =
"unsubscribes"
- SCOPE_COMPLAINTS =
"complaints"
- SCOPE_CLICKS =
"clicks"
- SCOPE_OPENS =
"opens"
- SCOPE_BLOCKS =
"blocks"
- STATUS_DONE =
"done"
- STATUS_RUNNING =
"running"
- STATUS_NODATA =
"nodata"
- STATUS_FAILED =
"failed"
MessagebusSDK::MessagebusBase::DEFAULT, MessagebusSDK::MessagebusBase::DEFAULT_API_ENDPOINT, MessagebusSDK::MessagebusBase::HEADER_SESSION_KEY, MessagebusSDK::MessagebusBase::HTTP_DELETE, MessagebusSDK::MessagebusBase::HTTP_GET, MessagebusSDK::MessagebusBase::HTTP_POST, MessagebusSDK::MessagebusBase::HTTP_PUT, MessagebusSDK::MessagebusBase::MAX_TEMPLATE_MESSAGES, MessagebusSDK::MessagebusBase::SCOPE_ALL, MessagebusSDK::MessagebusBase::TRUE_VALUE
Instance Method Summary
collapse
-
#create_blocklist_report(start_date, end_date, scope = 'blocks', format = 'json', channel_key = '', session_key = '') ⇒ Object
-
#create_feedback_report(start_date, end_date, scope = 'bounces', format = 'json', channel_key = '', session_key = '', use_send_time = true) ⇒ Object
-
#create_report(report_type, start_date, end_date, scope = nil, format = 'json', channel_key = '', session_key = '', use_send_time = true) ⇒ Object
-
#create_stats_report(start_date, end_date, format = 'json', channel_key = '', session_key = '') ⇒ Object
-
#initialize(api_key, api_endpoint = DEFAULT_API_ENDPOINT) ⇒ MessagebusReportsClient
constructor
A new instance of MessagebusReportsClient.
-
#report(report_key, file_name = '', sleep_interval = 5) ⇒ Object
-
#report_data(report_key, file_name = '') ⇒ Object
-
#report_status(report_key) ⇒ Object
#api_version, #cacert_info, #format_iso_time
Constructor Details
#initialize(api_key, api_endpoint = DEFAULT_API_ENDPOINT) ⇒ MessagebusReportsClient
Returns a new instance of MessagebusReportsClient.
37
38
39
40
|
# File 'lib/messagebus-sdk/reports_client.rb', line 37
def initialize(api_key, api_endpoint = DEFAULT_API_ENDPOINT)
super(api_key, api_endpoint)
@rest_endpoints = define_rest_endpoints
end
|
Instance Method Details
#create_blocklist_report(start_date, end_date, scope = 'blocks', format = 'json', channel_key = '', session_key = '') ⇒ Object
99
100
101
|
# File 'lib/messagebus-sdk/reports_client.rb', line 99
def create_blocklist_report(start_date, end_date, scope = 'blocks', format = 'json', channel_key = '', session_key = '')
create_report(REPORT_TYPE_BLOCKLIST, start_date, end_date, scope, format, channel_key, session_key)
end
|
#create_feedback_report(start_date, end_date, scope = 'bounces', format = 'json', channel_key = '', session_key = '', use_send_time = true) ⇒ Object
91
92
93
|
# File 'lib/messagebus-sdk/reports_client.rb', line 91
def create_feedback_report(start_date, end_date, scope = 'bounces', format = 'json', channel_key = '', session_key = '', use_send_time = true)
create_report(REPORT_TYPE_FEEDBACK, start_date, end_date, scope, format, channel_key, session_key, use_send_time)
end
|
#create_report(report_type, start_date, end_date, scope = nil, format = 'json', channel_key = '', session_key = '', use_send_time = true) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/messagebus-sdk/reports_client.rb', line 71
def create_report(report_type, start_date, end_date, scope = nil, format = 'json', channel_key = '', session_key = '', use_send_time = true)
path = @rest_endpoints[:reports]
days = 1
end_date = set_date(end_date, 0)
start_date = set_date(start_date, days)
post_data = {:reportType => report_type,
:format => format,
:startDate => start_date,
:endDate => end_date,
:channelKey => channel_key,
:sessionKey => session_key
}
post_data[:scope] = scope if (report_type == REPORT_TYPE_FEEDBACK || report_type == REPORT_TYPE_BLOCKLIST)
post_data[:useSendTime] = use_send_time if report_type == REPORT_TYPE_FEEDBACK
make_api_request(path, HTTP_POST, post_data.to_json)
end
|
#create_stats_report(start_date, end_date, format = 'json', channel_key = '', session_key = '') ⇒ Object
95
96
97
|
# File 'lib/messagebus-sdk/reports_client.rb', line 95
def create_stats_report(start_date, end_date, format = 'json', channel_key = '', session_key = '')
create_report(REPORT_TYPE_STATS, start_date, end_date, nil, format, channel_key, session_key)
end
|
#report(report_key, file_name = '', sleep_interval = 5) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/messagebus-sdk/reports_client.rb', line 52
def report(report_key, file_name = '', sleep_interval = 5)
report_data = ''
check_report_status = true
while check_report_status
response = report_status(report_key)
case response[:reportStatus]
when STATUS_DONE
report_data = report_data(report_key, file_name)
check_report_status = false
when STATUS_NODATA, STATUS_FAILED
report_data = ''
check_report_status = false
else
sleep(sleep_interval)
end
end
return report_data
end
|
#report_data(report_key, file_name = '') ⇒ Object
47
48
49
50
|
# File 'lib/messagebus-sdk/reports_client.rb', line 47
def report_data(report_key, file_name = '')
path = replace_report_key("#{@rest_endpoints[:report]}", report_key)
make_api_request(path, HTTP_GET, '', false, file_name)
end
|
#report_status(report_key) ⇒ Object
42
43
44
45
|
# File 'lib/messagebus-sdk/reports_client.rb', line 42
def report_status(report_key)
path = replace_report_key("#{@rest_endpoints[:status]}", report_key)
make_api_request(path)
end
|