pew_pew 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/build.yml +36 -0
- data/.gitignore +1 -0
- data/.rspec +1 -2
- data/Appraisals +7 -0
- data/CHANGELOG.md +7 -2
- data/README.md +6 -0
- data/gemfiles/faraday_2.0.gemfile +7 -0
- data/gemfiles/faraday_2.7.gemfile +7 -0
- data/lib/pew_pew/resource.rb +12 -10
- data/lib/pew_pew/version.rb +1 -1
- data/pew_pew.gemspec +20 -16
- data/spec/fixtures/messages.yml +153 -111
- data/spec/pew_pew/client_spec.rb +47 -39
- data/spec/pew_pew/config_spec.rb +28 -28
- data/spec/pew_pew/resource_spec.rb +42 -36
- data/spec/pew_pew/resources/bounces_spec.rb +57 -53
- data/spec/pew_pew/resources/campaigns_spec.rb +169 -167
- data/spec/pew_pew/resources/complaints_spec.rb +49 -45
- data/spec/pew_pew/resources/lists_spec.rb +209 -195
- data/spec/pew_pew/resources/logs_spec.rb +30 -25
- data/spec/pew_pew/resources/mailboxes_spec.rb +41 -39
- data/spec/pew_pew/resources/messages_spec.rb +49 -45
- data/spec/pew_pew/resources/routes_spec.rb +105 -103
- data/spec/pew_pew/resources/stats_spec.rb +19 -17
- data/spec/pew_pew/resources/unsubscribes_spec.rb +71 -65
- data/spec/pew_pew/response_spec.rb +25 -13
- data/spec/pew_pew_spec.rb +4 -5
- data/spec/spec_helper.rb +1 -1
- data/spec/support/contexts/api_requests.rb +5 -3
- data/spec/support/contexts/domain_resource.rb +1 -1
- data/spec/support/vcr.rb +36 -1
- metadata +84 -50
data/spec/pew_pew/config_spec.rb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
|
1
|
+
module PewPew
|
2
|
+
RSpec.describe Config do
|
3
|
+
{
|
4
|
+
BASE_URI: 'https://api.mailgun.net/v2',
|
5
|
+
USER_AGENT: "PewPew Ruby Gem #{VERSION}",
|
6
|
+
USERNAME: 'api'
|
7
|
+
}.each do |constant, value|
|
8
|
+
context "::#{constant}" do
|
9
|
+
subject { described_class.const_get(constant) }
|
2
10
|
|
3
|
-
|
4
|
-
|
5
|
-
BASE_URI: 'https://api.mailgun.net/v2',
|
6
|
-
USER_AGENT: "PewPew Ruby Gem #{PewPew::VERSION}",
|
7
|
-
USERNAME: 'api'
|
8
|
-
}.each do |constant, value|
|
9
|
-
context constant do
|
10
|
-
subject { described_class.const_get(constant) }
|
11
|
-
|
12
|
-
it { should == value }
|
11
|
+
it { should == value }
|
12
|
+
end
|
13
13
|
end
|
14
|
-
end
|
15
14
|
|
16
|
-
|
15
|
+
subject(:config) { Class.new { include Config }.new }
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
context 'defaults' do
|
18
|
+
its(:api_key) { should be_nil }
|
19
|
+
its(:domain) { should be_nil }
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
context '#api_key=' do
|
23
|
+
specify do
|
24
|
+
expect { config.api_key = 'key-02n9f3ijl9sm9u97-8p7r-d7-15q-ui1' }
|
25
|
+
.to change(config, :api_key)
|
26
|
+
.to('key-02n9f3ijl9sm9u97-8p7r-d7-15q-ui1')
|
27
|
+
end
|
28
28
|
end
|
29
|
-
end
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
context '#domain=' do
|
31
|
+
specify do
|
32
|
+
expect {
|
33
|
+
config.domain = 'pewpew.mailgun.org'
|
34
|
+
}.to change(config, :domain).to('pewpew.mailgun.org')
|
35
|
+
end
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -1,46 +1,52 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
1
|
+
module PewPew
|
2
|
+
RSpec.describe Resource do
|
3
|
+
let(:client) { Client.new }
|
4
|
+
|
5
|
+
subject(:resource) { Class.new { include Resource }.new(client) }
|
6
|
+
|
7
|
+
context '#connection' do
|
8
|
+
let(:connection) { resource.send(:connection) }
|
9
|
+
|
10
|
+
context 'middleware' do
|
11
|
+
let(:handlers) { connection.builder.handlers }
|
12
|
+
|
13
|
+
[
|
14
|
+
Resource::ResponseDecorator,
|
15
|
+
Faraday::Mashify::Middleware,
|
16
|
+
Faraday::Response::Json,
|
17
|
+
Faraday::Multipart::Middleware,
|
18
|
+
Faraday::Request::UrlEncoded
|
19
|
+
].each.with_index do |middleware, index|
|
20
|
+
it "uses #{middleware}" do
|
21
|
+
expect(handlers.index(middleware)).to eq index
|
22
|
+
end
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
|
-
end
|
28
27
|
|
29
|
-
describe
|
30
|
-
|
28
|
+
RSpec.describe Resource::ResponseDecorator do
|
29
|
+
subject(:middleware) { described_class.new }
|
31
30
|
|
32
|
-
|
33
|
-
env = { body: [:response] }
|
34
|
-
subject.on_complete(env)
|
35
|
-
env[:body].total_count.should == 1
|
36
|
-
env[:body].items.should == [:response]
|
37
|
-
end
|
31
|
+
it { is_expected.to be_a Faraday::Middleware }
|
38
32
|
|
39
|
-
|
40
|
-
|
33
|
+
it 'converts an array response into a mash' do
|
34
|
+
env = { body: [:response] }
|
41
35
|
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
middleware.on_complete env
|
37
|
+
|
38
|
+
expect(env).to match a_hash_including(
|
39
|
+
body: an_object_having_attributes(total_count: 1, items: [:response])
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'stores the request status on the response body' do
|
44
|
+
env = { body: Response.new, status: 200 }
|
45
|
+
|
46
|
+
expect { middleware.on_complete env }
|
47
|
+
.to change(env[:body], :status)
|
48
|
+
.from(nil)
|
49
|
+
.to(200)
|
50
|
+
end
|
45
51
|
end
|
46
52
|
end
|
@@ -1,78 +1,82 @@
|
|
1
|
-
|
1
|
+
module PewPew
|
2
|
+
module Resources
|
3
|
+
RSpec.describe Bounces, :resource, :domain do
|
4
|
+
let(:resource) { described_class.new(client) }
|
2
5
|
|
3
|
-
|
4
|
-
|
6
|
+
context '#all' do
|
7
|
+
let(:response) { resource.all }
|
5
8
|
|
6
|
-
|
7
|
-
let(:response) { resource.all }
|
9
|
+
subject { response }
|
8
10
|
|
9
|
-
|
11
|
+
specify { should be_success }
|
10
12
|
|
11
|
-
|
13
|
+
its(:status) { should == 200 }
|
14
|
+
its(:total_count) { should == 1 }
|
12
15
|
|
13
|
-
|
14
|
-
|
16
|
+
context 'item' do
|
17
|
+
subject { response.items.first }
|
15
18
|
|
16
|
-
|
17
|
-
|
19
|
+
its(:address) { should == 'test@example.com' }
|
20
|
+
its(:code) { should == '554' }
|
21
|
+
its(:error) { should == 'Relay access denied' }
|
22
|
+
its(:created_at) { should == 'Sat, 02 Jun 2012 07:24:08 GMT' }
|
23
|
+
end
|
24
|
+
end
|
18
25
|
|
19
|
-
|
20
|
-
|
21
|
-
its(:error) { should == 'Relay access denied' }
|
22
|
-
its(:created_at) { should == 'Sat, 02 Jun 2012 07:24:08 GMT' }
|
23
|
-
end
|
24
|
-
end
|
26
|
+
context '#find' do
|
27
|
+
let(:response) { resource.find('test@example.com') }
|
25
28
|
|
26
|
-
|
27
|
-
let(:response) { resource.find('test@example.com') }
|
29
|
+
subject { response }
|
28
30
|
|
29
|
-
|
31
|
+
specify { should be_success }
|
30
32
|
|
31
|
-
|
33
|
+
its(:status) { should == 200 }
|
32
34
|
|
33
|
-
|
35
|
+
context 'bounce' do
|
36
|
+
subject { response.bounce }
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
its(:created_at) { should == 'Sat, 02 Jun 2012 07:24:08 GMT' }
|
42
|
-
end
|
43
|
-
end
|
38
|
+
its(:address) { should == 'test@example.com' }
|
39
|
+
its(:code) { should == '554' }
|
40
|
+
its(:error) { should == 'Relay access denied' }
|
41
|
+
its(:created_at) { should == 'Sat, 02 Jun 2012 07:24:08 GMT' }
|
42
|
+
end
|
43
|
+
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
context '#create' do
|
46
|
+
let(:params) do
|
47
|
+
{
|
48
|
+
address: 'test@example.com',
|
49
|
+
code: 554,
|
50
|
+
error: 'Relay access denied',
|
51
|
+
}
|
52
|
+
end
|
53
53
|
|
54
|
-
|
54
|
+
let(:response) { resource.create(params) }
|
55
55
|
|
56
|
-
|
56
|
+
subject { response }
|
57
57
|
|
58
|
-
|
58
|
+
specify { should be_success }
|
59
59
|
|
60
|
-
|
61
|
-
|
60
|
+
its(:status) { should == 200 }
|
61
|
+
its(:message) {
|
62
|
+
should == 'Address has been added to the bounces table'
|
63
|
+
}
|
62
64
|
|
63
|
-
|
64
|
-
|
65
|
+
its(:address) { should == 'test@example.com' }
|
66
|
+
end
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
+
context '#remove' do
|
69
|
+
subject { response }
|
68
70
|
|
69
|
-
|
71
|
+
let(:response) { resource.remove('test@example.com') }
|
70
72
|
|
71
|
-
|
73
|
+
specify { should be_success }
|
72
74
|
|
73
|
-
|
74
|
-
|
75
|
+
its(:status) { should == 200 }
|
76
|
+
its(:message) { should == 'Bounced address has been removed' }
|
75
77
|
|
76
|
-
|
78
|
+
its(:address) { should == 'test@example.com' }
|
79
|
+
end
|
80
|
+
end
|
77
81
|
end
|
78
82
|
end
|