diff --git a/.ruby-version b/.ruby-version
index 6a81b4c..8a4b275 100644
--- a/.ruby-version
+++ b/.ruby-version
@@ -1 +1 @@
-2.7.8
+3.1.6
\ No newline at end of file
diff --git a/Gemfile b/Gemfile
index 2957e63..d553d81 100644
--- a/Gemfile
+++ b/Gemfile
@@ -8,3 +8,7 @@ gemspec
gem "rake", "~> 13.0"
gem "rspec", "~> 3.0"
+
+gem "webmock", "~> 3.25"
+
+gem "pry", "~> 0.15.2"
diff --git a/Gemfile.lock b/Gemfile.lock
index fa53b34..11bc58f 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -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)
@@ -41,19 +93,25 @@ 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
@@ -61,9 +119,11 @@ PLATFORMS
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
diff --git a/site_impact.gemspec b/site_impact.gemspec
index aa1d278..0b10945 100644
--- a/site_impact.gemspec
+++ b/site_impact.gemspec
@@ -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"
diff --git a/spec/client/reports_spec.rb b/spec/client/reports_spec.rb
new file mode 100644
index 0000000..acd24a4
--- /dev/null
+++ b/spec/client/reports_spec.rb
@@ -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
+
+
+
+
+
+
+
+
+ 12345
+ 100
+ 50
+ 2023-01-01T00:00:00Z
+
+
+
+
+
+
+
+
+ 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
diff --git a/spec/fixtures/service.wsdl b/spec/fixtures/service.wsdl
new file mode 100644
index 0000000..d307365
--- /dev/null
+++ b/spec/fixtures/service.wsdl
@@ -0,0 +1,168 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Retreive Client's Report Info
+
+
+
+
+ Retreive Link SummaryReport Info
+
+
+
+
+ Retreive Link Report Info
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index d6579b8..5de01a1 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
require "site_impact"
+require "webmock/rspec"
+WebMock.disable_net_connect!(allow_localhost: true)
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure