Class: LinearApi::CacheSync
- Inherits:
-
Object
- Object
- LinearApi::CacheSync
- Defined in:
- lib/linear_api/cache_sync.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#import_from_json(json_path) ⇒ Object
Import from linear.json file.
-
#sync_all ⇒ Object
Sync all metadata in a single API call (instead of 4 separate calls).
-
#sync_labels ⇒ Object
Individual sync methods (for targeted refresh).
- #sync_projects ⇒ Object
- #sync_states ⇒ Object
- #sync_users ⇒ Object
Class Method Details
.import_from_json(json_path) ⇒ Object
10 11 12 |
# File 'lib/linear_api/cache_sync.rb', line 10 def import_from_json(json_path) new.import_from_json(json_path) end |
.sync_all ⇒ Object
6 7 8 |
# File 'lib/linear_api/cache_sync.rb', line 6 def sync_all new.sync_all end |
Instance Method Details
#import_from_json(json_path) ⇒ Object
Import from linear.json file
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/linear_api/cache_sync.rb', line 69 def import_from_json(json_path) data = JSON.parse(File.read(json_path)) counts = { labels: 0, projects: 0, states: 0, users: 0 } # Import labels import_labels_from_json(data['labels'], counts) # Import projects data['projects']&.each do |key, project| CachedMetadata.upsert_from_api( type: 'project', linear_id: project['id'], name: project['name'], key: key, state_type: project['state'], raw_data: project ) counts[:projects] += 1 end # Import workflow states data['workflow_states']&.each do |key, state| CachedMetadata.upsert_from_api( type: 'state', linear_id: state['id'], name: state['name'], key: key, state_type: state['type'], raw_data: state ) counts[:states] += 1 end # Import users data['users']&.each do |key, user| CachedMetadata.upsert_from_api( type: 'user', linear_id: user['id'], name: user['name'], key: key, raw_data: user ) counts[:users] += 1 end counts end |
#sync_all ⇒ Object
Sync all metadata in a single API call (instead of 4 separate calls)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/linear_api/cache_sync.rb', line 16 def sync_all LinearApi.logger.info { 'LinearApi: syncing all metadata from Linear API' } result = LinearApi.client. unless result.success? LinearApi.logger.error { "LinearApi: metadata sync failed: #{result.error}" } return { labels: { success: false, error: result.error }, projects: { success: false, error: result.error }, states: { success: false, error: result.error }, users: { success: false, error: result.error } } end = result.data { labels: sync_labels_from_data([:labels]), projects: sync_projects_from_data([:projects]), states: sync_states_from_data([:states]), users: sync_users_from_data([:users]) } end |
#sync_labels ⇒ Object
Individual sync methods (for targeted refresh)
40 41 42 43 44 45 |
# File 'lib/linear_api/cache_sync.rb', line 40 def sync_labels result = LinearApi.client.list_labels return { success: false, error: result.error } unless result.success? sync_labels_from_data(result.data) end |
#sync_projects ⇒ Object
47 48 49 50 51 52 |
# File 'lib/linear_api/cache_sync.rb', line 47 def sync_projects result = LinearApi.client.list_projects return { success: false, error: result.error } unless result.success? sync_projects_from_data(result.data) end |
#sync_states ⇒ Object
54 55 56 57 58 59 |
# File 'lib/linear_api/cache_sync.rb', line 54 def sync_states result = LinearApi.client.list_states return { success: false, error: result.error } unless result.success? sync_states_from_data(result.data) end |
#sync_users ⇒ Object
61 62 63 64 65 66 |
# File 'lib/linear_api/cache_sync.rb', line 61 def sync_users result = LinearApi.client.list_users return { success: false, error: result.error } unless result.success? sync_users_from_data(result.data) end |