diograph-store 0.0.4 → 0.0.5
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/lib/diograph_store/store.rb +92 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53f5297681d6ff054f516108056e3a6800439d42
|
4
|
+
data.tar.gz: 82ddcbc2e2eb1db07283c0e65a23b6fabd84b964
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f08a3d6d4d07a13867582cca1a0c79dfaaeb7bf12fa0cb959d46ca3dd12c779092bd44707cecd4aac55f2db83376b9620894b8d8a30a5a0fc2eb580c904fb10f
|
7
|
+
data.tar.gz: 573766ad639b184c9b9de431333f6b3aa675e742ff20a4548e3f0c89dcfdaf7cc9a7f1f91bfc8d9cc29a0b5a8d690302bb0801ae8f0362560b1bfb018fbbf537
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'diograph_store/diory_store'
|
4
|
+
require 'diograph_store/connection_store'
|
5
|
+
require 'diograph_store/diory_connection_store'
|
6
|
+
|
7
|
+
### DOKUMENTAATIO
|
8
|
+
class Store
|
9
|
+
|
10
|
+
STORE_TYPES = ['diories', 'connections'].freeze
|
11
|
+
|
12
|
+
def initialize(type:, object_store: DiographStore::DiographStore.new)
|
13
|
+
unless STORE_TYPES.include?(type)
|
14
|
+
raise "Invalid store type. Should be one of these: #{STORE_TYPES}"
|
15
|
+
end
|
16
|
+
|
17
|
+
case type
|
18
|
+
when 'connections'
|
19
|
+
@store = ConnectionStore.new(object_store)
|
20
|
+
when 'diories'
|
21
|
+
@store = DioryStore.new(object_store)
|
22
|
+
end
|
23
|
+
|
24
|
+
@objects = {}
|
25
|
+
end
|
26
|
+
|
27
|
+
def get(id)
|
28
|
+
return @objects[id] unless @objects[id].nil?
|
29
|
+
|
30
|
+
object = @store.get(id)
|
31
|
+
return nil if object.nil?
|
32
|
+
|
33
|
+
@objects[object.id] = object
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.store_data(response)
|
37
|
+
extracted_response = extract_response(response)
|
38
|
+
|
39
|
+
extracted_response['diories'].each do |diory_data|
|
40
|
+
DioryStore.new.save(
|
41
|
+
diory_id: diory_data['diory-id'],
|
42
|
+
diory_data: diory_data
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
extracted_response['connections'].each do |connection_data|
|
47
|
+
# Save connection to connections_store
|
48
|
+
ConnectionStore.new.save(
|
49
|
+
connection_id: connection_data['connection-id'],
|
50
|
+
connection_data: connection_data
|
51
|
+
)
|
52
|
+
|
53
|
+
# Add connection into diory_connections_store (if not already there)
|
54
|
+
add_connection_into_diory_connections_store(connection_data)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.extract_response(data)
|
59
|
+
extracted_response = {
|
60
|
+
'diories' => [],
|
61
|
+
'connections' => []
|
62
|
+
}
|
63
|
+
|
64
|
+
objects = [data['data']] + (data['included'] || [])
|
65
|
+
|
66
|
+
objects.each do |object|
|
67
|
+
object['attributes']['id'] = object['id'] if object['attributes']
|
68
|
+
if object['type'] == 'diories'
|
69
|
+
extracted_response['diories'] << object['attributes']
|
70
|
+
elsif object['type'] == 'connections'
|
71
|
+
extracted_response['connections'] << object['attributes']
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
extracted_response
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.add_connection_into_diory_connections_store(connection_data)
|
79
|
+
# Save connection for from_diory
|
80
|
+
DioryConnectionStore.new.save(
|
81
|
+
diory_id: connection_data['from-diory-diory-id'],
|
82
|
+
connection_id: connection_data['connection-id']
|
83
|
+
)
|
84
|
+
|
85
|
+
### Don't save opposite direction connections at all
|
86
|
+
# Save connection for to_diory
|
87
|
+
# DioryConnectionStore.new.save(
|
88
|
+
# diory_id: connection_data['to-diory-diory-id'],
|
89
|
+
# connection_id: connection_data['connection-id']
|
90
|
+
# )
|
91
|
+
end
|
92
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diograph-store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jouni Alanen
|
@@ -74,6 +74,7 @@ extra_rdoc_files: []
|
|
74
74
|
files:
|
75
75
|
- lib/diograph-store.rb
|
76
76
|
- lib/diograph_store/diograph_api_request.rb
|
77
|
+
- lib/diograph_store/store.rb
|
77
78
|
homepage: http://dioryme.github.io
|
78
79
|
licenses: []
|
79
80
|
metadata: {}
|