mailshake-ruby 0.1.0 → 0.3.0

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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +80 -19
  3. data/lib/mailshake/activity.rb +14 -7
  4. data/lib/mailshake/campaigns.rb +10 -5
  5. data/lib/mailshake/client.rb +23 -2
  6. data/lib/mailshake/errors.rb +15 -0
  7. data/lib/mailshake/leads.rb +6 -3
  8. data/lib/mailshake/models/add_recipients_request.rb +8 -0
  9. data/lib/mailshake/models/added_recipients.rb +8 -0
  10. data/lib/mailshake/models/base_model.rb +79 -0
  11. data/lib/mailshake/models/campaign.rb +10 -0
  12. data/lib/mailshake/models/campaign_export.rb +8 -0
  13. data/lib/mailshake/models/campaign_export_request.rb +8 -0
  14. data/lib/mailshake/models/click.rb +11 -0
  15. data/lib/mailshake/models/created_leads.rb +8 -0
  16. data/lib/mailshake/models/lead.rb +11 -0
  17. data/lib/mailshake/models/lead_status.rb +8 -0
  18. data/lib/mailshake/models/list.rb +30 -0
  19. data/lib/mailshake/models/message.rb +8 -0
  20. data/lib/mailshake/models/open.rb +11 -0
  21. data/lib/mailshake/models/recipient.rb +8 -0
  22. data/lib/mailshake/models/reply.rb +11 -0
  23. data/lib/mailshake/models/sender.rb +8 -0
  24. data/lib/mailshake/models/sent_message.rb +11 -0
  25. data/lib/mailshake/models/user.rb +8 -0
  26. data/lib/mailshake/recipients.rb +8 -4
  27. data/lib/mailshake/senders.rb +2 -1
  28. data/lib/mailshake/team.rb +2 -1
  29. data/lib/mailshake/version.rb +1 -1
  30. data/lib/mailshake.rb +21 -0
  31. data/spec/examples.txt +89 -60
  32. data/spec/mailshake/activity_spec.rb +4 -2
  33. data/spec/mailshake/campaigns_spec.rb +10 -4
  34. data/spec/mailshake/client_spec.rb +54 -0
  35. data/spec/mailshake/leads_spec.rb +5 -2
  36. data/spec/mailshake/models/base_model_spec.rb +118 -0
  37. data/spec/mailshake/models/list_spec.rb +103 -0
  38. data/spec/mailshake/push_spec.rb +1 -0
  39. data/spec/mailshake/recipients_spec.rb +7 -3
  40. data/spec/mailshake/senders_spec.rb +2 -1
  41. data/spec/mailshake/team_spec.rb +2 -1
  42. metadata +24 -2
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Mailshake::Models::List do
6
+ describe "results array with model objects" do
7
+ it "wraps results in model objects" do
8
+ data = {
9
+ "results" => [
10
+ { "id" => 1, "title" => "Campaign 1" },
11
+ { "id" => 2, "title" => "Campaign 2" }
12
+ ],
13
+ "nextToken" => "abc123"
14
+ }
15
+
16
+ list = described_class.new(data, Mailshake::Models::Campaign)
17
+ expect(list.results.length).to eq(2)
18
+ expect(list.results.first).to be_a(Mailshake::Models::Campaign)
19
+ expect(list.results.first.title).to eq("Campaign 1")
20
+ expect(list.results.last.title).to eq("Campaign 2")
21
+ end
22
+
23
+ it "handles empty results" do
24
+ data = { "results" => [] }
25
+ list = described_class.new(data, Mailshake::Models::Campaign)
26
+ expect(list.results).to eq([])
27
+ end
28
+
29
+ it "handles missing results key" do
30
+ list = described_class.new({}, Mailshake::Models::Campaign)
31
+ expect(list.results).to eq([])
32
+ end
33
+ end
34
+
35
+ describe "next_token" do
36
+ it "exposes next_token from response" do
37
+ data = { "results" => [], "nextToken" => "page2" }
38
+ list = described_class.new(data, Mailshake::Models::Campaign)
39
+ expect(list.next_token).to eq("page2")
40
+ end
41
+
42
+ it "returns nil when no next_token" do
43
+ data = { "results" => [] }
44
+ list = described_class.new(data, Mailshake::Models::Campaign)
45
+ expect(list.next_token).to be_nil
46
+ end
47
+ end
48
+
49
+ describe "Enumerable methods" do
50
+ let(:data) do
51
+ {
52
+ "results" => [
53
+ { "id" => 1, "title" => "First" },
54
+ { "id" => 2, "title" => "Second" },
55
+ { "id" => 3, "title" => "Third" }
56
+ ]
57
+ }
58
+ end
59
+ let(:list) { described_class.new(data, Mailshake::Models::Campaign) }
60
+
61
+ it "supports each" do
62
+ titles = []
63
+ list.each { |campaign| titles << campaign.title }
64
+ expect(titles).to eq(["First", "Second", "Third"])
65
+ end
66
+
67
+ it "supports map" do
68
+ ids = list.map(&:id)
69
+ expect(ids).to eq([1, 2, 3])
70
+ end
71
+
72
+ it "supports select" do
73
+ selected = list.select { |c| c.id > 1 }
74
+ expect(selected.length).to eq(2)
75
+ end
76
+
77
+ it "supports first" do
78
+ expect(list.first).to be_a(Mailshake::Models::Campaign)
79
+ expect(list.first.id).to eq(1)
80
+ end
81
+
82
+ it "supports count" do
83
+ expect(list.count).to eq(3)
84
+ end
85
+ end
86
+
87
+ describe "[] backwards compatibility" do
88
+ it "accesses original hash keys" do
89
+ data = { "results" => [{ "id" => 1 }], "nextToken" => "abc" }
90
+ list = described_class.new(data, Mailshake::Models::Campaign)
91
+ expect(list["results"]).to eq([{ "id" => 1 }])
92
+ expect(list["nextToken"]).to eq("abc")
93
+ end
94
+ end
95
+
96
+ describe "#to_h" do
97
+ it "returns the original data hash" do
98
+ data = { "results" => [{ "id" => 1 }], "nextToken" => "abc" }
99
+ list = described_class.new(data, Mailshake::Models::Campaign)
100
+ expect(list.to_h).to eq(data)
101
+ end
102
+ end
103
+ end
@@ -14,6 +14,7 @@ RSpec.describe Mailshake::Push do
14
14
  headers: { "Content-Type" => "application/json" })
15
15
 
16
16
  result = push.create(target_url: "https://example.com/webhook", event: "reply")
17
+ expect(result).to be_a(Hash)
17
18
  expect(result["id"]).to eq(1)
18
19
  end
19
20
 
@@ -14,6 +14,7 @@ RSpec.describe Mailshake::Recipients do
14
14
  headers: { "Content-Type" => "application/json" })
15
15
 
16
16
  result = recipients.add(campaign_id: 1, addresses: [{ emailAddress: "john@example.com" }])
17
+ expect(result).to be_a(Mailshake::Models::AddRecipientsRequest)
17
18
  expect(result["statusID"]).to eq(10)
18
19
  end
19
20
  end
@@ -26,7 +27,8 @@ RSpec.describe Mailshake::Recipients do
26
27
  headers: { "Content-Type" => "application/json" })
27
28
 
28
29
  result = recipients.add_status(status_id: "10")
29
- expect(result["isFinished"]).to be true
30
+ expect(result).to be_a(Mailshake::Models::AddedRecipients)
31
+ expect(result.is_finished).to be true
30
32
  end
31
33
  end
32
34
 
@@ -38,7 +40,8 @@ RSpec.describe Mailshake::Recipients do
38
40
  headers: { "Content-Type" => "application/json" })
39
41
 
40
42
  result = recipients.list(campaign_id: "1")
41
- expect(result["results"]).to eq([])
43
+ expect(result).to be_a(Mailshake::Models::List)
44
+ expect(result.results).to eq([])
42
45
  end
43
46
 
44
47
  it "passes filter and pagination params" do
@@ -59,7 +62,8 @@ RSpec.describe Mailshake::Recipients do
59
62
  headers: { "Content-Type" => "application/json" })
60
63
 
61
64
  result = recipients.get(recipient_id: "100")
62
- expect(result["emailAddress"]).to eq("john@example.com")
65
+ expect(result).to be_a(Mailshake::Models::Recipient)
66
+ expect(result.email_address).to eq("john@example.com")
63
67
  end
64
68
  end
65
69
 
@@ -13,7 +13,8 @@ RSpec.describe Mailshake::Senders do
13
13
  headers: { "Content-Type" => "application/json" })
14
14
 
15
15
  result = senders.list
16
- expect(result["results"]).to eq([])
16
+ expect(result).to be_a(Mailshake::Models::List)
17
+ expect(result.results).to eq([])
17
18
  end
18
19
 
19
20
  it "passes search and pagination params" do
@@ -13,7 +13,8 @@ RSpec.describe Mailshake::Team do
13
13
  headers: { "Content-Type" => "application/json" })
14
14
 
15
15
  result = team.list_members
16
- expect(result["results"]).to eq([])
16
+ expect(result).to be_a(Mailshake::Models::List)
17
+ expect(result.results).to eq([])
17
18
  end
18
19
 
19
20
  it "passes search and pagination params" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailshake-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Souza
@@ -128,6 +128,24 @@ files:
128
128
  - lib/mailshake/configuration.rb
129
129
  - lib/mailshake/errors.rb
130
130
  - lib/mailshake/leads.rb
131
+ - lib/mailshake/models/add_recipients_request.rb
132
+ - lib/mailshake/models/added_recipients.rb
133
+ - lib/mailshake/models/base_model.rb
134
+ - lib/mailshake/models/campaign.rb
135
+ - lib/mailshake/models/campaign_export.rb
136
+ - lib/mailshake/models/campaign_export_request.rb
137
+ - lib/mailshake/models/click.rb
138
+ - lib/mailshake/models/created_leads.rb
139
+ - lib/mailshake/models/lead.rb
140
+ - lib/mailshake/models/lead_status.rb
141
+ - lib/mailshake/models/list.rb
142
+ - lib/mailshake/models/message.rb
143
+ - lib/mailshake/models/open.rb
144
+ - lib/mailshake/models/recipient.rb
145
+ - lib/mailshake/models/reply.rb
146
+ - lib/mailshake/models/sender.rb
147
+ - lib/mailshake/models/sent_message.rb
148
+ - lib/mailshake/models/user.rb
131
149
  - lib/mailshake/push.rb
132
150
  - lib/mailshake/recipients.rb
133
151
  - lib/mailshake/senders.rb
@@ -139,6 +157,8 @@ files:
139
157
  - spec/mailshake/client_spec.rb
140
158
  - spec/mailshake/configuration_spec.rb
141
159
  - spec/mailshake/leads_spec.rb
160
+ - spec/mailshake/models/base_model_spec.rb
161
+ - spec/mailshake/models/list_spec.rb
142
162
  - spec/mailshake/push_spec.rb
143
163
  - spec/mailshake/recipients_spec.rb
144
164
  - spec/mailshake/senders_spec.rb
@@ -148,9 +168,11 @@ homepage: https://github.com/esouza/mailshake-ruby
148
168
  licenses:
149
169
  - MIT
150
170
  metadata:
171
+ allowed_push_host: https://rubygems.org
151
172
  homepage_uri: https://github.com/esouza/mailshake-ruby
152
173
  source_code_uri: https://github.com/esouza/mailshake-ruby
153
- changelog_uri: https://github.com/esouza/mailshake-ruby/blob/main/CHANGELOG.md
174
+ changelog_uri: https://github.com/esouza/mailshake-ruby/blob/master/CHANGELOG.md
175
+ bug_tracker_uri: https://github.com/esouza/mailshake-ruby/issues
154
176
  post_install_message:
155
177
  rdoc_options: []
156
178
  require_paths: