mailgun-ruby 1.2.14 → 1.2.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3905ad8ab1dae85ea3b87b10d2ac01700de085adab73d9e02373f4d54e70451d
4
- data.tar.gz: e5794e301066318205a9ffb6de455d73642d3162b1ad75900cefed7aa95db798
3
+ metadata.gz: 88449bde0909456b09f66ea57e253fbfe06f2de6fddb2640f9b5571479d9cedc
4
+ data.tar.gz: 3ed8f2ace6300271251bedab59ffc118acd3fb570a7a361b5c26d6c2a98352e8
5
5
  SHA512:
6
- metadata.gz: af8ed54564c2f13b818aa7da6a550b9000b4148ee437b108d01219d80b610580fde3a1973dd831db3ffd8b0dbe934d9288b479a335a5521e3f275815a9f30c8e
7
- data.tar.gz: 5d11d20420e6333e9e71104fc529d80f19ed689cb300bc5b19ec4c2b855e9c92e24e59d7de83122d2bcdc910a0ec60f783ea277e011e8d375bb1e471be30802e
6
+ metadata.gz: 2159184a986dae450bec7069c8420671a860c7e06abe9ab660cf3a9af594ce62e67428c85782a25c242e99fc2bb250e172caa0e616e296332bf7f0f9fe7f8dc1
7
+ data.tar.gz: 2cf4aa439edfaf850e0151b43edbce7722701db5ec55ab087dbaffed70a64a1f8d99975cda71bc1e303284b5f6ce6865706a1414299fe554bbfdbc6f7e77669e
data/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [1.2.15] - 2024-02-13
8
+
9
+ ### Fixed
10
+
11
+ - Remove Openstruct usage (- Remove OpenStruct usage, will warn in Ruby 3.4, raise in Ruby 3.5 (https://github.com/mailgun/mailgun-ruby/issues/321)).
12
+ - Error handling (- Work around error responses without message property (https://github.com/mailgun/mailgun-ruby/pull/324)).
13
+
7
14
  ## [1.2.14] - 2024-02-13
8
15
 
9
16
  ### Added
data/README.md CHANGED
@@ -19,7 +19,7 @@ gem install mailgun-ruby
19
19
  Gemfile:
20
20
 
21
21
  ```ruby
22
- gem 'mailgun-ruby', '~>1.2.14'
22
+ gem 'mailgun-ruby', '~>1.2.15'
23
23
  ```
24
24
 
25
25
  Usage
@@ -50,7 +50,8 @@ module Mailgun
50
50
  end
51
51
 
52
52
  begin
53
- api_message = JSON.parse(response.body)['message']
53
+ json = JSON.parse(response.body)
54
+ api_message = json['message'] || json['Error'] || json['error']
54
55
  rescue JSON::ParserError
55
56
  api_message = response.body
56
57
  rescue NoMethodError
@@ -60,7 +61,7 @@ module Mailgun
60
61
  end
61
62
 
62
63
  message = message || ''
63
- message = message + ': ' + api_message
64
+ message = message + ': ' + (api_message || "")
64
65
 
65
66
  super(message, response)
66
67
  rescue NoMethodError, JSON::ParserError
@@ -1,5 +1,3 @@
1
- require 'ostruct'
2
-
3
1
  module Mailgun
4
2
  # A Mailgun::Response object is instantiated for each response generated
5
3
  # by the Client request. The Response object supports deserialization of
@@ -12,9 +10,10 @@ module Mailgun
12
10
  # slightly different
13
11
  attr_accessor :body, :code
14
12
 
13
+ ResponseHash = Struct.new(:body, :code)
15
14
  def self.from_hash(h)
16
15
  # Create a "fake" response object with the data passed from h
17
- self.new OpenStruct.new(h)
16
+ self.new ResponseHash.new(h[:body], h[:code])
18
17
  end
19
18
 
20
19
  def initialize(response)
@@ -1,4 +1,4 @@
1
1
  # It's the version. Yeay!
2
2
  module Mailgun
3
- VERSION = '1.2.14'
3
+ VERSION = '1.2.15'
4
4
  end
@@ -96,19 +96,19 @@ module Mailgun
96
96
  if resource_endpoint == "messages"
97
97
  t = Time.now
98
98
  id = "<#{t.to_i}.#{rand(99999999)}.5817@example.com>"
99
- return OpenStruct.new({ "body" => JSON.generate({"message" => "Queued. Thank you.", "id" => id}) })
99
+ return Response.from_hash({ body: JSON.generate({"message" => "Queued. Thank you.", "id" => id}) })
100
100
  end
101
101
  if resource_endpoint == "bounces"
102
- return OpenStruct.new({ "body" => JSON.generate({"total_count" => 1, "items" => {"created_at" => "Fri, 21 Oct 2011 11:02:55 GMT", "code" => 550, "address" => "baz@example.com", "error" => "Message was not accepted -- invalid mailbox. Local mailbox baz@example.com is unavailable: user not found"}}) })
102
+ return Response.from_hash({ body: JSON.generate({"total_count" => 1, "items" => {"created_at" => "Fri, 21 Oct 2011 11:02:55 GMT", "code" => 550, "address" => "baz@example.com", "error" => "Message was not accepted -- invalid mailbox. Local mailbox baz@example.com is unavailable: user not found"}}) })
103
103
  end
104
104
  if resource_endpoint == "lists"
105
- return OpenStruct.new({ "body" => JSON.generate({"member" => {"vars" => {"age" => 26}, "name" => "Foo Bar", "subscribed" => false, "address" => "bar@example.com"}, "message" => "Mailing list member has been updated"}) })
105
+ return Response.from_hash({ body: JSON.generate({"member" => {"vars" => {"age" => 26}, "name" => "Foo Bar", "subscribed" => false, "address" => "bar@example.com"}, "message" => "Mailing list member has been updated"}) })
106
106
  end
107
107
  if resource_endpoint == "campaigns"
108
- return OpenStruct.new({ "body" => JSON.generate({"message" => "Campaign has been deleted", "id" => "ABC123"}) })
108
+ return Response.from_hash({ body: JSON.generate({"message" => "Campaign has been deleted", "id" => "ABC123"}) })
109
109
  end
110
110
  if resource_endpoint == "events"
111
- return OpenStruct.new({ "body" => JSON.generate({"items" => [], "paging" => {"next"=> "https://api.mailgun.net/v3/thisisatestdomainformailgun.com/events/W3siYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzKzAwOjAwIn0sIHsiYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzKzAwOjAwIn0sIFsiZiJdLCBudWxsLCB7ImFjY291bnQuaWQiOiAiNGU4MjMwZjYxNDc2ZDg2NzEzMDBjNDc2IiwgImRvbWFpbi5uYW1lIjogInRoaXNpc2F0ZXN0ZG9tYWluZm9ybWFpbGd1bi5jb20iLCAic2V2ZXJpdHkiOiAiTk9UIGludGVybmFsIn0sIDEwMCwgbnVsbF0=", "previous"=> "https://api.mailgun.net/v2/thisisatestdomainformailgun.com/events/W3siYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzKzAwOjAwIn0sIHsiYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDdUMDA6NDU6NTEuNzQxODkyKzAwOjAwIn0sIFsicCIsICJmIl0sIG51bGwsIHsiYWNjb3VudC5pZCI6ICI0ZTgyMzBmNjE0NzZkODY3MTMwMGM0NzYiLCAiZG9tYWluLm5hbWUiOiAidGhpc2lzYXRlc3Rkb21haW5mb3JtYWlsZ3VuLmNvbSIsICJzZXZlcml0eSI6ICJOT1QgaW50ZXJuYWwifSwgMTAwLCBudWxsXQ=="}}) })
111
+ return Response.from_hash({ body: JSON.generate({"items" => [], "paging" => {"next"=> "https://api.mailgun.net/v3/thisisatestdomainformailgun.com/events/W3siYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzKzAwOjAwIn0sIHsiYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzKzAwOjAwIn0sIFsiZiJdLCBudWxsLCB7ImFjY291bnQuaWQiOiAiNGU4MjMwZjYxNDc2ZDg2NzEzMDBjNDc2IiwgImRvbWFpbi5uYW1lIjogInRoaXNpc2F0ZXN0ZG9tYWluZm9ybWFpbGd1bi5jb20iLCAic2V2ZXJpdHkiOiAiTk9UIGludGVybmFsIn0sIDEwMCwgbnVsbF0=", "previous"=> "https://api.mailgun.net/v2/thisisatestdomainformailgun.com/events/W3siYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzKzAwOjAwIn0sIHsiYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDdUMDA6NDU6NTEuNzQxODkyKzAwOjAwIn0sIFsicCIsICJmIl0sIG51bGwsIHsiYWNjb3VudC5pZCI6ICI0ZTgyMzBmNjE0NzZkODY3MTMwMGM0NzYiLCAiZG9tYWluLm5hbWUiOiAidGhpc2lzYXRlc3Rkb21haW5mb3JtYWlsZ3VuLmNvbSIsICJzZXZlcml0eSI6ICJOT1QgaW50ZXJuYWwifSwgMTAwLCBudWxsXQ=="}}) })
112
112
  end
113
113
  end
114
114
  end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Mailgun::CommunicationError do
4
+ describe '.new' do
5
+ context "when the Response body doesn't have a `message` property" do
6
+ it "doesn't raise an error" do
7
+ expect do
8
+ described_class.new('Boom!', Mailgun::Response.from_hash({ code: 401, body: '{}' }))
9
+ end.not_to raise_error
10
+ end
11
+
12
+ context "when the Response body has an `Error` property" do
13
+ it "uses the `Error` property as the API message" do
14
+ subject = described_class.new('Boom!', Mailgun::Response.from_hash({ code: 401, body: '{"Error":"unauthorized"}' }))
15
+
16
+ expect(subject.message).to eq("Boom!: unauthorized")
17
+ end
18
+ end
19
+
20
+ context "when the Response body has an `error` property" do
21
+ it "uses the `Error` property as the API message" do
22
+ subject = described_class.new('Boom!', Mailgun::Response.from_hash({ code: 401, body: '{"error":"not found"}' }))
23
+
24
+ expect(subject.message).to eq("Boom!: not found")
25
+ end
26
+ end
27
+
28
+ end
29
+ end
30
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailgun-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.14
4
+ version: 1.2.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mailgun
8
8
  - Travis Swientek
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-02-13 00:00:00.000000000 Z
12
+ date: 2024-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -214,6 +214,7 @@ files:
214
214
  - spec/spec_helper.rb
215
215
  - spec/unit/connection/test_client.rb
216
216
  - spec/unit/events/events_spec.rb
217
+ - spec/unit/exceptions/exceptions_spec.rb
217
218
  - spec/unit/lists/opt_in_handler_spec.rb
218
219
  - spec/unit/mailgun_spec.rb
219
220
  - spec/unit/messages/batch_message_spec.rb
@@ -254,7 +255,7 @@ licenses:
254
255
  metadata:
255
256
  documentation_uri: https://documentation.mailgun.com/
256
257
  source_code_uri: https://github.com/mailgun/mailgun-ruby
257
- post_install_message:
258
+ post_install_message:
258
259
  rdoc_options: []
259
260
  require_paths:
260
261
  - lib
@@ -269,9 +270,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
269
270
  - !ruby/object:Gem::Version
270
271
  version: '0'
271
272
  requirements: []
272
- rubyforge_project:
273
- rubygems_version: 2.7.6
274
- signing_key:
273
+ rubygems_version: 3.4.19
274
+ signing_key:
275
275
  specification_version: 4
276
276
  summary: Mailgun's Official Ruby SDK
277
277
  test_files:
@@ -297,6 +297,7 @@ test_files:
297
297
  - spec/spec_helper.rb
298
298
  - spec/unit/connection/test_client.rb
299
299
  - spec/unit/events/events_spec.rb
300
+ - spec/unit/exceptions/exceptions_spec.rb
300
301
  - spec/unit/lists/opt_in_handler_spec.rb
301
302
  - spec/unit/mailgun_spec.rb
302
303
  - spec/unit/messages/batch_message_spec.rb