Class: CandyCheck::PlayStore::DiscoveryRepository
- Inherits:
-
Object
- Object
- CandyCheck::PlayStore::DiscoveryRepository
- Defined in:
- lib/candy_check/play_store/discovery_repository.rb
Overview
A file-based repository to cache a local copy of the Google API discovery as suggested by Google.
Instance Method Summary collapse
-
#initialize(file_path) ⇒ DiscoveryRepository
constructor
Create a new instance bound to a single file path.
-
#load ⇒ Google::APIClient::API
Tries to load a cached copy of the discovery API.
-
#save(discovery) ⇒ Object
Tries to save a local copy of the discovery API.
Constructor Details
#initialize(file_path) ⇒ DiscoveryRepository
Create a new instance bound to a single file path
9 10 11 |
# File 'lib/candy_check/play_store/discovery_repository.rb', line 9 def initialize(file_path) @file_path = file_path end |
Instance Method Details
#load ⇒ Google::APIClient::API
Tries to load a cached copy of the discovery API. Me be nil if no cached version is available
16 17 18 19 20 21 |
# File 'lib/candy_check/play_store/discovery_repository.rb', line 16 def load return unless @file_path && File.exist?(@file_path) File.open(@file_path, 'rb') do |file| return Marshal.load(file) end end |
#save(discovery) ⇒ Object
Tries to save a local copy of the discovery API.
25 26 27 28 29 30 |
# File 'lib/candy_check/play_store/discovery_repository.rb', line 25 def save(discovery) return unless @file_path && discovery File.open(@file_path, 'wb') do |file| Marshal.dump(discovery, file) end end |