Class: GoogleWallet::Operations::SignObjects

Inherits:
Object
  • Object
show all
Defined in:
lib/google_wallet/operations/sign_objects.rb

Constant Summary collapse

DEFAULT_OBJECTS_TYPE =
'genericObjects'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resources: [], resource_ids: [], objects_type: DEFAULT_OBJECTS_TYPE) ⇒ SignObjects

Returns a new instance of SignObjects.



11
12
13
14
15
16
17
18
# File 'lib/google_wallet/operations/sign_objects.rb', line 11

def initialize(resources: [], resource_ids: [], objects_type: DEFAULT_OBJECTS_TYPE)
  @resources = resources.kind_of?(Array) ? resources : [resources]
  @resource_ids = resource_ids.kind_of?(Array) ? resource_ids : [resource_ids]
  @objects_type = objects_type
  unless resource_ids.empty?
    GoogleWallet.logger.info("You didn't provide objects_type, fallback to use default #{DEFAULT_OBJECTS_TYPE}")
  end
end

Instance Attribute Details

#jwtObject (readonly)

Returns the value of attribute jwt.



8
9
10
# File 'lib/google_wallet/operations/sign_objects.rb', line 8

def jwt
  @jwt
end

#objects_typeObject (readonly)

Returns the value of attribute objects_type.



8
9
10
# File 'lib/google_wallet/operations/sign_objects.rb', line 8

def objects_type
  @objects_type
end

#resource_idsObject (readonly)

Returns the value of attribute resource_ids.



8
9
10
# File 'lib/google_wallet/operations/sign_objects.rb', line 8

def resource_ids
  @resource_ids
end

#resourcesObject (readonly)

Returns the value of attribute resources.



8
9
10
# File 'lib/google_wallet/operations/sign_objects.rb', line 8

def resources
  @resources
end

Instance Method Details

#callObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/google_wallet/operations/sign_objects.rb', line 20

def call
  payload = {
    iss: GoogleWallet.configuration.json_credentials["client_email"],
    aud: 'google',
    typ: 'savetowallet',
    payload: objects_payload,
    origins: []
  }

  @jwt = JWT.encode(payload, rsa_private_key, 'RS256')

  true
end