emarsys 0.3.5 → 0.3.6

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
  SHA1:
3
- metadata.gz: 31cbab3211176489903574030ce2a194b17f44aa
4
- data.tar.gz: 3ddda91a55d7a46918cdd26c3fc94f5b52a66918
3
+ metadata.gz: 247a91fcb90eb1b733aeaf081416020ed0a01b55
4
+ data.tar.gz: 6aa2a34c4e5b4c5e6d0a9021665e329c265661b0
5
5
  SHA512:
6
- metadata.gz: 5fb1f42e3cf6ef978fd1d321d0fc8ef406f4b92f928fd52eb7cc9adfda2f07f8014cef71e674a84debb9a2bd8bf8ca895d3e35e02d1203cf32ba181f68beca72
7
- data.tar.gz: f0dd1aa961efbb2d166dc2098a9a654f2789848e1a8fba371fe3a465010ddf87b09e2a413ba33d3b52bdb992d0e4890c8d14b56c718e969f5ea5d8e4d8c24fd9
6
+ metadata.gz: c85175b2fa275793ae0de36b67c81048c15a928e6daa3f073acc58df33cd5a786a250a8fce410b8983db2e0503d1f36d3795a2ba9e2bb03c4c46b128f6d107e4
7
+ data.tar.gz: b9ccae40c2c73ee2eb0c851eb1a8040ab253daed9b673f226ee2f0c96a1228cdca0e9b4b327f1fda41bdc833ca72c91ec23b28d3b299a5502b4b6f23e31604ea
@@ -40,5 +40,13 @@ module Emarsys
40
40
  def calculated_digest
41
41
  Digest::SHA1.hexdigest(header_nonce + header_created + password)
42
42
  end
43
+
44
+ def open_timeout
45
+ Emarsys::Configuration.for(account).open_timeout
46
+ end
47
+
48
+ def read_timeout
49
+ Emarsys::Configuration.for(account).read_timeout
50
+ end
43
51
  end
44
52
  end
@@ -50,5 +50,11 @@ module Emarsys
50
50
  @api_password or raise ArgumentError.new('api_password is not set')
51
51
  end
52
52
 
53
+ # @!attribute open_timeout
54
+ # @return [Integer] Connect Timeout. default: RestClient timeout which is 60s
55
+ # @!attribute read_timeout
56
+ # @return [Integer] Read Timeout. default: RestClient timeout which is 60s
57
+ attr_accessor :open_timeout, :read_timeout
58
+
53
59
  end
54
60
  end
@@ -153,6 +153,24 @@ module Emarsys
153
153
  )
154
154
  post account, "email/getresponses", params
155
155
  end
156
+
157
+ # http://documentation.emarsys.com/resource/developers/endpoints/email/query-responses/
158
+ def responses(type:, start_date: nil, end_date: nil, campaign_id: nil, account: nil)
159
+ params = { type: type }
160
+ if !campaign_id.nil?
161
+ params.merge!(campaign_id: campaign_id)
162
+ elsif !start_date.nil? && !end_date.nil?
163
+ params.merge!(start_date: start_date, end_date: end_date)
164
+ else
165
+ raise "Either campaign_id OR start_date/end_date must be provided"
166
+ end
167
+ post account, "email/responses", params
168
+ end
169
+
170
+ # http://documentation.emarsys.com/resource/developers/endpoints/email/query-responses-result/
171
+ def responses_result(query_id, account: nil)
172
+ get account, "email/#{query_id}/responses", {}
173
+ end
156
174
  end
157
175
  end
158
176
  end
@@ -6,29 +6,32 @@ module Emarsys
6
6
 
7
7
  def initialize(account, http_verb, path, params = {})
8
8
  self.path = path
9
- self.http_verb = http_verb
9
+ self.http_verb = http_verb.to_sym
10
10
  self.params = params
11
11
  self.account = account
12
12
  end
13
13
 
14
14
  def send_request
15
- case http_verb.to_sym
16
- when :post
17
- RestClient.post(emarsys_uri, converted_params.to_json, :content_type => :json, :x_wsse => client.x_wsse_string) do |response, request, result, &block|
18
- Emarsys::Response.new(response)
19
- end
20
- when :put
21
- RestClient.put emarsys_uri, converted_params.to_json, :content_type => :json, :x_wsse => client.x_wsse_string do |response, request, result, &block|
22
- Emarsys::Response.new(response)
23
- end
24
- when :delete
25
- RestClient.delete(emarsys_uri, :content_type => :json, :x_wsse => client.x_wsse_string) do |response, request, result, &block|
26
- Emarsys::Response.new(response)
27
- end
28
- else
29
- RestClient.get(emarsys_uri, :content_type => :json, :x_wsse => client.x_wsse_string) do |response, request, result, &block|
30
- Emarsys::Response.new(response)
31
- end
15
+ args = {
16
+ method: http_verb,
17
+ url: emarsys_uri,
18
+ headers: { content_type: :json, x_wsse: client.x_wsse_string }
19
+ }
20
+
21
+ if client.open_timeout
22
+ args.merge!(open_timeout: client.open_timeout)
23
+ end
24
+
25
+ if client.read_timeout
26
+ args.merge!(read_timeout: client.read_timeout)
27
+ end
28
+
29
+ if [:post, :put].include?(http_verb)
30
+ args.merge!(payload: converted_params.to_json)
31
+ end
32
+
33
+ RestClient::Request.execute(args) do |response, request, result, &block|
34
+ Emarsys::Response.new(response)
32
35
  end
33
36
  end
34
37
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Emarsys
3
- VERSION = "0.3.5"
3
+ VERSION = "0.3.6"
4
4
  end
@@ -91,4 +91,21 @@ describe Emarsys::Email do
91
91
  end
92
92
  end
93
93
 
94
+ describe ".responses" do
95
+ it "queries responses" do
96
+ stub_params = { type: "received", campaign_id: 123 }
97
+ stub = stub_request(:post, "https://api.emarsys.net/api/v2/email/responses").with(:body => stub_params.to_json).to_return(standard_return_body)
98
+ Emarsys::Email.responses(stub_params)
99
+ expect(stub).to have_been_requested.once
100
+ end
101
+ end
102
+
103
+ describe ".responses_result" do
104
+ it "queries responses result" do
105
+ expect(
106
+ stub_get('email/123/responses') { Emarsys::Email.responses_result(123) }
107
+ ).to have_been_requested.once
108
+ end
109
+ end
110
+
94
111
  end
@@ -1,12 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Emarsys::Request do
4
- let(:client) { Emarsys::Client.new }
5
4
  let(:request) { Emarsys::Request.new(nil, 'get', 'some-path', {:a => 1}) }
6
5
 
7
6
  describe '#initialize' do
8
7
  it 'sets client, path, http_verb and params attributes on initialize' do
9
- expect(request.http_verb).to eq('get')
8
+ expect(request.http_verb).to eq(:get)
10
9
  expect(request.path).to eq("some-path")
11
10
  expect(request.params).to eq({:a => 1})
12
11
  end
@@ -24,4 +23,16 @@ describe Emarsys::Request do
24
23
  end
25
24
  end
26
25
 
26
+ describe '#send_request' do
27
+ let(:client) { Emarsys::Client.new }
28
+ it 'sets timeouts if configured' do
29
+ allow(request).to receive(:client).and_return(client)
30
+ allow(client).to receive(:read_timeout).and_return(2)
31
+ expect(RestClient::Request).to receive(:execute).with(
32
+ hash_including(read_timeout: 2)
33
+ )
34
+ request.send_request
35
+ end
36
+ end
37
+
27
38
  end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emarsys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Schoppmann
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-21 00:00:00.000000000 Z
11
+ date: 2017-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rest-client
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - '>='
16
+ - - ">="
18
17
  - !ruby/object:Gem::Version
19
18
  version: '0'
20
- type: :runtime
19
+ name: rest-client
21
20
  prerelease: false
21
+ type: :runtime
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
- - - ~>
30
+ - - "~>"
32
31
  - !ruby/object:Gem::Version
33
32
  version: '1.3'
34
- type: :development
33
+ name: bundler
35
34
  prerelease: false
35
+ type: :development
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
- - - '>='
44
+ - - ">="
46
45
  - !ruby/object:Gem::Version
47
46
  version: '0'
48
- type: :development
47
+ name: rake
49
48
  prerelease: false
49
+ type: :development
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
- - - '>='
58
+ - - ">="
60
59
  - !ruby/object:Gem::Version
61
60
  version: 3.5.0
62
- type: :development
61
+ name: rspec
63
62
  prerelease: false
63
+ type: :development
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.5.0
69
69
  - !ruby/object:Gem::Dependency
70
- name: webmock
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
- - - <
72
+ - - "<"
74
73
  - !ruby/object:Gem::Version
75
74
  version: '2.0'
76
- type: :development
75
+ name: webmock
77
76
  prerelease: false
77
+ type: :development
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - <
80
+ - - "<"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.0'
83
83
  description: A Ruby library for interacting with the Emarsys API.
@@ -87,9 +87,9 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - .gitignore
91
- - .rspec
92
- - .travis.yml
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
93
  - CHANGELOG.md
94
94
  - Gemfile
95
95
  - LICENSE.txt
@@ -155,24 +155,24 @@ homepage: https://github.com/Absolventa/emarsys-rb
155
155
  licenses:
156
156
  - MIT
157
157
  metadata: {}
158
- post_install_message:
158
+ post_install_message:
159
159
  rdoc_options: []
160
160
  require_paths:
161
161
  - lib
162
162
  required_ruby_version: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - '>='
164
+ - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  requirements:
169
- - - '>='
169
+ - - ">="
170
170
  - !ruby/object:Gem::Version
171
171
  version: '0'
172
172
  requirements: []
173
- rubyforge_project:
174
- rubygems_version: 2.0.14.1
175
- signing_key:
173
+ rubyforge_project:
174
+ rubygems_version: 2.6.8
175
+ signing_key:
176
176
  specification_version: 4
177
177
  summary: Easy to use ruby library for Emarsys Marketing Suite.
178
178
  test_files: