git-fit 0.14.3 → 0.15.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5922b46e00a21d66f591fb8d0e43b9a5e35dbb2fef4f5118aa7c689e62fa0118
4
- data.tar.gz: 103cb559cef56006024fb838982410a47c49485c9a104ee6bd29a33cc05179f2
3
+ metadata.gz: 1288abd3413532666d8f9582a8a2934dade01fc0dc81258f2903029d42129887
4
+ data.tar.gz: 5a6b72a2be75a4eef7f5136a8ac3d631b967f40fc0e6fff615279531ff160e0c
5
5
  SHA512:
6
- metadata.gz: d7de2f67f3c9d549cfa1f1117acb3d0843b15cf3543508a9e588e4d8a9e1b3e3ca06f1e6feb403204df9f17bc480b758b95586ef5ab55085e59795773890a545
7
- data.tar.gz: 5e252339935260098d9d8811ba9a4229dabf58c86c861afad78e6a2d17096aaed24dc2500f2144a5982e2157a2d343cf35b1269e0098f32675153afda2583640
6
+ metadata.gz: a488380bc74c1ae7baceb6686a98c38325fa8be5ccac2c32b6b09d9c715b25edc20cce66aeb1f5cb7342962e6240e95f48f0583c5be32d739824aa9c19bf9a95
7
+ data.tar.gz: 57b4d882f162663cf5b69c2eb024ed511bf7829dba0d99f6ac391508b315df9196c9bfd9b927c648a5f5b4a256f162c74ddc302e79b373b400895738d7f7df97
@@ -130,10 +130,12 @@ module GitFit
130
130
  details = fetch_activity_detail(act_id)
131
131
  return nil unless details
132
132
 
133
- polyline = fetch_summary_polyline(act_id)
134
-
135
- unless raw_file_exists?(act_id)
133
+ if raw_file_exists?(act_id)
134
+ polyline = fetch_summary_polyline(act_id)
135
+ else
136
+ write_raw_file(details, 'detail.json', act_id)
136
137
  download_fit_raw(act_id)
138
+ polyline = download_and_save_polyline(act_id)
137
139
  l2 = fit_to_l2(act_id)
138
140
  write_standardized_json(l2, act_id) if l2
139
141
  end
@@ -655,25 +657,63 @@ module GitFit
655
657
  FIT_EPOCH = 631_065_600
656
658
 
657
659
  def raw_path(platform_id)
658
- File.join(raw_dir, "#{platform_id}.fit")
660
+ File.join(raw_dir, platform_id, 'activity.fit')
659
661
  end
660
662
 
661
- def fetch_summary_polyline(activity_id)
662
- gps = api_get("/activity-service/activity/#{activity_id}/details")
663
- polyline = gps&.dig('geoPolylineDTO', 'polyline')
663
+ def raw_file_exists?(platform_id)
664
+ dir = File.join(raw_dir, platform_id)
665
+ %w[activity.fit detail.json polyline.json].all? do |f|
666
+ File.exist?(File.join(dir, f))
667
+ end
668
+ end
664
669
 
670
+ def write_source_archive(data, platform_id, ext = 'json')
671
+ write_raw_file(data, "activity.#{ext}", platform_id)
672
+ end
673
+
674
+ def write_raw_file(data, filename, platform_id)
675
+ dir = File.join(raw_dir, platform_id)
676
+ FileUtils.mkdir_p(dir)
677
+ tmp = File.join(dir, ".#{filename}.tmp")
678
+ dest = File.join(dir, filename)
679
+ case data
680
+ when String then File.write(tmp, data)
681
+ when Hash, Array then File.write(tmp, JSON.generate(data))
682
+ end
683
+ File.rename(tmp, dest)
684
+ end
685
+
686
+ def encode_polyline(polyline_data, activity_id = nil)
687
+ return nil unless polyline_data
688
+ polyline = polyline_data['polyline']
665
689
  if polyline.is_a?(Array)
666
690
  points = polyline.map { |pt| [pt['lat'], pt['lon']] }
667
- GitFit::Geo::Polyline.encode(points) if points.size >= 2
668
- else
669
- polyline
691
+ return GitFit::Geo::Polyline.encode(points) if points.size >= 2
670
692
  end
693
+ polyline
671
694
  rescue StandardError => e
672
- puts "Warning: failed to encode polyline for #{activity_id}: #{e.message}"
695
+ context = activity_id ? " for #{activity_id}" : ''
696
+ puts "Warning: failed to encode polyline#{context}: #{e.message}"
673
697
  nil
674
698
  end
675
699
 
700
+ def fetch_summary_polyline(activity_id)
701
+ gps = api_get("/activity-service/activity/#{activity_id}/details")
702
+ encode_polyline(gps&.dig('geoPolylineDTO'), activity_id)
703
+ end
704
+
705
+ def download_and_save_polyline(activity_id)
706
+ gps = api_get("/activity-service/activity/#{activity_id}/details")
707
+ return nil unless gps
708
+ polyline_data = gps['geoPolylineDTO']
709
+ return nil unless polyline_data
710
+ write_raw_file(polyline_data, 'polyline.json', activity_id)
711
+ encode_polyline(polyline_data, activity_id)
712
+ end
713
+
676
714
  def download_fit_raw(activity_id)
715
+ return true if File.exist?(raw_path(activity_id))
716
+
677
717
  uri = URI("#{connectapi_base}/download-service/files/activity/#{activity_id}")
678
718
  req = Net::HTTP::Get.new(uri)
679
719
  req['Authorization'] = "Bearer #{@access_token.fetch('access_token')}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitFit
4
- VERSION = '0.14.3'
4
+ VERSION = '0.15.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-fit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.3
4
+ version: 0.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lax