Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.8
3.1.6
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ gemspec
gem "rake", "~> 13.0"

gem "rspec", "~> 3.0"

gem "webmock", "~> 3.25"

gem "pry", "~> 0.15.2"
104 changes: 82 additions & 22 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,84 @@ PATH
remote: .
specs:
site_impact (0.1.0)
savon (~> 2.12.1)
httparty (~> 0.21.0)
savon (~> 2.15.1)

GEM
remote: https://rubygems.org/
specs:
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
akami (1.3.2)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
akami (1.3.3)
base64
gyoku (>= 0.4.0)
nokogiri
builder (3.2.4)
base64 (0.2.0)
bigdecimal (3.1.9)
builder (3.3.0)
coderay (1.1.3)
crack (1.0.0)
bigdecimal
rexml
date (3.4.1)
diff-lcs (1.5.0)
faraday (2.13.1)
faraday-net_http (>= 2.0, < 3.5)
json
logger
faraday-net_http (3.4.0)
net-http (>= 0.5.0)
gyoku (1.4.0)
builder (>= 2.1.2)
rexml (~> 3.0)
httpi (2.5.0)
rack
socksify
nokogiri (1.15.5-x86_64-darwin)
hashdiff (1.1.2)
httparty (0.21.0)
mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2)
httpi (4.0.4)
base64
mutex_m
nkf
rack (>= 2.0, < 4)
json (2.11.3)
logger (1.7.0)
mail (2.8.1)
mini_mime (>= 0.1.1)
net-imap
net-pop
net-smtp
method_source (1.1.0)
mini_mime (1.1.5)
mini_portile2 (2.8.8)
multi_xml (0.6.0)
mutex_m (0.3.0)
net-http (0.6.0)
uri
net-imap (0.5.8)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.2)
timeout
net-smtp (0.5.1)
net-protocol
nkf (0.2.0)
nokogiri (1.18.8)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nori (2.6.0)
public_suffix (5.0.4)
racc (1.7.3)
rack (3.0.8)
nokogiri (1.18.8-x86_64-darwin)
racc (~> 1.4)
nori (2.7.1)
bigdecimal
pry (0.15.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (6.0.2)
racc (1.8.1)
rack (3.1.14)
rake (13.0.6)
rexml (3.2.6)
rexml (3.4.1)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
Expand All @@ -41,29 +93,37 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.3)
savon (2.12.1)
savon (2.15.1)
akami (~> 1.2)
builder (>= 2.1.2)
gyoku (~> 1.2)
httpi (~> 2.3)
httpi (>= 4, < 5)
mail (~> 2.5)
nokogiri (>= 1.8.1)
nori (~> 2.4)
wasabi (~> 3.4)
socksify (1.7.1)
wasabi (3.7.0)
wasabi (>= 3.7, < 6)
timeout (0.4.3)
uri (1.0.3)
wasabi (5.1.0)
addressable
httpi (~> 2.0)
nokogiri (>= 1.4.2)
faraday (>= 1.9, < 3)
nokogiri (>= 1.13.9)
webmock (3.25.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)

PLATFORMS
ruby
x86_64-darwin-22

DEPENDENCIES
bundler (~> 2.0)
pry (~> 0.15.2)
rake (~> 13.0)
rspec (~> 3.0)
site_impact!
webmock (~> 3.25)

BUNDLED WITH
2.4.18
2.4.22
2 changes: 1 addition & 1 deletion site_impact.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

# Uncomment to register a new dependency of your gem
spec.add_runtime_dependency 'savon', '~> 2.12.1'
spec.add_runtime_dependency 'savon', '~> 2.15.1'
spec.add_runtime_dependency 'httparty', '~> 0.21.0'
spec.add_development_dependency "bundler", "~> 2.0"

Expand Down
74 changes: 74 additions & 0 deletions spec/client/reports_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
require "spec_helper"

RSpec.describe SiteImpact::Report do
let(:report_endpoint) {
"https://ecampaignstats.com/cp/index.php/report_api/"
}
let(:get_client_report_response) do
<<~XML
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<get_client_report_response xmlns="https://ecampaignstats.com/cp/index.php/report_api/">
<get_client_report_result>
<ds>
<diffgram>
<new_data_set>
<table>
<campaign_x0020_id>12345</campaign_x0020_id>
<opens>100</opens>
<clicks>50</clicks>
<broadcast_x0020_date>2023-01-01T00:00:00Z</broadcast_x0020_date>
</table>
</new_data_set>
</diffgram>
</ds>
</get_client_report_result>
</get_client_report_response>
</soap:Body>
</soap:Envelope>
XML
end

let(:client) { described_class }
let(:from) { Time.parse("2023-01-01") }

before do
stub_request(:get, SiteImpact.reports_base_url)
.to_return(
status: 200,
headers: { 'Content-Type' => 'text/xml' },
body: File.read("spec/fixtures/service.wsdl")
)

stub_request(:post, report_endpoint).
with(
headers: {
'Soapaction'=>'"https://ecampaignstats.com/cp/index.php/report_api/GetClientReport"',
}).
to_return(status: 200, body: get_client_report_response, headers: {})
end

describe "#get_client_report" do
context "when a valid response is returned" do
it "returns the response body" do
result = client.get_client_report(from)
expect(result).to_not be_nil
end
end

context "when the response is empty" do
before do
stub_request(:post, report_endpoint).
with(
headers: {
'Soapaction'=>'"https://ecampaignstats.com/cp/index.php/report_api/GetClientReport"',
}).
to_return(status: 200, body: nil, headers: {})
end

it "raises an error" do
expect { client.get_client_report(from) }.to raise_error(Savon::InvalidResponseError)
end
end
end
end
Loading