Skip to content

Commit

Permalink
Merge pull request mailjet#206 from mailjet/DE-38
Browse files Browse the repository at this point in the history
DE-38 Statcounters resource
  • Loading branch information
xab3r authored Jan 6, 2021
2 parents 539234b + a107573 commit 0fbc57e
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ RSpec::Core::RakeTask.new(:spec) do |t|
"spec/resources/template_detailcontent_spec.rb",
"spec/resources/integration_spec.rb",
"spec/resources/newsletter_spec.rb",
"spec/resources/statcounters_spec.rb",
]
end

Expand Down
33 changes: 33 additions & 0 deletions lib/mailjet/resources/statcounters.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Mailjet
class Statcounters
include Mailjet::Resource
self.resource_path = 'REST/statcounters'
self.public_operations = [:get]
self.filters = [:source_id, :counter_resolution, :counter_source, :counter_timing]
self.resourceprop = [
:api_key_id,
:event_click_delay,
:event_clicked_count,
:event_open_delay,
:event_opened_count,
:event_spam_count,
:event_unsubscribed_count,
:event_workflow_exited_count,
:message_blocked_count,
:message_clicked_count,
:message_deferred_count,
:message_hard_bounced_count,
:message_opened_count,
:message_queued_count,
:message_sent_count,
:message_soft_bounced_count,
:message_spam_count,
:message_unsubscribed_count,
:message_work_flow_exited_count,
:source_id,
:timeslice,
:total,
]
self.read_only = true
end
end
45 changes: 45 additions & 0 deletions spec/cassettes/Mailjet_Statcounters/_all/returns_all_records.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions spec/resources/statcounters_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require "mailjet_spec_helper"

RSpec.describe Mailjet::Statcounters, :vcr do
describe ".all" do
before { Mailjet.config.api_version = "v3" }

it "returns all records" do
res = described_class.all(
source_id: 52387,
counter_source: "Sender",
counter_timing: "Message",
counter_resolution: "Lifetime"
)

expect(res.count).to eq 1
expect(res.first.attributes).to eq({
"persisted" => true,
"api_key_id" => 1404561,
"event_click_delay" => 0,
"event_clicked_count" => 0,
"event_open_delay" => 31806,
"event_opened_count" => 36,
"event_spam_count" => 0,
"event_unsubscribed_count" => 0,
"event_workflow_exited_count" => 0,
"message_blocked_count" => 10,
"message_clicked_count" => 0,
"message_deferred_count" => 0,
"message_hard_bounced_count" => 0,
"message_opened_count" => 12,
"message_queued_count" => 0,
"message_sent_count" => 44,
"message_soft_bounced_count" => 0,
"message_spam_count" => 0,
"message_unsubscribed_count" => 0,
"message_work_flow_exited_count" => 0,
"source_id" => 52387,
"timeslice" => "",
"total" => 54
})
end
end
end

0 comments on commit 0fbc57e

Please sign in to comment.