emarsys 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +32 -0
  3. data/README.md +42 -38
  4. data/lib/emarsys/client.rb +11 -5
  5. data/lib/emarsys/configuration.rb +54 -0
  6. data/lib/emarsys/data_object.rb +16 -23
  7. data/lib/emarsys/data_objects/condition.rb +2 -2
  8. data/lib/emarsys/data_objects/contact.rb +27 -25
  9. data/lib/emarsys/data_objects/contact_list.rb +8 -8
  10. data/lib/emarsys/data_objects/email.rb +19 -19
  11. data/lib/emarsys/data_objects/email_category.rb +2 -2
  12. data/lib/emarsys/data_objects/event.rb +8 -8
  13. data/lib/emarsys/data_objects/export.rb +4 -4
  14. data/lib/emarsys/data_objects/field.rb +5 -5
  15. data/lib/emarsys/data_objects/file.rb +8 -8
  16. data/lib/emarsys/data_objects/folder.rb +2 -2
  17. data/lib/emarsys/data_objects/form.rb +2 -2
  18. data/lib/emarsys/data_objects/language.rb +2 -2
  19. data/lib/emarsys/data_objects/segment.rb +2 -2
  20. data/lib/emarsys/data_objects/source.rb +6 -6
  21. data/lib/emarsys/error.rb +4 -0
  22. data/lib/emarsys/request.rb +9 -8
  23. data/lib/emarsys/response.rb +9 -11
  24. data/lib/emarsys/version.rb +1 -1
  25. data/lib/emarsys.rb +6 -18
  26. data/spec/emarsys/client_spec.rb +13 -9
  27. data/spec/emarsys/configuration_spec.rb +22 -0
  28. data/spec/emarsys/data_object_spec.rb +11 -11
  29. data/spec/emarsys/data_objects/contact_spec.rb +12 -12
  30. data/spec/emarsys/data_objects/email_launch_status_spec.rb +1 -1
  31. data/spec/emarsys/data_objects/email_spec.rb +5 -5
  32. data/spec/emarsys/data_objects/email_status_code_spec.rb +1 -1
  33. data/spec/emarsys/data_objects/event_spec.rb +3 -3
  34. data/spec/emarsys/data_objects/field_spec.rb +1 -1
  35. data/spec/emarsys/data_objects/file_spec.rb +5 -5
  36. data/spec/emarsys/data_objects/folder_spec.rb +1 -1
  37. data/spec/emarsys/data_objects/source_spec.rb +1 -1
  38. data/spec/emarsys/request_spec.rb +1 -1
  39. data/spec/emarsys/response_spec.rb +17 -12
  40. data/spec/emarsys_spec.rb +1 -7
  41. data/spec/spec_helper.rb +1 -0
  42. metadata +6 -2
@@ -10,7 +10,7 @@ describe Emarsys::Field do
10
10
 
11
11
  it "requests all fields with translate parameter" do
12
12
  expect(
13
- stub_get("field/translate/en") { Emarsys::Field.collection('translate' => 'en') }
13
+ stub_get("field/translate/en") { Emarsys::Field.collection(translate: 'en') }
14
14
  ).to have_been_requested.once
15
15
  end
16
16
  end
@@ -10,23 +10,23 @@ describe Emarsys::File do
10
10
 
11
11
  it "requests all files with parameter" do
12
12
  expect(
13
- stub_get("file/?folder=3") { Emarsys::File.collection(:folder => 3) }
13
+ stub_get("file/?folder=3") { Emarsys::File.collection(folder: 3) }
14
14
  ).to have_been_requested.once
15
15
  end
16
16
  end
17
17
 
18
18
  describe ".create" do
19
19
  it "requests file creation with parameters" do
20
- stub_params = {:filename => 'my_file.jpg', :file => 'base_64_encoded_string'}
20
+ stub_params = {filename: 'my_file.jpg', file: 'base_64_encoded_string'}
21
21
  stub = stub_request(:post, "https://api.emarsys.net/api/v2/file").with(:body => stub_params.to_json).to_return(standard_return_body)
22
- Emarsys::File.create('my_file.jpg', 'base_64_encoded_string')
22
+ Emarsys::File.create(filename: 'my_file.jpg', file: 'base_64_encoded_string')
23
23
  expect(stub).to have_been_requested.once
24
24
  end
25
25
 
26
26
  it "requests file creation with optional folder parameter" do
27
- stub_params = {:filename => 'my_file.jpg', :file => 'base_64_encoded_string', :folder => 3}
27
+ stub_params = {filename: 'my_file.jpg', file: 'base_64_encoded_string', folder: 3}
28
28
  stub = stub_request(:post, "https://api.emarsys.net/api/v2/file").with(:body => stub_params.to_json).to_return(standard_return_body)
29
- Emarsys::File.create('my_file.jpg', 'base_64_encoded_string', 3)
29
+ Emarsys::File.create(filename: 'my_file.jpg', file: 'base_64_encoded_string', folder: 3)
30
30
  expect(stub).to have_been_requested.once
31
31
  end
32
32
  end
@@ -10,7 +10,7 @@ describe Emarsys::Folder do
10
10
 
11
11
  it "requests all folders with parameters" do
12
12
  expect(
13
- stub_get("folder/?folder=3") { Emarsys::Folder.collection(:folder => 3) }
13
+ stub_get("folder/?folder=3") { Emarsys::Folder.collection(folder: 3) }
14
14
  ).to have_been_requested.once
15
15
  end
16
16
  end
@@ -12,7 +12,7 @@ describe Emarsys::Source do
12
12
  describe ".create" do
13
13
  it "requests source creation with parameters" do
14
14
  stub = stub_request(:post, "https://api.emarsys.net/api/v2/source/create").with(:body => {:name => 'test_source'}.to_json).to_return(standard_return_body)
15
- Emarsys::Source.create('test_source')
15
+ Emarsys::Source.create(name: 'test_source')
16
16
  expect(stub).to have_been_requested.once
17
17
  end
18
18
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Emarsys::Request do
4
4
  let(:client) { Emarsys::Client.new }
5
- let(:request) { Emarsys::Request.new('get', 'some-path', {:a => 1}) }
5
+ let(:request) { Emarsys::Request.new(nil, 'get', 'some-path', {:a => 1}) }
6
6
 
7
7
  describe '#initialize' do
8
8
  it 'sets client, path, http_verb and params attributes on initialize' do
@@ -47,30 +47,35 @@ describe Emarsys::Response do
47
47
  end
48
48
  end
49
49
 
50
- describe '#result' do
50
+ describe '#data' do
51
51
  let(:response_string) { "{\"replyCode\":0,\"replyText\":\"Something\",\"data\":1}" }
52
- let(:response) { Emarsys::Response.new(FakeResponse.new(response_string).extend(FakeResponse::JSON)) }
52
+ let(:fake_response) { FakeResponse.new(response_string).extend(FakeResponse::JSON) }
53
+ let(:response) { Emarsys::Response.new(fake_response) }
53
54
 
54
55
  it "returns data if code is 0" do
55
- allow(response).to receive(:code).and_return(0)
56
- expect(response.result).to eq(1)
56
+ allow(fake_response).to receive(:code).and_return(0)
57
+ expect(response.data).to eq(1)
57
58
  end
59
+ end
60
+
61
+ describe 'error response' do
62
+ let(:response_string) { "{\"replyCode\":1,\"replyText\":\"Something\",\"data\":1}" }
63
+ let(:fake_response) { FakeResponse.new(response_string).extend(FakeResponse::JSON) }
64
+ let(:response) { Emarsys::Response.new(fake_response) }
58
65
 
59
66
  it "raises BadRequest error if code is not 0" do
60
- allow(response).to receive(:code).and_return(1)
61
- expect{response.result}.to raise_error(Emarsys::BadRequest)
67
+ allow(fake_response).to receive(:code).and_return(500)
68
+ expect{response}.to raise_error(Emarsys::BadRequest)
62
69
  end
63
70
 
64
71
  it "raises Unauthorized error if http-status is 401" do
65
- allow(response).to receive(:code).and_return(1)
66
- allow(response).to receive(:status).and_return(401)
67
- expect{response.result}.to raise_error(Emarsys::Unauthorized)
72
+ allow(fake_response).to receive(:code).and_return(401)
73
+ expect{response}.to raise_error(Emarsys::Unauthorized)
68
74
  end
69
75
 
70
76
  it "raises TooManyRequests error if http-status is 429" do
71
- allow(response).to receive(:code).and_return(1)
72
- allow(response).to receive(:status).and_return(429)
73
- expect{response.result}.to raise_error(Emarsys::TooManyRequests)
77
+ allow(fake_response).to receive(:code).and_return(429)
78
+ expect{response}.to raise_error(Emarsys::TooManyRequests)
74
79
  end
75
80
  end
76
81
 
data/spec/emarsys_spec.rb CHANGED
@@ -8,15 +8,9 @@ describe Emarsys do
8
8
  Emarsys.configure do |config|
9
9
  config.send("#{key}=", key)
10
10
  end
11
- expect(Emarsys.instance_variable_get(:"@#{key}")).to eq key
11
+ expect(Emarsys::Configuration.for(nil).__send__(key)).to eq key
12
12
  end
13
13
  end
14
14
  end
15
15
 
16
- describe ".api_endpoint getter" do
17
- it "returns specific url as default value" do
18
- Emarsys.api_endpoint = nil
19
- expect(Emarsys.api_endpoint).to eq('https://api.emarsys.net/api/v2')
20
- end
21
- end
22
16
  end
data/spec/spec_helper.rb CHANGED
@@ -13,6 +13,7 @@ def stub_emarsys_authentication!
13
13
  config.api_username = "my_username"
14
14
  config.api_password = "my_password"
15
15
  end
16
+ Emarsys.allow_default_configuration = true
16
17
  end
17
18
 
18
19
  def standard_return_body
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emarsys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Schoppmann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-15 00:00:00.000000000 Z
11
+ date: 2017-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -90,6 +90,7 @@ files:
90
90
  - .gitignore
91
91
  - .rspec
92
92
  - .travis.yml
93
+ - CHANGELOG.md
93
94
  - Gemfile
94
95
  - LICENSE.txt
95
96
  - README.md
@@ -97,6 +98,7 @@ files:
97
98
  - emarsys.gemspec
98
99
  - lib/emarsys.rb
99
100
  - lib/emarsys/client.rb
101
+ - lib/emarsys/configuration.rb
100
102
  - lib/emarsys/country.rb
101
103
  - lib/emarsys/data_object.rb
102
104
  - lib/emarsys/data_objects/condition.rb
@@ -123,6 +125,7 @@ files:
123
125
  - lib/emarsys/response.rb
124
126
  - lib/emarsys/version.rb
125
127
  - spec/emarsys/client_spec.rb
128
+ - spec/emarsys/configuration_spec.rb
126
129
  - spec/emarsys/country_spec.rb
127
130
  - spec/emarsys/data_object_spec.rb
128
131
  - spec/emarsys/data_objects/condition_spec.rb
@@ -174,6 +177,7 @@ specification_version: 4
174
177
  summary: Easy to use ruby library for Emarsys Marketing Suite.
175
178
  test_files:
176
179
  - spec/emarsys/client_spec.rb
180
+ - spec/emarsys/configuration_spec.rb
177
181
  - spec/emarsys/country_spec.rb
178
182
  - spec/emarsys/data_object_spec.rb
179
183
  - spec/emarsys/data_objects/condition_spec.rb