emarsys 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +171 -0
- data/Rakefile +7 -0
- data/emarsys.gemspec +25 -0
- data/lib/emarsys.rb +60 -0
- data/lib/emarsys/client.rb +40 -0
- data/lib/emarsys/data_object.rb +78 -0
- data/lib/emarsys/data_objects/condition.rb +20 -0
- data/lib/emarsys/data_objects/contact.rb +121 -0
- data/lib/emarsys/data_objects/contact_list.rb +47 -0
- data/lib/emarsys/data_objects/email.rb +133 -0
- data/lib/emarsys/data_objects/email_category.rb +20 -0
- data/lib/emarsys/data_objects/email_launch_status.rb +38 -0
- data/lib/emarsys/data_objects/email_status_code.rb +39 -0
- data/lib/emarsys/data_objects/event.rb +44 -0
- data/lib/emarsys/data_objects/export.rb +22 -0
- data/lib/emarsys/data_objects/field.rb +39 -0
- data/lib/emarsys/data_objects/file.rb +39 -0
- data/lib/emarsys/data_objects/folder.rb +24 -0
- data/lib/emarsys/data_objects/form.rb +21 -0
- data/lib/emarsys/data_objects/language.rb +20 -0
- data/lib/emarsys/data_objects/segment.rb +21 -0
- data/lib/emarsys/data_objects/source.rb +40 -0
- data/lib/emarsys/error.rb +24 -0
- data/lib/emarsys/extensions.rb +8 -0
- data/lib/emarsys/field_mapping.rb +55 -0
- data/lib/emarsys/params_converter.rb +29 -0
- data/lib/emarsys/request.rb +46 -0
- data/lib/emarsys/response.rb +24 -0
- data/lib/emarsys/version.rb +3 -0
- data/spec/emarsys/client_spec.rb +85 -0
- data/spec/emarsys/data_object_spec.rb +55 -0
- data/spec/emarsys/data_objects/condition_spec.rb +9 -0
- data/spec/emarsys/data_objects/contact_list_spec.rb +9 -0
- data/spec/emarsys/data_objects/contact_spec.rb +79 -0
- data/spec/emarsys/data_objects/email_category_spec.rb +9 -0
- data/spec/emarsys/data_objects/email_launch_status_spec.rb +25 -0
- data/spec/emarsys/data_objects/email_spec.rb +84 -0
- data/spec/emarsys/data_objects/email_status_code_spec.rb +25 -0
- data/spec/emarsys/data_objects/event_spec.rb +23 -0
- data/spec/emarsys/data_objects/export_spec.rb +9 -0
- data/spec/emarsys/data_objects/field_spec.rb +19 -0
- data/spec/emarsys/data_objects/file_spec.rb +29 -0
- data/spec/emarsys/data_objects/folder_spec.rb +13 -0
- data/spec/emarsys/data_objects/form_spec.rb +9 -0
- data/spec/emarsys/data_objects/language_spec.rb +9 -0
- data/spec/emarsys/data_objects/segment_spec.rb +9 -0
- data/spec/emarsys/data_objects/source_spec.rb +25 -0
- data/spec/emarsys/extensions_spec.rb +24 -0
- data/spec/emarsys/field_mapping_spec.rb +14 -0
- data/spec/emarsys/params_converter_spec.rb +52 -0
- data/spec/emarsys/request_spec.rb +27 -0
- data/spec/emarsys/response_spec.rb +35 -0
- data/spec/emarsys_spec.rb +22 -0
- data/spec/spec_helper.rb +28 -0
- metadata +178 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hash do
|
4
|
+
|
5
|
+
context 'extensions on Hash' do
|
6
|
+
|
7
|
+
describe '#stringfy_keys' do
|
8
|
+
it "add stringify_keys method to Hash" do
|
9
|
+
expect(Hash.new).to respond_to(:stringify_keys)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "converts symbol-keys into strings" do
|
13
|
+
hash = {:a => 1, :b => 2}
|
14
|
+
expect(hash.stringify_keys).to eq({'a' => 1, "b" => 2})
|
15
|
+
end
|
16
|
+
|
17
|
+
it "does not touch string-keys" do
|
18
|
+
hash = {:a => 1, 'b' => 2}
|
19
|
+
expect(hash.stringify_keys).to eq({'a' => 1, "b" => 2})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Emarsys::FieldMapping do
|
4
|
+
|
5
|
+
it "defines constant ATTRBUTES " do
|
6
|
+
Emarsys::FieldMapping::ATTRIBUTES.should be_a(Array)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "defines constant ATTRBUTES as an array if hashes" do
|
10
|
+
Emarsys::FieldMapping::ATTRIBUTES.should be_a(Array)
|
11
|
+
Emarsys::FieldMapping::ATTRIBUTES.map{|elem| elem.should be_a(Hash)}
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Emarsys::ParamsConverter do
|
4
|
+
let(:converter) { Emarsys::ParamsConverter.new({}) }
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
attributes = [
|
8
|
+
{:id => 0, :identifier => 'interests', :name => 'Interests'},
|
9
|
+
{:id => 1, :identifier => 'first_name', :name => 'First Name'},
|
10
|
+
{:id => 2, :identifier => 'last_name', :name => 'Last Name'},
|
11
|
+
]
|
12
|
+
stub_const("Emarsys::FieldMapping::ATTRIBUTES", attributes)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'with attributes' do
|
16
|
+
it 'sets params attribute on initialize' do
|
17
|
+
params = {1 => 'Jane', 2 => 'Doe'}
|
18
|
+
params_converter = Emarsys::ParamsConverter.new(params)
|
19
|
+
params_converter.params.should eq(params)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'converting id-based hashes into string keys' do
|
24
|
+
it 'converts all findable string keys' do
|
25
|
+
converter.params = {'first_name' => 'Jane', 'last_name' => 'Doe'}
|
26
|
+
expect(converter.convert_to_ids).to eq({1 => 'Jane', 2 => 'Doe'})
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'does not convert non-findable keys' do
|
30
|
+
converter.params = {'first_name' => 'Jane', 'last_name' => 'Doe', 'something' => 'abc'}
|
31
|
+
expect(converter.convert_to_ids).to eq({1 => 'Jane', 2 => 'Doe', 'something' => 'abc'})
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'converting string-based hashes into id keys' do
|
36
|
+
it 'converts all findable keys' do
|
37
|
+
converter.params = {1 => 'Jane', 2 => 'Doe'}
|
38
|
+
expect(converter.convert_to_identifiers).to eq({'first_name' => 'Jane', 'last_name' => 'Doe'})
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'does not convert 0-key (since ''.to_i, which is 0, is a relevant field at emarsys)' do
|
42
|
+
converter.params = {0 => 'Yeah', 1 => 'Jane', 2 => 'Doe'}
|
43
|
+
expect(converter.convert_to_identifiers).to eq({0 => 'Yeah', 'first_name' => 'Jane', 'last_name' => 'Doe'})
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'does not convert non-findable keys' do
|
47
|
+
converter.params = {1 => 'Jane', 2 => 'Doe', 4 => 'something'}
|
48
|
+
expect(converter.convert_to_identifiers).to eq({'first_name' => 'Jane', 'last_name' => 'Doe', 4 => 'something'})
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Emarsys::Request do
|
4
|
+
let(:client) { Emarsys::Client.new }
|
5
|
+
let(:request) { Emarsys::Request.new('get', 'some-path', {:a => 1}) }
|
6
|
+
|
7
|
+
describe '#initialize' do
|
8
|
+
it 'sets client, path, http_verb and params attributes on initialize' do
|
9
|
+
expect(request.http_verb).to eq('get')
|
10
|
+
expect(request.path).to eq("some-path")
|
11
|
+
expect(request.params).to eq({:a => 1})
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#client' do
|
16
|
+
it "provides a simple client accessor method" do
|
17
|
+
expect(request.client).to be_a(Emarsys::Client)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#emarsys_uri' do
|
22
|
+
it 'concats api_endpoint with path' do
|
23
|
+
expect(request.emarsys_uri).to eq("https://suite5.emarsys.net/api/v2/some-path")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Emarsys::Response do
|
4
|
+
|
5
|
+
describe '#initialize' do
|
6
|
+
it 'sets code, text and data attributes on initialize' do
|
7
|
+
response_string = "{\"replyCode\":0,\"replyText\":\"Something\",\"data\":1}"
|
8
|
+
response = Emarsys::Response.new(response_string)
|
9
|
+
expect(response.code).to eq(0)
|
10
|
+
expect(response.text).to eq("Something")
|
11
|
+
expect(response.data).to eq(1)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#result' do
|
16
|
+
let(:response) { Emarsys::Response.new("{\"replyCode\":0,\"replyText\":\"Something\",\"data\":1}") }
|
17
|
+
|
18
|
+
it "returns data if code is 0" do
|
19
|
+
response.stub(:code).and_return(0)
|
20
|
+
expect(response.result).to eq(1)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "raises BadRequest error if code is not 0" do
|
24
|
+
response.stub(:code).and_return(1)
|
25
|
+
expect{response.result}.to raise_error(Emarsys::BadRequest)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "raises Unauthorized error if http-status is 401" do
|
29
|
+
response.stub(:code).and_return(1)
|
30
|
+
response.stub(:status).and_return(401)
|
31
|
+
expect{response.result}.to raise_error(Emarsys::Unauthorized)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Emarsys do
|
4
|
+
|
5
|
+
describe ".configure" do
|
6
|
+
[:api_endpoint, :api_username, :api_password].each do |key|
|
7
|
+
it "sets the #{key.to_s.gsub('_', ' ')}" do
|
8
|
+
Emarsys.configure do |config|
|
9
|
+
config.send("#{key}=", key)
|
10
|
+
end
|
11
|
+
expect(Emarsys.instance_variable_get(:"@#{key}")).to eq key
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe ".api_endpoint getter" do
|
17
|
+
it "returns specific url as default value" do
|
18
|
+
Emarsys.api_endpoint = nil
|
19
|
+
Emarsys.api_endpoint.should eq('https://suite5.emarsys.net/api/v2')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'emarsys'
|
2
|
+
require 'rspec'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
|
5
|
+
WebMock.disable_net_connect!
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
|
10
|
+
config.before(:all) { stub_emarsys_authentication! }
|
11
|
+
end
|
12
|
+
|
13
|
+
def stub_emarsys_authentication!
|
14
|
+
Emarsys.configure do |config|
|
15
|
+
config.api_username = "my_username"
|
16
|
+
config.api_password = "my_password"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def standard_return_body
|
21
|
+
{:body => "{\"replyCode\":0,\"replyText\":\"Something\",\"data\":1}"}
|
22
|
+
end
|
23
|
+
|
24
|
+
def stub_get(path, &block)
|
25
|
+
stub = stub_request(:get, "https://suite5.emarsys.net/api/v2/#{path}").to_return(standard_return_body)
|
26
|
+
yield if block_given?
|
27
|
+
stub
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: emarsys
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Daniel Schoppmann
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.3'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.3'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: A Ruby library for interacting with the Emarsys API.
|
63
|
+
email:
|
64
|
+
- daniel.schoppmann@absolventa.de
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- emarsys.gemspec
|
76
|
+
- lib/emarsys.rb
|
77
|
+
- lib/emarsys/client.rb
|
78
|
+
- lib/emarsys/data_object.rb
|
79
|
+
- lib/emarsys/data_objects/condition.rb
|
80
|
+
- lib/emarsys/data_objects/contact.rb
|
81
|
+
- lib/emarsys/data_objects/contact_list.rb
|
82
|
+
- lib/emarsys/data_objects/email.rb
|
83
|
+
- lib/emarsys/data_objects/email_category.rb
|
84
|
+
- lib/emarsys/data_objects/email_launch_status.rb
|
85
|
+
- lib/emarsys/data_objects/email_status_code.rb
|
86
|
+
- lib/emarsys/data_objects/event.rb
|
87
|
+
- lib/emarsys/data_objects/export.rb
|
88
|
+
- lib/emarsys/data_objects/field.rb
|
89
|
+
- lib/emarsys/data_objects/file.rb
|
90
|
+
- lib/emarsys/data_objects/folder.rb
|
91
|
+
- lib/emarsys/data_objects/form.rb
|
92
|
+
- lib/emarsys/data_objects/language.rb
|
93
|
+
- lib/emarsys/data_objects/segment.rb
|
94
|
+
- lib/emarsys/data_objects/source.rb
|
95
|
+
- lib/emarsys/error.rb
|
96
|
+
- lib/emarsys/extensions.rb
|
97
|
+
- lib/emarsys/field_mapping.rb
|
98
|
+
- lib/emarsys/params_converter.rb
|
99
|
+
- lib/emarsys/request.rb
|
100
|
+
- lib/emarsys/response.rb
|
101
|
+
- lib/emarsys/version.rb
|
102
|
+
- spec/emarsys/client_spec.rb
|
103
|
+
- spec/emarsys/data_object_spec.rb
|
104
|
+
- spec/emarsys/data_objects/condition_spec.rb
|
105
|
+
- spec/emarsys/data_objects/contact_list_spec.rb
|
106
|
+
- spec/emarsys/data_objects/contact_spec.rb
|
107
|
+
- spec/emarsys/data_objects/email_category_spec.rb
|
108
|
+
- spec/emarsys/data_objects/email_launch_status_spec.rb
|
109
|
+
- spec/emarsys/data_objects/email_spec.rb
|
110
|
+
- spec/emarsys/data_objects/email_status_code_spec.rb
|
111
|
+
- spec/emarsys/data_objects/event_spec.rb
|
112
|
+
- spec/emarsys/data_objects/export_spec.rb
|
113
|
+
- spec/emarsys/data_objects/field_spec.rb
|
114
|
+
- spec/emarsys/data_objects/file_spec.rb
|
115
|
+
- spec/emarsys/data_objects/folder_spec.rb
|
116
|
+
- spec/emarsys/data_objects/form_spec.rb
|
117
|
+
- spec/emarsys/data_objects/language_spec.rb
|
118
|
+
- spec/emarsys/data_objects/segment_spec.rb
|
119
|
+
- spec/emarsys/data_objects/source_spec.rb
|
120
|
+
- spec/emarsys/extensions_spec.rb
|
121
|
+
- spec/emarsys/field_mapping_spec.rb
|
122
|
+
- spec/emarsys/params_converter_spec.rb
|
123
|
+
- spec/emarsys/request_spec.rb
|
124
|
+
- spec/emarsys/response_spec.rb
|
125
|
+
- spec/emarsys_spec.rb
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
homepage: http://www.absolventa.de
|
128
|
+
licenses:
|
129
|
+
- MIT
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
136
|
+
requirements:
|
137
|
+
- - ! '>='
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 1.8.25
|
149
|
+
signing_key:
|
150
|
+
specification_version: 3
|
151
|
+
summary: Easy to use ruby library for Emarsys Marketing Suite.
|
152
|
+
test_files:
|
153
|
+
- spec/emarsys/client_spec.rb
|
154
|
+
- spec/emarsys/data_object_spec.rb
|
155
|
+
- spec/emarsys/data_objects/condition_spec.rb
|
156
|
+
- spec/emarsys/data_objects/contact_list_spec.rb
|
157
|
+
- spec/emarsys/data_objects/contact_spec.rb
|
158
|
+
- spec/emarsys/data_objects/email_category_spec.rb
|
159
|
+
- spec/emarsys/data_objects/email_launch_status_spec.rb
|
160
|
+
- spec/emarsys/data_objects/email_spec.rb
|
161
|
+
- spec/emarsys/data_objects/email_status_code_spec.rb
|
162
|
+
- spec/emarsys/data_objects/event_spec.rb
|
163
|
+
- spec/emarsys/data_objects/export_spec.rb
|
164
|
+
- spec/emarsys/data_objects/field_spec.rb
|
165
|
+
- spec/emarsys/data_objects/file_spec.rb
|
166
|
+
- spec/emarsys/data_objects/folder_spec.rb
|
167
|
+
- spec/emarsys/data_objects/form_spec.rb
|
168
|
+
- spec/emarsys/data_objects/language_spec.rb
|
169
|
+
- spec/emarsys/data_objects/segment_spec.rb
|
170
|
+
- spec/emarsys/data_objects/source_spec.rb
|
171
|
+
- spec/emarsys/extensions_spec.rb
|
172
|
+
- spec/emarsys/field_mapping_spec.rb
|
173
|
+
- spec/emarsys/params_converter_spec.rb
|
174
|
+
- spec/emarsys/request_spec.rb
|
175
|
+
- spec/emarsys/response_spec.rb
|
176
|
+
- spec/emarsys_spec.rb
|
177
|
+
- spec/spec_helper.rb
|
178
|
+
has_rdoc:
|