Class: CandyCheck::PlayStore::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/candy_check/play_store/client.rb

Overview

A client which uses the official Google API SDK to authenticate and request product information from Google’s API.

Examples:

Usage

config = ClientConfig.new({...})
client = Client.new(config)
client.boot! # a single time
client.verify('my.bundle', 'product_1', 'a-very-long-secure-token')
# ... multiple calls from now on
client.verify('my.bundle', 'product_1', 'another-long-token')

Defined Under Namespace

Classes: DiscoveryError

Constant Summary collapse

API_URL =

API endpoint

'https://accounts.google.com/o/oauth2/token'
API_SCOPE =

API scope for Android services

'https://www.googleapis.com/auth/androidpublisher'
API_DISCOVER =

API discovery namespace

'androidpublisher'
API_VERSION =

API version

'v2'

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Client

Initializes a client using a configuration.

Parameters:

  • config (ClientConfig)


28
29
30
# File 'lib/candy_check/play_store/client.rb', line 28

def initialize(config)
  self.config = config
end

Instance Method Details

#boot!Object

Boots a client by discovering the API’s services and then authorizes by fetching an access token. If the config has a cache_file the client tries to load discovery



35
36
37
38
39
40
41
42
# File 'lib/candy_check/play_store/client.rb', line 35

def boot!
  self.api_client = Google::APIClient.new(
    application_name:    config.application_name,
    application_version: config.application_version
  )
  discover!
  authorize!
end

#verify(package, product_id, token) ⇒ Hash

Calls the remote API to load the product information for a specific combination of parameter which should be loaded from the client.

Parameters:

  • package (String)

    the app’s package name

  • product_id (String)

    the app’s item id

  • token (String)

    the purchase token

Returns:

  • (Hash)

    result of the API call



50
51
52
53
54
55
56
57
58
59
# File 'lib/candy_check/play_store/client.rb', line 50

def verify(package, product_id, token)
  api_client.execute(
    api_method: rpc.purchases.products.get,
    parameters: {
      'packageName' => package,
      'productId'   => product_id,
      'token'       => token
    }
  ).data.to_hash
end