Class: CandyCheck::PlayStore::DiscoveryRepository

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(file_path) ⇒ DiscoveryRepository

Create a new instance bound to a single file path

Parameters:

  • file_path (String)

    to save and load the cached copy



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

#loadGoogle::APIClient::API

Tries to load a cached copy of the discovery API. Me be nil if no cached version is available

Returns:

  • (Google::APIClient::API)


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.

Parameters:

  • discovery (Google::APIClient::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