ofsys 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Rakefile +23 -0
- data/lib/ofsys/config.rb +13 -0
- data/lib/ofsys/request/base.rb +72 -0
- data/lib/ofsys/request/contacts_delete.rb +7 -0
- data/lib/ofsys/request/contacts_merge.rb +7 -0
- data/lib/ofsys/request/sendings_send_single.rb +7 -0
- data/lib/ofsys/request.rb +9 -0
- data/lib/ofsys/version.rb +3 -0
- data/lib/ofsys.rb +5 -0
- data/spec/config_spec.rb +29 -0
- data/spec/contacts_delete_spec.rb +37 -0
- data/spec/contacts_merge_spec.rb +61 -0
- data/spec/send_single_spec.rb +46 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/configure_helper.rb +9 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f999d360b1138a8187c4c4692ddd0f3bb57e5aff
|
4
|
+
data.tar.gz: bef1207e4b668e54f1aacec44d687e558b7608bf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 241eeb2fe1c96bbee9cea8780f9bfd217603627fed69b0b5cdbd0cd2f5657f20309d01e05723c2b4627245df02521b6adaecdfb6f2ecfe7eeae261abacdd30ac
|
7
|
+
data.tar.gz: 68e8c432d75459da5784b9648eac16c5abc81cf8c69b6062ac931489bd293803529036fe7cdb6711d6dc6f935b2f4503164351924c48daf981d5e866e60b0700
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Ofsys'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'rspec/core'
|
18
|
+
require 'rspec/core/rake_task'
|
19
|
+
|
20
|
+
desc 'Run all specs in spec directory (excluding plugin specs)'
|
21
|
+
RSpec::Core::RakeTask.new(:spec)
|
22
|
+
|
23
|
+
task default: :spec
|
data/lib/ofsys/config.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'yajl'
|
2
|
+
|
3
|
+
module Ofsys
|
4
|
+
module Request
|
5
|
+
class Base
|
6
|
+
class FailedError < RuntimeError; end
|
7
|
+
|
8
|
+
def initialize(config = Ofsys.config)
|
9
|
+
@id_key = config.id_key
|
10
|
+
@key = config.key
|
11
|
+
@id_project = config.id_project
|
12
|
+
end
|
13
|
+
|
14
|
+
def perform(params = {})
|
15
|
+
request.body = body(params)
|
16
|
+
result_body = http.request(request).body
|
17
|
+
decode_result(result_body)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
ENDPOINT_BASE = 'https://ofsys.com/webservices/ofc4'.freeze
|
23
|
+
|
24
|
+
def request
|
25
|
+
@request ||= Net::HTTP::Post.new(uri.request_uri)
|
26
|
+
end
|
27
|
+
|
28
|
+
def uri
|
29
|
+
@uri ||= URI.parse(self.class::ENDPOINT)
|
30
|
+
end
|
31
|
+
|
32
|
+
def http
|
33
|
+
@http ||= build_http
|
34
|
+
end
|
35
|
+
|
36
|
+
def build_http
|
37
|
+
Net::HTTP.new(uri.host, uri.port).tap do |http|
|
38
|
+
http.use_ssl = true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def body(source_params)
|
43
|
+
params = merge_auth(source_params)
|
44
|
+
to_json(params)
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_json(hash)
|
48
|
+
::Yajl::Encoder.encode(hash)
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_hash(text)
|
52
|
+
::Yajl::Parser.parse(text)
|
53
|
+
end
|
54
|
+
|
55
|
+
def merge_auth(source_params)
|
56
|
+
source_params.merge!(
|
57
|
+
AuthKey: {
|
58
|
+
Key: @key,
|
59
|
+
idKey: @id_key
|
60
|
+
},
|
61
|
+
idProject: @id_project
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
def decode_result(body)
|
66
|
+
result = to_hash(body)
|
67
|
+
fail FailedError.new(body) unless result['Success']
|
68
|
+
result
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/ofsys.rb
ADDED
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ofsys do
|
4
|
+
context 'known keys' do
|
5
|
+
it 'assigns config variables' do
|
6
|
+
described_class.configure do |config|
|
7
|
+
config.id_key = 'key1'
|
8
|
+
config.key = 'key2'
|
9
|
+
config.id_project = 'key3'
|
10
|
+
end
|
11
|
+
|
12
|
+
expect(described_class.config.id_key).to eq('key1')
|
13
|
+
expect(described_class.config.key).to eq('key2')
|
14
|
+
expect(described_class.config.id_project).to eq('key3')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'unknown key' do
|
19
|
+
subject do
|
20
|
+
described_class.configure do |config|
|
21
|
+
config.unknown_key = 'key1'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'raise error' do
|
26
|
+
expect { subject }.to raise_error(NoMethodError)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ofsys::Request::ContactsDelete do
|
4
|
+
include ConfigureHelper
|
5
|
+
before(:each) { configure_defaults }
|
6
|
+
|
7
|
+
let(:data) do
|
8
|
+
{
|
9
|
+
Clause: {
|
10
|
+
:'$type' => 'FieldClause',
|
11
|
+
Field: {
|
12
|
+
Name: 'f_EMail'
|
13
|
+
},
|
14
|
+
TypeOperator: 'Equal',
|
15
|
+
ComparisonValue: 'aishek@gmail.com'
|
16
|
+
},
|
17
|
+
MaxRows: 1
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:result) do
|
22
|
+
{
|
23
|
+
'Success' => true,
|
24
|
+
'ErrorCode' => nil,
|
25
|
+
'ErrorMessage' => nil,
|
26
|
+
'DeletedRecords' => 1,
|
27
|
+
'idRequest' => 18946891,
|
28
|
+
'Trace' => "Beginning request (04:26:51)\r\n\tchecking OFSYS User authentication: False\r\n\tchecking Dialog Insight administrator: False\r\nTargeted service: Contacts.Delete\r\nDeserializing JSON...\r\nDeserializing JSON completed\r\nValidating parameters...\r\nValidating parameterscompleted with success\r\nExecuting method...\r\nExecuting method completed with success"
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'performs correct request with passed data' do
|
33
|
+
VCR.use_cassette('contacts_delete') do
|
34
|
+
expect(described_class.new.perform(data)).to eq(result)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ofsys::Request::ContactsMerge do
|
4
|
+
include ConfigureHelper
|
5
|
+
before(:each) { configure_defaults }
|
6
|
+
|
7
|
+
let(:data) do
|
8
|
+
{
|
9
|
+
Records: [
|
10
|
+
{
|
11
|
+
ID: {
|
12
|
+
key_f_EMail: 'aishek@gmail.com'
|
13
|
+
},
|
14
|
+
Data: {
|
15
|
+
f_EMail: 'aishek@gmail.com'
|
16
|
+
}
|
17
|
+
}
|
18
|
+
],
|
19
|
+
MergeOptions: {
|
20
|
+
AllowInsert: true,
|
21
|
+
AllowUpdate: true,
|
22
|
+
SkipDuplicateRecords: false,
|
23
|
+
SkipUnmatchedRecords: false,
|
24
|
+
ReturnRecordsOnSuccess: false,
|
25
|
+
ReturnRecordsOnError: false,
|
26
|
+
FieldOptions: nil
|
27
|
+
}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:result) do
|
32
|
+
{
|
33
|
+
'Success' => true,
|
34
|
+
'ErrorCode' => nil,
|
35
|
+
'ErrorMessage' => nil,
|
36
|
+
'CreatedRecords' => 0,
|
37
|
+
'UpdatedRecords' => 1,
|
38
|
+
'Records' => [
|
39
|
+
{
|
40
|
+
'IdRecord' => 15,
|
41
|
+
'Status' => 'Updated',
|
42
|
+
'ValidationResult' => 'OK',
|
43
|
+
'Message' => nil,
|
44
|
+
'ID' => {
|
45
|
+
'key_f_EMail' => 'aishek@gmail.com'
|
46
|
+
},
|
47
|
+
'Data' => nil,
|
48
|
+
'Record' => nil
|
49
|
+
}
|
50
|
+
],
|
51
|
+
'idRequest' => 18945355,
|
52
|
+
'Trace' => "Beginning request (04:15:25)\r\n\tchecking OFSYS User authentication: False\r\n\tchecking Dialog Insight administrator: False\r\nTargeted service: Contacts.Merge\r\nDeserializing JSON...\r\nDeserializing JSON completed\r\nValidating parameters...\r\nRecords count: 1\r\nRecords candidates for insert: 1\r\nRecords candidates for update: 1\r\nValidating parameterscompleted with success\r\nExecuting method...\r\n\tRecords bulked: 1\r\n\tRecords matched by PK: 1\r\n\tRecords dupes, source versus source: 0\r\n\tRecords dupes, source versus target: 0\r\n\tRecords updated: 1\r\n\tRecords created: 0\r\n\tEMails changed: 0\r\n\tOptins field changed: no flag involved\r\nExecuting method completed with success"
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'performs correct request with passed data' do
|
57
|
+
VCR.use_cassette('contacts_merge') do
|
58
|
+
expect(described_class.new.perform(data)).to eq(result)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ofsys::Request::SendingsSendSingle do
|
4
|
+
include ConfigureHelper
|
5
|
+
before(:each) { configure_defaults }
|
6
|
+
|
7
|
+
let(:data) do
|
8
|
+
{
|
9
|
+
idMessage: 538731,
|
10
|
+
contactFilter: {
|
11
|
+
Mode: 'Clauses',
|
12
|
+
TableClauses: [
|
13
|
+
{
|
14
|
+
TableCode: 'Contact',
|
15
|
+
Clause: {
|
16
|
+
:'$type' => 'FieldClause',
|
17
|
+
Field: {
|
18
|
+
TableCode: 'Contact',
|
19
|
+
Name: 'f_EMail'
|
20
|
+
},
|
21
|
+
TypeOperator: 'Equal',
|
22
|
+
ComparisonValue: 'ab+45@cifronomika.ru'
|
23
|
+
}
|
24
|
+
}
|
25
|
+
]
|
26
|
+
}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:result) do
|
31
|
+
{
|
32
|
+
'Success' => true,
|
33
|
+
'ErrorCode' => nil,
|
34
|
+
'ErrorMessage' => nil,
|
35
|
+
'AffectedContacts' => 1,
|
36
|
+
'idRequest' => 18947426,
|
37
|
+
'Trace' => "Beginning request (04:30:24)\r\n\tchecking OFSYS User authentication: False\r\n\tchecking Dialog Insight administrator: False\r\nTargeted service: Sendings.SendSingle\r\nDeserializing JSON...\r\nDeserializing JSON completed\r\nValidating parameters...\r\nValidating parameterscompleted with success\r\nExecuting method...\r\nExecuting method completed with success"
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'performs correct request with passed data' do
|
42
|
+
VCR.use_cassette('sendings_send_single') do
|
43
|
+
expect(described_class.new.perform(data)).to eq(result)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
|
3
|
+
require 'ofsys'
|
4
|
+
|
5
|
+
require 'coveralls'
|
6
|
+
Coveralls.wear!
|
7
|
+
|
8
|
+
# Load support files
|
9
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
10
|
+
|
11
|
+
require 'vcr'
|
12
|
+
VCR.configure do |c|
|
13
|
+
c.cassette_library_dir = "#{File.dirname(__FILE__)}/fixtures/vcr_cassettes"
|
14
|
+
c.hook_into :webmock
|
15
|
+
c.allow_http_connections_when_no_cassette = true
|
16
|
+
end
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
20
|
+
config.run_all_when_everything_filtered = true
|
21
|
+
config.order = 'random'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ofsys
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexandr Borisov
|
8
|
+
- Sergey Zyablitsky
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-12-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: yajl-ruby
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: webmock
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: vcr
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: coveralls
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rubocop
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
description: Ofsys.com API wrapper for Ruby language
|
99
|
+
email:
|
100
|
+
- aishek@gmail.com
|
101
|
+
- sergey.zyablitsky@gmail.com
|
102
|
+
executables: []
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- Rakefile
|
107
|
+
- lib/ofsys.rb
|
108
|
+
- lib/ofsys/config.rb
|
109
|
+
- lib/ofsys/request.rb
|
110
|
+
- lib/ofsys/request/base.rb
|
111
|
+
- lib/ofsys/request/contacts_delete.rb
|
112
|
+
- lib/ofsys/request/contacts_merge.rb
|
113
|
+
- lib/ofsys/request/sendings_send_single.rb
|
114
|
+
- lib/ofsys/version.rb
|
115
|
+
- spec/config_spec.rb
|
116
|
+
- spec/contacts_delete_spec.rb
|
117
|
+
- spec/contacts_merge_spec.rb
|
118
|
+
- spec/send_single_spec.rb
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
- spec/support/configure_helper.rb
|
121
|
+
homepage: https://github.com/the-furnish/ofsys
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.2.2
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Provides interface for ofsys.com (inteligentemails.com) service API
|
145
|
+
test_files:
|
146
|
+
- spec/contacts_delete_spec.rb
|
147
|
+
- spec/config_spec.rb
|
148
|
+
- spec/spec_helper.rb
|
149
|
+
- spec/support/configure_helper.rb
|
150
|
+
- spec/contacts_merge_spec.rb
|
151
|
+
- spec/send_single_spec.rb
|
152
|
+
has_rdoc:
|