mailerlite-ruby 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/.env.example +1 -0
  3. data/.github/workflows/main.yml +17 -0
  4. data/.github/workflows/publish_gem.yml +21 -0
  5. data/.gitignore +60 -0
  6. data/.rspec +1 -0
  7. data/.rubocop.yml +36 -0
  8. data/CHANGELOG.md +1 -0
  9. data/Gemfile +4 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +801 -0
  12. data/Rakefile +8 -0
  13. data/bin/console +8 -0
  14. data/bin/setup +8 -0
  15. data/fixtures/automations/fetch.yml +61 -0
  16. data/fixtures/automations/get.yml +68 -0
  17. data/fixtures/automations/get_subscriber_activity.yml +71 -0
  18. data/fixtures/batch/request.yml +59 -0
  19. data/fixtures/campaigns/activity.yml +64 -0
  20. data/fixtures/campaigns/create.yml +65 -0
  21. data/fixtures/campaigns/delete.yml +53 -0
  22. data/fixtures/campaigns/fetch.yml +64 -0
  23. data/fixtures/campaigns/get.yml +68 -0
  24. data/fixtures/campaigns/languages.yml +60 -0
  25. data/fixtures/campaigns/schedule.yml +160 -0
  26. data/fixtures/campaigns/update.yml +159 -0
  27. data/fixtures/fields/create.yml +57 -0
  28. data/fixtures/fields/delete.yml +53 -0
  29. data/fixtures/fields/get.yml +60 -0
  30. data/fixtures/fields/update.yml +57 -0
  31. data/fixtures/forms/delete.yml +53 -0
  32. data/fixtures/forms/fetch.yml +60 -0
  33. data/fixtures/forms/fetch_subscribers.yml +59 -0
  34. data/fixtures/forms/list.yml +62 -0
  35. data/fixtures/forms/update.yml +60 -0
  36. data/fixtures/groups/assign_subscriber.yml +58 -0
  37. data/fixtures/groups/create.yml +58 -0
  38. data/fixtures/groups/delete.yml +53 -0
  39. data/fixtures/groups/get.yml +63 -0
  40. data/fixtures/groups/get_subscribers.yml +62 -0
  41. data/fixtures/groups/unassign_subscriber.yml +53 -0
  42. data/fixtures/groups/update.yml +58 -0
  43. data/fixtures/segments/delete.yml +53 -0
  44. data/fixtures/segments/get_subscribers.yml +61 -0
  45. data/fixtures/segments/list.yml +60 -0
  46. data/fixtures/segments/update.yml +58 -0
  47. data/fixtures/subscribers/create.yml +57 -0
  48. data/fixtures/subscribers/delete.yml +51 -0
  49. data/fixtures/subscribers/fetch.yml +68 -0
  50. data/fixtures/subscribers/fetch_count.yml +55 -0
  51. data/fixtures/subscribers/get.yml +62 -0
  52. data/fixtures/timezones/list.yml +575 -0
  53. data/fixtures/webhooks/create.yml +58 -0
  54. data/fixtures/webhooks/delete.yml +53 -0
  55. data/fixtures/webhooks/get.yml +58 -0
  56. data/fixtures/webhooks/list.yml +61 -0
  57. data/fixtures/webhooks/update.yml +58 -0
  58. data/lib/mailerlite/automations/automations.rb +62 -0
  59. data/lib/mailerlite/batch/batch.rb +24 -0
  60. data/lib/mailerlite/campaigns/campaigns.rb +216 -0
  61. data/lib/mailerlite/client.rb +35 -0
  62. data/lib/mailerlite/fields/fields.rb +61 -0
  63. data/lib/mailerlite/forms/forms.rb +73 -0
  64. data/lib/mailerlite/groups/groups.rb +90 -0
  65. data/lib/mailerlite/segments/segments.rb +62 -0
  66. data/lib/mailerlite/subscribers/subscribers.rb +116 -0
  67. data/lib/mailerlite/timezones/timezones.rb +22 -0
  68. data/lib/mailerlite/version.rb +5 -0
  69. data/lib/mailerlite/webhooks/webhooks.rb +67 -0
  70. data/lib/mailerlite-ruby.rb +3 -0
  71. data/lib/mailerlite.rb +13 -0
  72. data/mailerlite-ruby.gemspec +42 -0
  73. data/renovate.json +5 -0
  74. data/spec/automations_rspec.rb +63 -0
  75. data/spec/batches_rspec.rb +41 -0
  76. data/spec/campaigns_rspec.rb +155 -0
  77. data/spec/fields_rspec.rb +70 -0
  78. data/spec/forms_rspec.rb +81 -0
  79. data/spec/groups_rspec.rb +97 -0
  80. data/spec/segments_rspec.rb +70 -0
  81. data/spec/spec_helper.rb +101 -0
  82. data/spec/subscribers_rspec.rb +84 -0
  83. data/spec/timezones_rspec.rb +36 -0
  84. data/spec/webhooks_rspec.rb +86 -0
  85. metadata +303 -0
@@ -0,0 +1,155 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Import the RSpec and VCR gems
4
+ require 'spec_helper'
5
+ require 'vcr'
6
+ require 'json'
7
+
8
+ # require "webmock/rspec"
9
+ # Import the `Campaigns` class
10
+
11
+ # Configure VCR to save and replay HTTP requests
12
+ VCR.configure do |config|
13
+ config.cassette_library_dir = './fixtures'
14
+ config.hook_into :webmock
15
+ config.filter_sensitive_data('<AUTH>') do |interaction|
16
+ interaction.request.headers['Authorization'][0]
17
+ end
18
+ end
19
+
20
+ # Set up the test for the `Campaigns` class
21
+ RSpec.describe MailerLite::Campaigns do
22
+ let(:client) { MailerLite::Client.new }
23
+ let(:campaigns) { described_class.new(client: client) }
24
+
25
+ describe '#get' do
26
+ # Use VCR to record and replay the HTTP request
27
+ it 'returns a list of Campaigns' do
28
+ VCR.use_cassette('campaigns/get') do
29
+ response = campaigns.get(
30
+ filter: {
31
+ status: 'sent',
32
+ type: 'regular'
33
+ }
34
+ )
35
+ body = JSON.parse(response.body)
36
+ expect(response.status).to eq 200
37
+ expect(body['data']).to be_an Array
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '#create' do
43
+ # Use VCR to record and replay the HTTP request
44
+ it 'creates a new campaign' do
45
+ VCR.use_cassette('campaigns/create') do
46
+ response = campaigns.create(name: 'test_campaign',
47
+ type: 'regular',
48
+ emails: [{
49
+ subject: 'test subject',
50
+ from: 'sdk@mailerlite.com',
51
+ from_name: 'user'
52
+ }])
53
+ body = JSON.parse(response.body)
54
+ expect(response.status).to eq 201
55
+ expect(Integer(body['data']['id'])).to be_a Integer
56
+ end
57
+ end
58
+ end
59
+ describe '#update' do
60
+ # Use VCR to record and replay the HTTP request
61
+ it 'updates a new campaign' do
62
+ VCR.use_cassette('campaigns/update') do
63
+ response = campaigns.update(
64
+ campaign_id: 74_917_804_992_628_332,
65
+ name: 'test_campaign1',
66
+ type: 'regular',
67
+ emails: [{
68
+ subject: 'testsubject1',
69
+ from: 'sdk@mailerlite.com',
70
+ from_name: 'user',
71
+ content: '<!DOCTYPE html>
72
+ <html>
73
+ <body>
74
+ This is a test email
75
+ </body>
76
+ </html>'
77
+ }]
78
+ )
79
+ body = JSON.parse(response.body)
80
+ expect(response.status).to eq 200
81
+ expect(Integer(body['data']['id'])).to be_a Integer
82
+ end
83
+ end
84
+ end
85
+
86
+ describe '#fetch' do
87
+ # Use VCR to record and replay the HTTP request
88
+ it 'fetches a campaign' do
89
+ VCR.use_cassette('campaigns/fetch') do
90
+ response = campaigns.fetch(74_917_804_992_628_332)
91
+ body = JSON.parse(response.body)
92
+ expect(response.status).to eq 200
93
+ expect(Integer(body['data']['id'])).to be_a Integer
94
+ expect(Integer(body['data']['account_id'])).to be_a Integer
95
+ end
96
+ end
97
+ end
98
+
99
+ describe '#schedule' do
100
+ # Use VCR to record and replay the HTTP request
101
+ it 'schedules a campaign' do
102
+ VCR.use_cassette('campaigns/schedule') do
103
+ response = campaigns.schedule(
104
+ campaign_id: 75_323_121_649_846_116,
105
+ delivery: 'scheduled',
106
+ schedule: { date: '2022-12-31', hours: '22', minutes: '00' }
107
+ )
108
+ body = JSON.parse(response.body)
109
+ expect(response.status).to eq 200
110
+ expect(body['data']['status']).to eq 'ready'
111
+ expect(Integer(body['data']['account_id'])).to be_a Integer
112
+ expect(Integer(body['data']['id'])).to be_a Integer
113
+ end
114
+ end
115
+ end
116
+
117
+ describe '#activity' do
118
+ # Use VCR to record and replay the HTTP request
119
+ it 'gets subscriber activity of a campaign' do
120
+ VCR.use_cassette('campaigns/activity') do
121
+ response = campaigns.activity(
122
+ campaign_id: 75_037_917_434_611_569,
123
+ filter: {
124
+ type: 'opened'
125
+ }
126
+ )
127
+ body = JSON.parse(response.body)
128
+ expect(response.status).to eq 200
129
+ expect(body['data']).to be_a Array
130
+ end
131
+ end
132
+ end
133
+
134
+ describe '#languages' do
135
+ # Use VCR to record and replay the HTTP request
136
+ it 'gets subscriber languages of a campaign' do
137
+ VCR.use_cassette('campaigns/languages') do
138
+ response = campaigns.languages
139
+ body = JSON.parse(response.body)
140
+ expect(response.status).to eq 200
141
+ expect(body['data']).to be_a Array
142
+ end
143
+ end
144
+ end
145
+
146
+ describe '#delete' do
147
+ # Use VCR to record and replay the HTTP request
148
+ it 'deletes a campaign' do
149
+ VCR.use_cassette('campaigns/delete') do
150
+ response = campaigns.delete(74_917_804_992_628_332)
151
+ expect(response.status).to eq 204
152
+ end
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Import the RSpec and VCR gems
4
+ require 'spec_helper'
5
+ require 'vcr'
6
+ require 'json'
7
+
8
+ # require "webmock/rspec"
9
+ # Import the `Fields` class
10
+
11
+ # Configure VCR to save and replay HTTP requests
12
+ VCR.configure do |config|
13
+ config.cassette_library_dir = './fixtures'
14
+ config.hook_into :webmock
15
+ config.filter_sensitive_data('<AUTH>') do |interaction|
16
+ interaction.request.headers['Authorization'][0]
17
+ end
18
+ end
19
+
20
+ # Set up the test for the `Fields` class
21
+ RSpec.describe MailerLite::Fields do
22
+ let(:client) { MailerLite::Client.new }
23
+ let(:fields) { described_class.new(client: client) }
24
+
25
+ describe '#get' do
26
+ # Use VCR to record and replay the HTTP request
27
+ it 'returns a list of Fields' do
28
+ VCR.use_cassette('fields/get') do
29
+ response = fields.get
30
+ body = JSON.parse(response.body)
31
+ expect(response.status).to eq 200
32
+ expect(body['data']).to be_an Array
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '#create' do
38
+ # Use VCR to record and replay the HTTP request
39
+ it 'creates a field' do
40
+ VCR.use_cassette('fields/create') do
41
+ response = fields.create(type: 'text', name: 'test_field_name')
42
+ body = JSON.parse(response.body)
43
+ expect(response.status).to eq 201
44
+ expect(Integer(body['data']['id'])).to be_an Integer
45
+ end
46
+ end
47
+ end
48
+
49
+ describe '#update' do
50
+ # Use VCR to record and replay the HTTP request
51
+ it 'updates a field' do
52
+ VCR.use_cassette('fields/update') do
53
+ response = fields.update(field_id: 91_115, name: 'test_field2')
54
+ body = JSON.parse(response.body)
55
+ expect(response.status).to eq 200
56
+ expect(Integer(body['data']['id'])).to be_an Integer
57
+ end
58
+ end
59
+ end
60
+
61
+ describe '#delete' do
62
+ # Use VCR to record and replay the HTTP request
63
+ it 'deletes a field' do
64
+ VCR.use_cassette('fields/delete') do
65
+ response = fields.delete(91_115)
66
+ expect(response.status).to eq 204
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Import the RSpec and VCR gems
4
+ require 'spec_helper'
5
+ require 'vcr'
6
+ require 'json'
7
+
8
+ # require "webmock/rspec"
9
+ # Import the `Forms` class
10
+
11
+ # Configure VCR to save and replay HTTP requests
12
+ VCR.configure do |config|
13
+ config.cassette_library_dir = './fixtures'
14
+ config.hook_into :webmock
15
+ config.filter_sensitive_data('<AUTH>') do |interaction|
16
+ interaction.request.headers['Authorization'][0]
17
+ end
18
+ end
19
+
20
+ # Set up the test for the `Forms` class
21
+ RSpec.describe MailerLite::Forms do
22
+ let(:client) { MailerLite::Client.new }
23
+ let(:forms) { described_class.new(client: client) }
24
+
25
+ describe '#list' do
26
+ # Use VCR to record and replay the HTTP request
27
+ it 'lists all form' do
28
+ VCR.use_cassette('forms/list') do
29
+ response = forms.list(type: 'popup')
30
+ body = JSON.parse(response.body)
31
+ expect(response.status).to eq 200
32
+ expect(body['data']).to be_an Array
33
+ end
34
+ end
35
+ end
36
+ describe '#update' do
37
+ # Use VCR to record and replay the HTTP request
38
+ it 'updates a form' do
39
+ VCR.use_cassette('forms/update') do
40
+ response = forms.update(form_id: 75_017_795_259_074_408, name: 'test_form2')
41
+ body = JSON.parse(response.body)
42
+ expect(response.status).to eq 200
43
+ expect(Integer(body['data']['id'])).to be_an Integer
44
+ end
45
+ end
46
+ end
47
+
48
+ describe '#fetch' do
49
+ # Use VCR to record and replay the HTTP request
50
+ it 'fetchs all form' do
51
+ VCR.use_cassette('forms/fetch') do
52
+ response = forms.fetch(75_016_692_854_425_001)
53
+ body = JSON.parse(response.body)
54
+ expect(response.status).to eq 200
55
+ expect(Integer(body['data']['id'])).to be_an Integer
56
+ end
57
+ end
58
+ end
59
+
60
+ describe '#fetch_subscribers' do
61
+ # Use VCR to record and replay the HTTP request
62
+ it 'fetch_subscribers of a form' do
63
+ VCR.use_cassette('forms/fetch_subscribers') do
64
+ response = forms.fetch_subscribers(75_231_510_415_803_781)
65
+ body = JSON.parse(response.body)
66
+ expect(response.status).to eq 200
67
+ expect(body['data']).to be_an Array
68
+ end
69
+ end
70
+ end
71
+
72
+ describe '#delete' do
73
+ # Use VCR to record and replay the HTTP request
74
+ it 'deletes a form' do
75
+ VCR.use_cassette('forms/delete') do
76
+ response = forms.delete(75_016_692_854_425_001)
77
+ expect(response.status).to eq 204
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Import the RSpec and VCR gems
4
+ require 'spec_helper'
5
+ require 'vcr'
6
+ require 'json'
7
+
8
+ # Configure VCR to save and replay HTTP requests
9
+ VCR.configure do |config|
10
+ config.cassette_library_dir = './fixtures'
11
+ config.hook_into :webmock
12
+ config.filter_sensitive_data('<AUTH>') do |interaction|
13
+ interaction.request.headers['Authorization'][0]
14
+ end
15
+ end
16
+
17
+ # Set up the test for the `Groups` class
18
+ RSpec.describe MailerLite::Groups do
19
+ let(:client) { MailerLite::Client.new }
20
+ let(:groups) { described_class.new(client: client) }
21
+
22
+ describe '#get' do
23
+ # Use VCR to record and replay the HTTP request
24
+ it 'returns a list of groups' do
25
+ VCR.use_cassette('groups/get') do
26
+ response = groups.get
27
+ body = JSON.parse(response.body)
28
+ expect(response.status).to eq 200
29
+ expect(body['data']).to be_an Array
30
+ end
31
+ end
32
+ end
33
+ describe '#create' do
34
+ # Use VCR to record and replay the HTTP request
35
+ it 'creates a group' do
36
+ VCR.use_cassette('groups/create') do
37
+ response = groups.create(name: 'test_group2')
38
+ body = JSON.parse(response.body)
39
+ expect(response.status).to eq 201
40
+ expect(Integer(body['data']['id'])).to be_an Integer
41
+ end
42
+ end
43
+ end
44
+ describe '#update' do
45
+ # Use VCR to record and replay the HTTP request
46
+ it 'updates a group' do
47
+ VCR.use_cassette('groups/update') do
48
+ response = groups.update(group_id: 75_138_589_423_306_653, name: 'test_group3')
49
+ body = JSON.parse(response.body)
50
+ expect(response.status).to eq 200
51
+ expect(Integer(body['data']['id'])).to be_an Integer
52
+ end
53
+ end
54
+ end
55
+
56
+ describe '#delete' do
57
+ # Use VCR to record and replay the HTTP request
58
+ it 'deletes a group' do
59
+ VCR.use_cassette('groups/delete') do
60
+ response = groups.delete(75_138_589_423_306_653)
61
+ expect(response.status).to eq 204
62
+ end
63
+ end
64
+ end
65
+
66
+ describe '#get_subscribers' do
67
+ # Use VCR to record and replay the HTTP request
68
+ it 'get_subscribers for a group' do
69
+ VCR.use_cassette('groups/get_subscribers') do
70
+ response = groups.get_subscribers(group_id: 75_011_449_370_445_335)
71
+ body = JSON.parse(response.body)
72
+ expect(response.status).to eq 200
73
+ expect(body['data']).to be_an Array
74
+ end
75
+ end
76
+ end
77
+
78
+ describe '#assign_subscribers' do
79
+ # Use VCR to record and replay the HTTP request
80
+ it 'assign_subscribers for a group' do
81
+ VCR.use_cassette('groups/assign_subscriber') do
82
+ response = groups.assign_subscriber(group_id: 75_138_557_045_376_452, subscriber: 75_009_808_379_414_225)
83
+ expect(response.status).to eq 200
84
+ end
85
+ end
86
+ end
87
+
88
+ describe '#unassign_subscribers' do
89
+ # Use VCR to record and replay the HTTP request
90
+ it 'unassign_subscribers for a group' do
91
+ VCR.use_cassette('groups/unassign_subscriber') do
92
+ response = groups.unassign_subscriber(group_id: 75_138_557_045_376_452, subscriber: 75_009_808_379_414_225)
93
+ expect(response.status).to eq 204
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Import the RSpec and VCR gems
4
+ require 'spec_helper'
5
+ require 'vcr'
6
+ require 'json'
7
+
8
+ # require "webmock/rspec"
9
+ # Import the `Segments` class
10
+
11
+ # Configure VCR to save and replay HTTP requests
12
+ VCR.configure do |config|
13
+ config.cassette_library_dir = './fixtures'
14
+ config.hook_into :webmock
15
+ config.filter_sensitive_data('<AUTH>') do |interaction|
16
+ interaction.request.headers['Authorization'][0]
17
+ end
18
+ end
19
+
20
+ # Set up the test for the `Segments` class
21
+ RSpec.describe MailerLite::Segments do
22
+ let(:client) { MailerLite::Client.new }
23
+ let(:segments) { described_class.new(client: client) }
24
+
25
+ describe '#list' do
26
+ # Use VCR to record and replay the HTTP request
27
+ it 'returns a list of Segments' do
28
+ VCR.use_cassette('segments/list') do
29
+ response = segments.list
30
+ body = JSON.parse(response.body)
31
+ expect(response.status).to eq 200
32
+ expect(body['data']).to be_an Array
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '#update' do
38
+ # Use VCR to record and replay the HTTP request
39
+ it 'updates a segment' do
40
+ VCR.use_cassette('segments/update') do
41
+ response = segments.update(segment_id: 75_140_256_628_737_109, name: 'test_segment2')
42
+ body = JSON.parse(response.body)
43
+ expect(response.status).to eq 200
44
+ expect(Integer(body['data']['id'])).to be_an Integer
45
+ end
46
+ end
47
+ end
48
+
49
+ describe '#get_subscribers' do
50
+ # Use VCR to record and replay the HTTP request
51
+ it 'get_subscribers for a segment' do
52
+ VCR.use_cassette('segments/get_subscribers') do
53
+ response = segments.get_subscribers(segment_id: 75_140_256_628_737_109)
54
+ body = JSON.parse(response.body)
55
+ expect(response.status).to eq 200
56
+ expect(body['data']).to be_an Array
57
+ end
58
+ end
59
+ end
60
+
61
+ describe '#delete' do
62
+ # Use VCR to record and replay the HTTP request
63
+ it 'deletes a segment' do
64
+ VCR.use_cassette('segments/delete') do
65
+ response = segments.delete(75_140_256_628_737_109)
66
+ expect(response.status).to eq 204
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'mailerlite'
6
+ # This file was generated by the `rspec --init` command. Conventionally, all
7
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
8
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
9
+ # this file to always be loaded, without a need to explicitly require it in any
10
+ # files.
11
+ #
12
+ # Given that it is always loaded, you are encouraged to keep this file as
13
+ # light-weight as possible. Requiring heavyweight dependencies from this file
14
+ # will add to the boot time of your test suite on EVERY test run, even for an
15
+ # individual file that may not need all of that loaded. Instead, consider making
16
+ # a separate helper file that requires the additional dependencies and performs
17
+ # the additional setup, and require it from the spec files that actually need
18
+ # it.
19
+ #
20
+ # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+ RSpec.configure do |config|
22
+ # rspec-expectations config goes here. You can use an alternate
23
+ # assertion/expectation library such as wrong or the stdlib/minitest
24
+ # assertions if you prefer.
25
+ config.expect_with :rspec do |expectations|
26
+ # This option will default to `true` in RSpec 4. It makes the `description`
27
+ # and `failure_message` of custom matchers include text for helper methods
28
+ # defined using `chain`, e.g.:
29
+ # be_bigger_than(2).and_smaller_than(4).description
30
+ # # => "be bigger than 2 and smaller than 4"
31
+ # ...rather than:
32
+ # # => "be bigger than 2"
33
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
+ end
35
+
36
+ # rspec-mocks config goes here. You can use an alternate test double
37
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
38
+ config.mock_with :rspec do |mocks|
39
+ # Prevents you from mocking or stubbing a method that does not exist on
40
+ # a real object. This is generally recommended, and will default to
41
+ # `true` in RSpec 4.
42
+ mocks.verify_partial_doubles = true
43
+ end
44
+
45
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
46
+ # have no way to turn it off -- the option exists only for backwards
47
+ # compatibility in RSpec 3). It causes shared context metadata to be
48
+ # inherited by the metadata hash of host groups and examples, rather than
49
+ # triggering implicit auto-inclusion in groups with matching metadata.
50
+ config.shared_context_metadata_behavior = :apply_to_host_groups
51
+
52
+ # The settings below are suggested to provide a good initial experience
53
+ # with RSpec, but feel free to customize to your heart's content.
54
+ # # This allows you to limit a spec run to individual examples or groups
55
+ # # you care about by tagging them with `:focus` metadata. When nothing
56
+ # # is tagged with `:focus`, all examples get run. RSpec also provides
57
+ # # aliases for `it`, `describe`, and `context` that include `:focus`
58
+ # # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
59
+ # config.filter_run_when_matching :focus
60
+ #
61
+ # # Allows RSpec to persist some state between runs in order to support
62
+ # # the `--only-failures` and `--next-failure` CLI options. We recommend
63
+ # # you configure your source control system to ignore this file.
64
+ # config.example_status_persistence_file_path = "spec/examples.txt"
65
+ #
66
+ # # Limits the available syntax to the non-monkey patched syntax that is
67
+ # # recommended. For more details, see:
68
+ # # https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode
69
+ # config.disable_monkey_patching!
70
+ #
71
+ # # This setting enables warnings. It's recommended, but in some cases may
72
+ # # be too noisy due to issues in dependencies.
73
+ # config.warnings = true
74
+ #
75
+ # # Many RSpec users commonly either run the entire suite or an individual
76
+ # # file, and it's useful to allow more verbose output when running an
77
+ # # individual spec file.
78
+ # if config.files_to_run.one?
79
+ # # Use the documentation formatter for detailed output,
80
+ # # unless a formatter has already been configured
81
+ # # (e.g. via a command-line flag).
82
+ # config.default_formatter = "doc"
83
+ # end
84
+ #
85
+ # # Print the 10 slowest examples and example groups at the
86
+ # # end of the spec run, to help surface which specs are running
87
+ # # particularly slow.
88
+ # config.profile_examples = 10
89
+ #
90
+ # # Run specs in random order to surface order dependencies. If you find an
91
+ # # order dependency and want to debug it, you can fix the order by providing
92
+ # # the seed, which is printed after each run.
93
+ # # --seed 1234
94
+ # config.order = :random
95
+ #
96
+ # # Seed global randomization in this process using the `--seed` CLI option.
97
+ # # Setting this allows you to use `--seed` to deterministically reproduce
98
+ # # test failures related to randomization by passing the same `--seed` value
99
+ # # as the one that triggered the failure.
100
+ # Kernel.srand config.seed
101
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Import the RSpec and VCR gems
4
+ require 'spec_helper'
5
+ require 'vcr'
6
+ require 'json'
7
+
8
+ # require "webmock/rspec"
9
+ # Import the `Subscribers` class
10
+
11
+ # Configure VCR to save and replay HTTP requests
12
+ VCR.configure do |config|
13
+ config.cassette_library_dir = './fixtures'
14
+ config.hook_into :webmock
15
+ config.filter_sensitive_data('<AUTH>') do |interaction|
16
+ interaction.request.headers['Authorization'][0]
17
+ end
18
+ end
19
+
20
+ # Set up the test for the `Subscribers` class
21
+ RSpec.describe MailerLite::Subscribers do
22
+ let(:client) { MailerLite::Client.new }
23
+ let(:subscribers) { described_class.new(client: client) }
24
+
25
+ describe '#fetch' do
26
+ # Use VCR to record and replay the HTTP request
27
+ it 'returns a list of subscribers' do
28
+ VCR.use_cassette('subscribers/fetch') do
29
+ response = subscribers.fetch(filter: { status: 'active' })
30
+ body = JSON.parse(response.body)
31
+ expect(response.status).to eq 200
32
+ expect(body['data']).to be_an Array
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '#create' do
38
+ # Use VCR to record and replay the HTTP request
39
+ it 'creates a new subscriber' do
40
+ VCR.use_cassette('subscribers/create') do
41
+ response = subscribers.create(email: 'user@example.com')
42
+ body = JSON.parse(response.body)
43
+ expect(response.status).to eq 200
44
+ expect(Integer(body['data']['id'])).to be_a Integer
45
+ expect(body['data']['email']).to eq 'user@example.com'
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '#get' do
51
+ # Use VCR to record and replay the HTTP request
52
+ it 'gets a subscriber' do
53
+ VCR.use_cassette('subscribers/get') do
54
+ response = subscribers.get('second@email.com')
55
+ body = JSON.parse(response.body)
56
+ expect(response.status).to eq 200
57
+ expect(Integer(body['data']['id'])).to eq 75_009_808_379_414_225
58
+ expect(body['data']['email']).to be_a String
59
+ end
60
+ end
61
+ end
62
+
63
+ describe '#fetch_count' do
64
+ # Use VCR to record and replay the HTTP request
65
+ it 'fetches the subscriber count' do
66
+ VCR.use_cassette('subscribers/fetch_count') do
67
+ response = subscribers.fetch_count
68
+ body = JSON.parse(response.body)
69
+ expect(response.status).to eq 200
70
+ expect(body['total']).to be_a Integer
71
+ end
72
+ end
73
+ end
74
+
75
+ describe '#delete' do
76
+ # Use VCR to record and replay the HTTP request
77
+ it 'deletes a subscriber' do
78
+ VCR.use_cassette('subscribers/delete') do
79
+ response = subscribers.delete(73_871_649_530_709_291)
80
+ expect(response.status).to eq 204
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Import the RSpec and VCR gems
4
+ require 'spec_helper'
5
+ require 'vcr'
6
+ require 'json'
7
+
8
+ # require "webmock/rspec"
9
+ # Import the `Timezones` class
10
+
11
+ # Configure VCR to save and replay HTTP requests
12
+ VCR.configure do |config|
13
+ config.cassette_library_dir = './fixtures'
14
+ config.hook_into :webmock
15
+ config.filter_sensitive_data('<AUTH>') do |interaction|
16
+ interaction.request.headers['Authorization'][0]
17
+ end
18
+ end
19
+
20
+ # Set up the test for the `Timezones` class
21
+ RSpec.describe MailerLite::Timezones do
22
+ let(:client) { MailerLite::Client.new }
23
+ let(:timezones) { described_class.new(client: client) }
24
+
25
+ describe '#list' do
26
+ # Use VCR to record and replay the HTTP request
27
+ it 'lists all Timezones' do
28
+ VCR.use_cassette('timezones/list') do
29
+ response = timezones.list
30
+ body = JSON.parse(response.body)
31
+ expect(response.status).to eq 200
32
+ expect(body['data']).to be_an Array
33
+ end
34
+ end
35
+ end
36
+ end