ud_sync 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +23 -15
- data/app/controllers/ud_sync/application_controller.rb +12 -0
- data/app/controllers/ud_sync/operations_controller.rb +24 -4
- data/lib/ud_sync/version.rb +1 -1
- 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: b2e88b07b7d759d3dc100a40d4022fc0ecf5d821
|
4
|
+
data.tar.gz: 5f524ceb2805d9ba4050bbc32ac76b7afadac55a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea7afdac72e4a4a383a789f65da1587c58ad5082aee9cd5bbf15acd29e034502ece603931b37954052cb2aefeb1bcb0f40633b3f81d031dab618e9a6b1fd31c1
|
7
|
+
data.tar.gz: 31cf08ae9779115c78d44b905c9174e7fbd6b6e0e1b1d11d8ac761448bce764d33e59b2aeb61570b370e4a4b559f0701c200dd38040880b661d2da3c3b57cd8a
|
data/README.md
CHANGED
@@ -26,7 +26,15 @@ And then execute:
|
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
-
**Step 1:
|
29
|
+
**Step 1: runs migrations**
|
30
|
+
|
31
|
+
```
|
32
|
+
rake db:migrate
|
33
|
+
```
|
34
|
+
|
35
|
+
`ud-sync` records operations and configurations in database tables.
|
36
|
+
|
37
|
+
**Step 2: add the route**
|
30
38
|
|
31
39
|
```ruby
|
32
40
|
Rails.application.routes.draw do
|
@@ -36,7 +44,7 @@ Rails.application.routes.draw do
|
|
36
44
|
end
|
37
45
|
```
|
38
46
|
|
39
|
-
**Step
|
47
|
+
**Step 3: configure your models**
|
40
48
|
|
41
49
|
```ruby
|
42
50
|
class Post < ActiveRecord::Base
|
@@ -48,25 +56,25 @@ end
|
|
48
56
|
|
49
57
|
Whenever you save or delete a post, this will save the operation automatically.
|
50
58
|
|
51
|
-
**Step
|
59
|
+
**Step 4: consume /ud_sync/operations**
|
52
60
|
|
53
61
|
When you access `GET /ud_sync/operations`, you will get a response such as the
|
54
62
|
following.
|
55
63
|
|
56
64
|
```json
|
57
65
|
{
|
58
|
-
"operations"
|
59
|
-
"id"
|
60
|
-
"name"
|
61
|
-
"record_id"
|
62
|
-
"entity"
|
63
|
-
"date"
|
66
|
+
"operations": [{
|
67
|
+
"id": 1,
|
68
|
+
"name": "save",
|
69
|
+
"record_id": "record-1",
|
70
|
+
"entity": "User",
|
71
|
+
"date": "2025-10-23T10:32:41Z"
|
64
72
|
}, {
|
65
|
-
"id"
|
66
|
-
"name"
|
67
|
-
"record_id"
|
68
|
-
"entity"
|
69
|
-
"date"
|
73
|
+
"id": 2,
|
74
|
+
"name": "delete",
|
75
|
+
"record_id": "record-2",
|
76
|
+
"entity": "Post",
|
77
|
+
"date": "2025-10-23T11:23:23Z"
|
70
78
|
}]
|
71
79
|
}
|
72
80
|
```
|
@@ -80,7 +88,7 @@ with id `record-2`, this operation will be recorded. When DeviceB comes online,
|
|
80
88
|
it will request the operations endpoint and check that the Post was deleted
|
81
89
|
online. It will then delete it locally so that it's synchronized with DeviceA.
|
82
90
|
|
83
|
-
**Step
|
91
|
+
**Step 5: define current_user in your application controller**
|
84
92
|
|
85
93
|
If your `ApplicationController` has `current_user` defined, `GET /operations`
|
86
94
|
will only return Operations which `owner_id` equals `current_user.id`
|
@@ -1,19 +1,39 @@
|
|
1
1
|
module UdSync
|
2
|
-
class OperationsController <
|
2
|
+
class OperationsController < UdSync::ApplicationController
|
3
3
|
def index
|
4
|
-
|
4
|
+
render body: false, status: 401 and return if forbidden?
|
5
|
+
|
6
|
+
operations = UdSync::Operation
|
7
|
+
if current_user_present?
|
8
|
+
operations = operations.where(owner_id: current_user.id)
|
9
|
+
end
|
10
|
+
|
11
|
+
if params[:since].present?
|
12
|
+
since = DateTime.parse(params[:since])
|
13
|
+
operations = operations.where('created_at >= ?', since)
|
14
|
+
end
|
15
|
+
|
16
|
+
operations = operations.all
|
5
17
|
|
6
18
|
render json: {
|
7
19
|
operations: operations.map do |operation|
|
8
20
|
{
|
9
|
-
id: operation.id,
|
21
|
+
id: operation.id.to_s,
|
10
22
|
name: operation.name,
|
11
|
-
record_id: operation.
|
23
|
+
record_id: operation.external_id,
|
12
24
|
entity: operation.entity_name,
|
13
25
|
date: operation.created_at.iso8601,
|
14
26
|
}
|
15
27
|
end
|
16
28
|
}
|
17
29
|
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def current_user_present?
|
34
|
+
current_user.present?
|
35
|
+
rescue NameError
|
36
|
+
false
|
37
|
+
end
|
18
38
|
end
|
19
39
|
end
|
data/lib/ud_sync/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ud_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre de Oliveira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- Gemfile
|
136
136
|
- README.md
|
137
137
|
- Rakefile
|
138
|
+
- app/controllers/ud_sync/application_controller.rb
|
138
139
|
- app/controllers/ud_sync/operations_controller.rb
|
139
140
|
- app/models/ud_sync/operation.rb
|
140
141
|
- bin/console
|