synced 1.3.0 → 1.4.0

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: 4e12f68714c45cb3257ac0116c7412e34879bff8
4
- data.tar.gz: 07828256826de59fcb3e8e0c8da913270bab003d
3
+ metadata.gz: b945df81754cad42074724a1571ee354c1933224
4
+ data.tar.gz: 751cd8bbe6f45e57291d803b84a732ce85f8b94f
5
5
  SHA512:
6
- metadata.gz: aad5845c643c3a8485db188837bf7f43307513c8cbf3092b0e190a4759ffb00dd879ba74cfa0f77798128c0b81ab7710db268eec8e14fed782d51d4389b53195
7
- data.tar.gz: f000eb92f1ccb6d09b10a10995571240f8619612206129305faa8a7283809169ed02a656cf9a50e775fecb93e847a8c35e4cfd2f64ca98992b1f94c8942f716a
6
+ metadata.gz: 8ddb414c76f87761d53d9cef876709c216da97bff6ad3deed9e972919559d41ec71d1deef1e6c6bb3e7a584f3c8e2dae4d9ad590d5ac9e873daa1667b737e4d5
7
+ data.tar.gz: ac416d727ee33daf592af9b7d4d0717d151212d0d3c39070abcb65e3492ffc28b6e5e04acded3bc97dcf783f3e9a1d9789250cd704536653d6d8bfe6249a5b59
data/README.md CHANGED
@@ -243,7 +243,7 @@ class CreateSyncedTimestamps < ActiveRecord::Migration
243
243
  t.datetime :synced_at, null: false
244
244
  end
245
245
 
246
- add_index :synced_timestamps, [:parent_scope_id, :parent_scope_type, :synced_at], name: 'synced_timestamps_max_index', order: { synced_at: 'DESC' }
246
+ add_index :synced_timestamps, [:parent_scope_id, :parent_scope_type, :model_class, :synced_at], name: 'synced_timestamps_max_index', order: { synced_at: 'DESC' }
247
247
  end
248
248
  end
249
249
  ```
@@ -47,7 +47,6 @@ module Synced
47
47
  @scope = options[:scope]
48
48
  @id_key = options[:id_key]
49
49
  @data_key = options[:data_key]
50
- @remove = options[:remove]
51
50
  @only_updated = options[:only_updated]
52
51
  @include = options[:include]
53
52
  @local_attributes = synced_attributes_as_hash(options[:local_attributes])
@@ -16,11 +16,12 @@ module Synced
16
16
  end
17
17
 
18
18
  def perform
19
+ raise MissingTimestampError.new unless first_request_timestamp
19
20
  super.tap do |local_objects|
20
21
  instrument("update_synced_timestamp_perform.synced", model: @model_class) do
21
22
  # TODO: it can't be Time.now. this value has to be fetched from the API as well
22
23
  # https://github.com/BookingSync/synced/issues/29
23
- @timestamp_strategy.update(Time.now)
24
+ @timestamp_strategy.update(first_request_timestamp)
24
25
  end
25
26
  end
26
27
  end
@@ -54,11 +55,22 @@ module Synced
54
55
  meta && meta[:deleted_ids] or raise CannotDeleteDueToNoDeletedIdsError.new(@model_class)
55
56
  end
56
57
 
58
+ def first_request_timestamp
59
+ if first_response_headers && first_response_headers["x-updated-since-request-synced-at"]
60
+ Time.zone.parse(first_response_headers["x-updated-since-request-synced-at"])
61
+ end
62
+ end
63
+
57
64
  def meta
58
65
  remote_objects
59
66
  @meta ||= api.last_response.meta
60
67
  end
61
68
 
69
+ def first_response_headers
70
+ remote_objects
71
+ @first_response_headers ||= api.pagination_first_response.headers
72
+ end
73
+
62
74
  # Remove all objects with ids from deleted_ids field in the meta key
63
75
  def remove_relation
64
76
  relation_scope.where(@id_key => deleted_remote_objects_ids)
@@ -79,6 +91,12 @@ module Synced
79
91
  @model_class.to_s.pluralize
80
92
  end
81
93
  end
94
+
95
+ class MissingTimestampError < StandardError
96
+ def message
97
+ "Synchronization failed. API response is missing 'x-updated-since-request-synced-at' header."
98
+ end
99
+ end
82
100
  end
83
101
  end
84
102
  end
@@ -1,3 +1,3 @@
1
1
  module Synced
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synced
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastien Grosjean
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-07 00:00:00.000000000 Z
12
+ date: 2016-12-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 0.0.20
34
+ version: 0.1.3
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: 0.0.20
41
+ version: 0.1.3
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: hashie
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -81,6 +81,20 @@ dependencies:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: listen
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '2.7'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '2.7'
84
98
  - !ruby/object:Gem::Dependency
85
99
  name: guard-rspec
86
100
  requirement: !ruby/object:Gem::Requirement
@@ -210,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
224
  version: '0'
211
225
  requirements: []
212
226
  rubyforge_project:
213
- rubygems_version: 2.4.8
227
+ rubygems_version: 2.5.1
214
228
  signing_key:
215
229
  specification_version: 4
216
230
  summary: Keep your BookingSync Application synced with BookingSync.