basecrm 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -3
- data/lib/basecrm.rb +1 -0
- data/lib/basecrm/models/meta.rb +11 -0
- data/lib/basecrm/services/sync_service.rb +9 -3
- data/lib/basecrm/sync.rb +2 -2
- data/lib/basecrm/version.rb +1 -1
- data/spec/basecrm/sync_spec.rb +8 -7
- data/spec/services/sync_service_spec.rb +8 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e150ccbdeb24176553161e55e95a985d0355519d
|
4
|
+
data.tar.gz: c3425ea82d471eb5c98fd998f3fc4107afdae7d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be39ed5e4cbdede0f58e3ff0b0ae0a0a15d84107f12a72f2cf708bc1b74b2df6065e839ca0f433a0d3a9958d1725ee8a0334cb55c84747a901a10b668088c30d
|
7
|
+
data.tar.gz: f8fd742d3ba87a17968f40fdb1eea93a0884a1dd8c9a79e32ec5001cc177ab7f54a1011050ea997223cb278998e6c9b77e6444b6881ddd299e8eaa82f73d3ab5
|
data/README.md
CHANGED
@@ -135,12 +135,18 @@ sync = BaseCRM::Sync.new(client: client, device_uuid: "<YOUR_DEVICES_UUID>")
|
|
135
135
|
Now all you have to do is to call `#fetch` method and pass a block that you might use to store fetched data to a database.
|
136
136
|
|
137
137
|
```ruby
|
138
|
-
sync.fetch do |
|
139
|
-
|
138
|
+
sync.fetch do |meta, resource|
|
139
|
+
options = {
|
140
|
+
table: meta.type,
|
141
|
+
statement: meta.sync.event_type,
|
142
|
+
properties: resource
|
143
|
+
}
|
144
|
+
|
145
|
+
DB.execute(options) ? meta.sync.ack : meta.sync.nack
|
140
146
|
end
|
141
147
|
```
|
142
148
|
|
143
|
-
Notice that you must call either `#ack` or `#nack` method
|
149
|
+
Notice that you must call either `#ack` or `#nack` method on an instance of `BaseCRM::SyncMeta`.
|
144
150
|
|
145
151
|
## Resources and actions
|
146
152
|
|
data/lib/basecrm.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
module BaseCRM
|
2
|
+
class Meta < Model
|
3
|
+
# @attribute [r] type
|
4
|
+
# @return [String] An entity type.
|
5
|
+
# attr_reader :type
|
6
|
+
|
7
|
+
# @attribute [r] sync
|
8
|
+
# @return [SyncMeta] An entity which represents sync metadata. See below for it's attributes.
|
9
|
+
# attr_reader :sync
|
10
|
+
end
|
11
|
+
end
|
@@ -33,7 +33,7 @@ module BaseCRM
|
|
33
33
|
# @param device_uuid [String] Device's UUID for which to perform synchronization
|
34
34
|
# @param session_id [String] Unique identifier of a synchronization session.
|
35
35
|
# @param queue [String|Symbol] Queue name.
|
36
|
-
# @return [Array<Array<
|
36
|
+
# @return [Array<Array<Meta, Model>>] The list of sync's metadata associated with data and data.
|
37
37
|
def fetch(device_uuid, session_id, queue='main')
|
38
38
|
validate_device!(device_uuid)
|
39
39
|
raise ArgumentError, "session_id must not be nil nor empty" unless session_id && !session_id.strip.empty?
|
@@ -44,7 +44,8 @@ module BaseCRM
|
|
44
44
|
|
45
45
|
root[:items].map do |item|
|
46
46
|
klass = classify_type(item[:meta][:type])
|
47
|
-
|
47
|
+
next unless klass
|
48
|
+
[build_meta(item[:meta]), klass.new(item[:data])]
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
@@ -82,7 +83,8 @@ module BaseCRM
|
|
82
83
|
end
|
83
84
|
|
84
85
|
def classify_type(type)
|
85
|
-
|
86
|
+
return nil unless type && !type.empty?
|
87
|
+
BaseCRM.const_get(type.split('_').map(&:capitalize).join) rescue nil
|
86
88
|
end
|
87
89
|
|
88
90
|
def build_session(root)
|
@@ -90,5 +92,9 @@ module BaseCRM
|
|
90
92
|
session_data[:queues] = session_data[:queues].map { |queue| SyncQueue.new(queue[:data]) }
|
91
93
|
SyncSession.new(session_data)
|
92
94
|
end
|
95
|
+
|
96
|
+
def build_meta(meta)
|
97
|
+
Meta.new(meta.merge(sync: SyncMeta.new(meta[:sync])))
|
98
|
+
end
|
93
99
|
end
|
94
100
|
end
|
data/lib/basecrm/sync.rb
CHANGED
@@ -28,8 +28,8 @@ module BaseCRM
|
|
28
28
|
#
|
29
29
|
# client = BaseCRM::Client.new(access_token: "<YOUR_ACCESS_TOKEN>")
|
30
30
|
# sync = BaseCRM::Sync.new(client: client, device_uuid: "<YOUR_DEVICES_UUID>")
|
31
|
-
# sync.fetch do |
|
32
|
-
# DB.send(
|
31
|
+
# sync.fetch do |meta, resource|
|
32
|
+
# DB.send(meta.sync.event_type, entity) ? meta.sync.ack : meta.sync.nack
|
33
33
|
# end
|
34
34
|
#
|
35
35
|
# @param block [Proc] Procedure that will be called for every item in the queue. Takes two input arguments: SyncMeta instance
|
data/lib/basecrm/version.rb
CHANGED
data/spec/basecrm/sync_spec.rb
CHANGED
@@ -61,8 +61,8 @@ describe BaseCRM::Sync do
|
|
61
61
|
|
62
62
|
let(:queue_items) do
|
63
63
|
[
|
64
|
-
[BaseCRM::SyncMeta.new(event_type: 'created', ack_key: 'User-1234-1'), BaseCRM::User.new(id: 1)],
|
65
|
-
[BaseCRM::SyncMeta.new(event_type: 'created', ack_key: 'Source-1234-1'), BaseCRM::Source.new(id: 1)]
|
64
|
+
[BaseCRM::Meta.new(type: 'user', sync: BaseCRM::SyncMeta.new(event_type: 'created', ack_key: 'User-1234-1')), BaseCRM::User.new(id: 1)],
|
65
|
+
[BaseCRM::Meta.new(type: 'source', sync: BaseCRM::SyncMeta.new(event_type: 'created', ack_key: 'Source-1234-1')), BaseCRM::Source.new(id: 1)]
|
66
66
|
]
|
67
67
|
end
|
68
68
|
|
@@ -74,19 +74,20 @@ describe BaseCRM::Sync do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'does whole synchronization flow' do
|
77
|
-
subject.fetch { |
|
77
|
+
subject.fetch { |m, r| m.sync.ack }
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'calls a provided block as many times as items in the queue' do
|
81
81
|
counter = 0
|
82
|
-
subject.fetch { |
|
82
|
+
subject.fetch { |m, r| counter += 1; m.sync.ack }
|
83
83
|
expect(counter).to eq(2)
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'passes two elements to provided block: first element is BaseCRM::SyncMeta and the second is a resource' do
|
87
|
-
subject.fetch do |
|
88
|
-
expect(
|
89
|
-
|
87
|
+
subject.fetch do |m, r|
|
88
|
+
expect(m).to be_a BaseCRM::Meta
|
89
|
+
expect(m.sync).to be_a BaseCRM::SyncMeta
|
90
|
+
m.sync.ack
|
90
91
|
end
|
91
92
|
end
|
92
93
|
end
|
@@ -267,15 +267,19 @@ describe BaseCRM::SyncService do
|
|
267
267
|
items = client.sync.fetch(device_uuid, session_id)
|
268
268
|
|
269
269
|
sync_meta, user = items[0]
|
270
|
-
expect(sync_meta).to be_a BaseCRM::
|
270
|
+
expect(sync_meta).to be_a BaseCRM::Meta
|
271
|
+
expect(sync_meta.sync).to be_a BaseCRM::SyncMeta
|
271
272
|
expect(user).to be_a BaseCRM::User
|
272
|
-
expect(sync_meta.
|
273
|
+
expect(sync_meta.type).to eq('user')
|
274
|
+
expect(sync_meta.sync.ack_key).to eq('User-123-1')
|
273
275
|
expect(user.id).to eq(1)
|
274
276
|
|
275
277
|
sync_meta, source = items[1]
|
276
|
-
expect(sync_meta).to be_a BaseCRM::
|
278
|
+
expect(sync_meta).to be_a BaseCRM::Meta
|
279
|
+
expect(sync_meta.sync).to be_a BaseCRM::SyncMeta
|
277
280
|
expect(source).to be_a BaseCRM::Source
|
278
|
-
expect(sync_meta.
|
281
|
+
expect(sync_meta.type).to eq('source')
|
282
|
+
expect(sync_meta.sync.ack_key).to eq('Source-123-1')
|
279
283
|
expect(source.id).to eq(1)
|
280
284
|
end
|
281
285
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basecrm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BaseCRM developers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- lib/basecrm/models/deal.rb
|
145
145
|
- lib/basecrm/models/lead.rb
|
146
146
|
- lib/basecrm/models/loss_reason.rb
|
147
|
+
- lib/basecrm/models/meta.rb
|
147
148
|
- lib/basecrm/models/note.rb
|
148
149
|
- lib/basecrm/models/pipeline.rb
|
149
150
|
- lib/basecrm/models/source.rb
|