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'.freeze
API_SCOPE =

API scope for Android services

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

API discovery namespace

'androidpublisher'.freeze
API_VERSION =

API version

'v2'.freeze

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)
  @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
43
# File 'lib/candy_check/play_store/client.rb', line 35

def boot!
  @api_client = Google::APIClient.new(
    application_name:    config.application_name,
    application_version: config.application_version,
    user_agent: user_agent
  )
  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



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

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

#verify_subscription(package, subscription_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

  • subscription_id (String)

    the app’s item id

  • token (String)

    the purchase token

Returns:

  • (Hash)

    result of the API call



66
67
68
69
70
71
72
73
# File 'lib/candy_check/play_store/client.rb', line 66

def verify_subscription(package, subscription_id, token)
  parameters = {
    'packageName'    => package,
    'subscriptionId' => subscription_id,
    'token'          => token
  }
  execute(parameters, rpc.purchases.subscriptions.get)
end