-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
192 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,5 @@ end | |
|
||
group :test do | ||
gem "rspec" | ||
gem "webmock" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Vero | ||
class SenderLookup | ||
def [](key) | ||
klass_name = key.to_s.split("_").map(&:capitalize).join | ||
|
||
if Vero::Senders.const_defined?(klass_name) | ||
Vero::Senders.const_get(klass_name) | ||
else | ||
Vero::Senders::Base | ||
end | ||
end | ||
end | ||
|
||
class Sender | ||
def self.senders | ||
@senders ||= Vero::SenderLookup.new | ||
@senders ||= Vero::Sender::Lookup.new | ||
end | ||
|
||
def self.send(api_class, sender_strategy, domain, options) | ||
senders[sender_strategy].new.call(api_class, domain, options) | ||
def self.call(api_class, sender_strategy, domain, options) | ||
senders[sender_strategy] | ||
.new | ||
.call(api_class, domain, options) | ||
rescue => e | ||
options_s = JSON.dump(options) | ||
Vero::App.log(new, "method: #{api_class.name}, options: #{options_s}, error: #{e.message}") | ||
Vero::App.log(new, "method: #{api_class.name}, options: #{JSON.dump(options)}, error: #{e.message}") | ||
raise e | ||
end | ||
|
||
class Lookup | ||
def [](key) | ||
klass_name = key.to_s.split("_").map(&:capitalize).join | ||
|
||
if Vero::Senders.const_defined?(klass_name) | ||
Vero::Senders.const_get(klass_name) | ||
else | ||
Vero::Senders::Base | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
class Vero::Senders::Sidekiq | ||
def call(api_class, domain, options) | ||
response = ::Vero::SidekiqWorker.perform_async(api_class.to_s, domain, options) | ||
Vero::App.log(self, "method: #{api_class.name}, options: #{options.to_json}, response: sidekiq job queued") | ||
|
||
Vero::App.log(self, "method: #{api_class.name}, options: #{JSON.dump(options)}, response: sidekiq job queued") | ||
|
||
response | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,11 +47,18 @@ | |
end | ||
end | ||
|
||
describe :request do | ||
it "should send a JSON request to the Vero API" do | ||
expect(RestClient).to receive(:post).with("https://api.getvero.com/api/v2/events/track.json", {auth_token: "abcd", identity: {email: "[email protected]"}, event_name: "test_event"}.to_json, {content_type: :json, accept: :json}) | ||
allow(RestClient).to receive(:post).and_return(200) | ||
describe "request" do | ||
it "should send a request to the Vero API" do | ||
stub = stub_request(:post, "https://api.getvero.com/api/v2/events/track.json") | ||
.with( | ||
body: {auth_token: "abcd", identity: {email: "[email protected]"}, event_name: "test_event"}.to_json, | ||
headers: {"Content-Type" => "application/json", "Accept" => "application/json"} | ||
) | ||
.to_return(status: 200) | ||
|
||
subject.send(:request) | ||
|
||
expect(stub).to have_been_requested | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,17 +17,26 @@ | |
end | ||
end | ||
|
||
describe :request do | ||
describe "request" do | ||
it "should send a request to the Vero API" do | ||
expect(RestClient).to receive(:put).with("https://api.getvero.com/api/v2/users/edit.json", {auth_token: "abcd", email: "[email protected]", changes: {email: "[email protected]"}}.to_json, {content_type: :json, accept: :json}) | ||
allow(RestClient).to receive(:put).and_return(200) | ||
stub = stub_request(:put, "https://api.getvero.com/api/v2/users/edit.json") | ||
.with( | ||
body: {auth_token: "abcd", email: "[email protected]", changes: {email: "[email protected]"}}.to_json, | ||
headers: {"Content-Type" => "application/json", "Accept" => "application/json"} | ||
) | ||
.to_return(status: 200) | ||
|
||
subject.send(:request) | ||
|
||
expect(stub).to have_been_requested | ||
end | ||
end | ||
|
||
describe "integration test" do | ||
it "should not raise any errors" do | ||
allow(RestClient).to receive(:put).and_return(200) | ||
stub_request(:put, "https://api.getvero.com/api/v2/users/edit.json") | ||
.to_return(status: 200) | ||
|
||
expect { subject.perform }.to_not raise_error | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,17 +55,25 @@ | |
end | ||
end | ||
|
||
describe :request do | ||
describe "request" do | ||
it "should send a request to the Vero API" do | ||
expect(RestClient).to receive(:put).with("https://api.getvero.com/api/v2/users/tags/edit.json", {auth_token: "abcd", email: "[email protected]", add: ["test"]}.to_json, {content_type: :json, accept: :json}) | ||
allow(RestClient).to receive(:put).and_return(200) | ||
stub = stub_request(:put, "https://api.getvero.com/api/v2/users/tags/edit.json") | ||
.with( | ||
body: {auth_token: "abcd", email: "[email protected]", add: ["test"]}.to_json, | ||
headers: {"Content-Type" => "application/json", "Accept" => "application/json"} | ||
) | ||
.to_return(status: 200) | ||
|
||
subject.send(:request) | ||
|
||
expect(stub).to have_been_requested | ||
end | ||
end | ||
|
||
describe "integration test" do | ||
it "should not raise any errors" do | ||
allow(RestClient).to receive(:put).and_return(200) | ||
stub_request(:put, "https://api.getvero.com/api/v2/users/tags/edit.json") | ||
.to_return(status: 200) | ||
expect { subject.perform }.to_not raise_error | ||
end | ||
end | ||
|
Oops, something went wrong.