Class: SpreeCmCommissioner::GoogleWallets::BaseGenericClass

Inherits:
Object
  • Object
show all
Defined in:
app/services/spree_cm_commissioner/google_wallets/base_generic_class.rb

Direct Known Subclasses

BaseHotelClass

Constant Summary collapse

GOOGLE_API_ENDPOINT =
'https://walletobjects.googleapis.com/walletobjects/v1/genericClass'.freeze
GOOGLE_OAUTH_SCOPE =
'https://www.googleapis.com/auth/wallet_object.issuer'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(google_wallet_class) ⇒ BaseGenericClass

Returns a new instance of BaseGenericClass.



9
10
11
# File 'app/services/spree_cm_commissioner/google_wallets/base_generic_class.rb', line 9

def initialize(google_wallet_class)
  @google_wallet_class = google_wallet_class
end

Instance Method Details

#access_tokenObject



62
63
64
65
66
67
68
# File 'app/services/spree_cm_commissioner/google_wallets/base_generic_class.rb', line 62

def access_token
  authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
    json_key_io: StringIO.new(credentials.to_json),
    scope: GOOGLE_OAUTH_SCOPE
  )
  authorizer.fetch_access_token!['access_token']
end

#build_request_bodyObject

This method is to be overrided in subclasses

Raises:

  • (NotImplementedError)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/services/spree_cm_commissioner/google_wallets/base_generic_class.rb', line 14

def build_request_body
  raise NotImplementedError, 'build_request_body must be implemented in subclasses'

  ## Reference: https://developers.google.com/wallet/reference/rest/v1/genericclass
  ## Example of what the body should look like
  # {
  #   id: string,
  #   imageModulesData: [
  #     {
  #       mainImage: {
  #         sourceUri: {
  #           uri: 'https://storage.googleapis.com/wallet-lab-tools-codelab-artifacts-public/google-io-2021-card.png'
  #         },
  #         contentDescription: {
  #           defaultValue: {
  #             language: 'en-US',
  #             value: 'Google I/O 2022 Banner'
  #           }
  #         }
  #       },
  #       id: 'event_banner'
  #     }
  #   ],

  #   textModulesData: [
  #     {
  #       header: 'Gather points meeting new people at Google I/O',
  #       body: 'Join the game and accumulate points in this badge by meeting other attendees in the event.',
  #       id: 'game_overview'
  #     }
  #   ],

  #   linksModuleData: {
  #     uris: [
  #       {
  #         uri: 'https://io.google/2022/',
  #         description: 'Official I/O \'22 Site',
  #         id: 'official_site'
  #       }
  #     ]
  #   }
  # }
end

#credentialsObject



58
59
60
# File 'app/services/spree_cm_commissioner/google_wallets/base_generic_class.rb', line 58

def credentials
  Rails.application.credentials.
end