mailjet 1.5.1 → 1.5.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.
- checksums.yaml +4 -4
- data/lib/mailjet/connection.rb +14 -11
- data/lib/mailjet/resource.rb +15 -11
- data/lib/mailjet/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e5aca2e6992e3629225e95b54f92c345b9a425a
|
4
|
+
data.tar.gz: eb1f16741cb17b0a1db5303e29fd57fc853c44ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48c6bd96487aa123c5a201157e4d1d199325ebe582c54423bad89b0ad58c5c9d1f3f5d692ff94257ecd6745625ab1939dfb908cf81f55258a6081125a9d0747b
|
7
|
+
data.tar.gz: 54836996f885ea2286b23ff127d09913722fac7819764436e9f757cbd93bd8d4f0374fd207615438ef417acc1199d575896c8b91688198057abad0c81d43bf30
|
data/lib/mailjet/connection.rb
CHANGED
@@ -6,7 +6,7 @@ require 'json'
|
|
6
6
|
module Mailjet
|
7
7
|
class Connection
|
8
8
|
|
9
|
-
attr_accessor :adapter, :public_operations, :read_only
|
9
|
+
attr_accessor :adapter, :public_operations, :read_only, :perform_api_call
|
10
10
|
alias :read_only? :read_only
|
11
11
|
|
12
12
|
delegate :options, :concat_urls, :url, to: :adapter
|
@@ -37,36 +37,39 @@ module Mailjet
|
|
37
37
|
self.read_only = options[:read_only]
|
38
38
|
# self.adapter = adapter_class.new(end_point, options.merge(user: api_key, password: secret_key, :verify_ssl => false, content_type: 'application/json'))
|
39
39
|
self.adapter = adapter_class.new(end_point, options.merge(user: api_key, password: secret_key, content_type: 'application/json'))
|
40
|
+
self.perform_api_call = options.key?(:perform_api_call) ? options[:perform_api_call] : true
|
40
41
|
end
|
41
42
|
|
42
|
-
def get(additional_headers = {},
|
43
|
-
handle_api_call(:get, additional_headers,
|
43
|
+
def get(additional_headers = {}, &block)
|
44
|
+
handle_api_call(:get, additional_headers, &block)
|
44
45
|
end
|
45
46
|
|
46
|
-
def post(payload, additional_headers = {},
|
47
|
-
handle_api_call(:post, additional_headers, payload,
|
47
|
+
def post(payload, additional_headers = {}, &block)
|
48
|
+
handle_api_call(:post, additional_headers, payload, &block)
|
48
49
|
end
|
49
50
|
|
50
|
-
def put(payload, additional_headers = {},
|
51
|
-
handle_api_call(:put, additional_headers, payload,
|
51
|
+
def put(payload, additional_headers = {}, &block)
|
52
|
+
handle_api_call(:put, additional_headers, payload, &block)
|
52
53
|
end
|
53
54
|
|
54
|
-
def delete(additional_headers = {},
|
55
|
-
handle_api_call(:delete, additional_headers,
|
55
|
+
def delete(additional_headers = {}, &block)
|
56
|
+
handle_api_call(:delete, additional_headers, &block)
|
56
57
|
end
|
57
58
|
|
58
59
|
private
|
59
60
|
|
60
|
-
def handle_api_call(method, additional_headers = {}, payload = {},
|
61
|
+
def handle_api_call(method, additional_headers = {}, payload = {}, &block)
|
61
62
|
formatted_payload = (additional_headers[:content_type] == :json) ? payload.to_json : payload
|
62
63
|
raise Mailjet::MethodNotAllowed unless method_allowed(method)
|
63
64
|
|
64
|
-
if perform_api_call
|
65
|
+
if self.perform_api_call
|
65
66
|
if [:get, :delete].include?(method)
|
66
67
|
@adapter.send(method, additional_headers, &block)
|
67
68
|
else
|
68
69
|
@adapter.send(method, formatted_payload, additional_headers, &block)
|
69
70
|
end
|
71
|
+
else
|
72
|
+
return {'Count': 0, 'Data': [mock_api_call: true], 'Total': 0}.to_json
|
70
73
|
end
|
71
74
|
rescue RestClient::Exception => e
|
72
75
|
handle_exception(e, additional_headers, formatted_payload)
|
data/lib/mailjet/resource.rb
CHANGED
@@ -36,7 +36,8 @@ module Mailjet
|
|
36
36
|
options[:api_key] || Mailjet.config.api_key,
|
37
37
|
options[:secret_key] || Mailjet.config.secret_key,
|
38
38
|
public_operations: public_operations,
|
39
|
-
read_only: read_only
|
39
|
+
read_only: read_only,
|
40
|
+
perform_api_call: options[:perform_api_call])
|
40
41
|
end
|
41
42
|
|
42
43
|
def self.default_headers
|
@@ -57,14 +58,14 @@ module Mailjet
|
|
57
58
|
def all(params = {}, options = {})
|
58
59
|
opts = change_resource_path(options)
|
59
60
|
params = format_params(params)
|
60
|
-
response = connection(opts).get(default_headers.merge(params: params)
|
61
|
+
response = connection(opts).get(default_headers.merge(params: params))
|
61
62
|
attribute_array = parse_api_json(response)
|
62
63
|
attribute_array.map{ |attributes| instanciate_from_api(attributes) }
|
63
64
|
end
|
64
65
|
|
65
66
|
def count(options = {})
|
66
67
|
opts = change_resource_path(options)
|
67
|
-
response_json = connection(opts).get(default_headers.merge(params: {limit: 1, countrecords: 1})
|
68
|
+
response_json = connection(opts).get(default_headers.merge(params: {limit: 1, countrecords: 1}))
|
68
69
|
response_hash = ActiveSupport::JSON.decode(response_json)
|
69
70
|
response_hash['Total']
|
70
71
|
end
|
@@ -74,7 +75,7 @@ module Mailjet
|
|
74
75
|
opts = change_resource_path(options)
|
75
76
|
self.resource_path = create_action_resource_path(id, job_id) if self.action
|
76
77
|
#
|
77
|
-
attributes = parse_api_json(connection(opts)[id].get(default_headers
|
78
|
+
attributes = parse_api_json(connection(opts)[id].get(default_headers)).first
|
78
79
|
instanciate_from_api(attributes)
|
79
80
|
|
80
81
|
rescue Mailjet::ApiError => e
|
@@ -111,7 +112,7 @@ module Mailjet
|
|
111
112
|
# if action method, ammend url to appropriate id
|
112
113
|
opts = change_resource_path(options)
|
113
114
|
self.resource_path = create_action_resource_path(id) if self.action
|
114
|
-
connection(
|
115
|
+
connection(opts)[id].delete(default_headers)
|
115
116
|
end
|
116
117
|
|
117
118
|
def instanciate_from_api(attributes = {})
|
@@ -120,6 +121,7 @@ module Mailjet
|
|
120
121
|
|
121
122
|
def parse_api_json(response_json)
|
122
123
|
response_hash = ActiveSupport::JSON.decode(response_json)
|
124
|
+
|
123
125
|
#Take the response from the API and put it through a method -- taken from the ActiveSupport library -- which converts
|
124
126
|
#the date-time from "2014-05-19T15:31:09Z" to "Mon, 19 May 2014 15:31:09 +0000" format.
|
125
127
|
response_hash = convert_dates_from(response_hash)
|
@@ -218,7 +220,7 @@ module Mailjet
|
|
218
220
|
perform_api_call = options[:perform_api_call]
|
219
221
|
end
|
220
222
|
if options.key?(:url)
|
221
|
-
url = options[
|
223
|
+
url = options[:url]
|
222
224
|
end
|
223
225
|
end
|
224
226
|
ret = {version: ver, url: url, perform_api_call: perform_api_call}
|
@@ -243,16 +245,18 @@ module Mailjet
|
|
243
245
|
attributes[:persisted]
|
244
246
|
end
|
245
247
|
|
246
|
-
def save(options)
|
248
|
+
def save(options = {})
|
249
|
+
opts = self.class.change_resource_path(options)
|
250
|
+
|
247
251
|
if persisted?
|
248
252
|
# case where the entity is updated
|
249
|
-
response = connection(
|
253
|
+
response = connection(opts)[attributes[:id]].put(formatted_payload, default_headers)
|
250
254
|
else
|
251
255
|
# case where the entity is created
|
252
|
-
response = connection(
|
256
|
+
response = connection(opts).post(formatted_payload, default_headers)
|
253
257
|
end
|
254
258
|
|
255
|
-
if
|
259
|
+
if opts[:perform_api_call] && !persisted?
|
256
260
|
# get attributes only for entity creation
|
257
261
|
self.attributes = if self.resource_path == 'send'
|
258
262
|
ActiveSupport::JSON.decode(response)
|
@@ -271,7 +275,7 @@ module Mailjet
|
|
271
275
|
end
|
272
276
|
end
|
273
277
|
|
274
|
-
def save!(options)
|
278
|
+
def save!(options = {})
|
275
279
|
save(options) || raise(StandardError.new("Resource not persisted"))
|
276
280
|
end
|
277
281
|
|
data/lib/mailjet/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailjet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Nappy
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2017-05
|
14
|
+
date: 2017-06-05 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|