ud_sync 0.1.0 → 0.1.1

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: 6bd624f7a50e53ab1cfaa2ddce8be9f50f7342b5
4
- data.tar.gz: aa73de3d74848846325ab80eeba6d6f39cd9b810
3
+ metadata.gz: b2e88b07b7d759d3dc100a40d4022fc0ecf5d821
4
+ data.tar.gz: 5f524ceb2805d9ba4050bbc32ac76b7afadac55a
5
5
  SHA512:
6
- metadata.gz: 3a68af143ba1bf28704e3269ac26aa3017d3f087c457437d366331d3d53703f34c40e58f447d3c47e4f657825561101ff3709cdd8eca02f8a23121277a3b346d
7
- data.tar.gz: f5c5d56349b628b3f0e6553f617c9450106b957476ff2c461db0515013377da0d9f2add2f0ada9b9c04ac173c06f47c77618b03cee826b3945b09fd4878f5dab
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: add the route**
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 2: configure your models**
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 3: consume /ud_sync/operations**
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" => 1,
60
- "name" => "save",
61
- "record_id" => "record-1",
62
- "entity" => "User",
63
- "date" => "2025-10-23T10:32:41Z"
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" => 2,
66
- "name" => "delete",
67
- "record_id" => "record-2",
68
- "entity" => "Post",
69
- "date" => "2025-10-23T11:23:23Z"
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 4: define current_user in your application controller**
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`
@@ -0,0 +1,12 @@
1
+ module UdSync
2
+ class ApplicationController < ::ApplicationController
3
+
4
+ private
5
+
6
+ def forbidden?
7
+ current_user.blank?
8
+ rescue NameError
9
+ false
10
+ end
11
+ end
12
+ end
@@ -1,19 +1,39 @@
1
1
  module UdSync
2
- class OperationsController < ActionController::Base
2
+ class OperationsController < UdSync::ApplicationController
3
3
  def index
4
- operations = UdSync::Operation.all
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.record_id,
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
@@ -1,3 +1,3 @@
1
1
  module UdSync
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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-01-31 00:00:00.000000000 Z
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