google_wallet 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd967517d51f87610d1718191b6a0da9874ace6b0835ca35b0b04f8673f2e95e
4
- data.tar.gz: 62844c5062d351f69923887e2297e7dbee9d48fb269e7bd7c86cc1921ecbc96a
3
+ metadata.gz: 358156bceb3c82fed5cf3ca4e2abc632dfe03c231082de9c1264d9d9b2c73f63
4
+ data.tar.gz: e76ce87afd020e4e61bd33d054b4485768c4c55f7c68e8e87a60717cafa46110
5
5
  SHA512:
6
- metadata.gz: a85c8c2991cc045b1d321b69ac5295dfc308b5e45c788a8d0b25827d5683465cb2dccd45483551ea5a9080607b72e32c640a1d749954742f7cf7f555b1817657
7
- data.tar.gz: d1a5f6acadd8f48612fe0c28abc7ccba7975b3337a6d4e7e70f95f007d025420a4680d5c7e77bc81ff41625cd4d49e08e91d9f44966ea694e65f62a3b2fd1dde
6
+ metadata.gz: cbe474b0ee786e48a16ea9f5c45d7974cbbdd816d60b7fdb63a79e725e05d4c4d0ec3647d241905bde07e3f1c1787679c9610dadc9b36087c7a62709d92bc649
7
+ data.tar.gz: a000fba2348bac73eba76bee03caec4db80f0580607d4a65b6f8c8c3402a83ba57ddff5bde7fa581dd14253443c5384a491890def57ca71215514e3ac7d143dd
data/README.md CHANGED
@@ -1,22 +1,133 @@
1
+ <p align="right">
2
+ <a href="https://github.com/vergilet/google_wallet"><img align="" src="https://user-images.githubusercontent.com/2478436/51829223-cb05d600-22f5-11e9-9245-bc6e82dcf028.png" width="56" height="56" /></a>
3
+ <a href="https://rubygems.org/gems/google_wallet"><img align="right" src="https://user-images.githubusercontent.com/2478436/51829691-c55cc000-22f6-11e9-99a5-42f88a8f2a55.png" width="56" height="56" /></a>
4
+ </p>
5
+
6
+
7
+ <p align="center">
8
+ <a href="https://rubygems.org/gems/repost">
9
+ <img width="460" src="https://github.com/vergilet/google_wallet/assets/2478436/5f9c5925-129a-401e-bd46-82e6ae2b2430"></a>
10
+ </p>
11
+
12
+
13
+
1
14
  # GoogleWallet
15
+ Unofficial Ruby Gem for [Google Wallet API](https://developers.google.com/wallet).
2
16
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/google_wallet`. To experiment with that code, run `bin/console` for an interactive prompt.
17
+ ## Prerequisites
18
+ Before you use the Google Wallet API for an integration, complete first four steps from [this guide](https://developers.google.com/wallet/tickets/events/web/prerequisites).
4
19
 
5
- TODO: Delete this and the text above, and describe your gem
20
+ *On 3rd step you are going to obtain **key.json**, which will be needed for the gem initialization.*
6
21
 
7
22
  ## Installation
8
23
 
9
- Install the gem and add to the application's Gemfile by executing:
24
+ Add this line to your application's Gemfile:
25
+
26
+ ```ruby
27
+ gem 'google_wallet'
28
+ ```
10
29
 
11
- $ bundle add google_wallet
30
+ And then execute:
12
31
 
13
- If bundler is not being used to manage dependencies, install the gem by executing:
32
+ $ bundle install
33
+
34
+ Or install it yourself as:
14
35
 
15
36
  $ gem install google_wallet
16
37
 
17
38
  ## Usage
18
39
 
19
- TODO: Write usage instructions here
40
+ Create initializer:
41
+ ```ruby
42
+ # config/initializers/google_wallet.rb
43
+
44
+ GoogleWallet.configure do |config|
45
+ config.load_credentials_from_file('./key.json')
46
+ config.issuer_id = '33880000000XXXXXXXX'
47
+ config.debug_mode = true
48
+ config.logger = Logger.new(STDOUT)
49
+ end
50
+ ```
51
+
52
+ ### EventTicket
53
+
54
+ #### Create class (event representation):
55
+ ```ruby
56
+ event_attributes = {
57
+ # required fields
58
+ class_identifier: 'Event-123456',
59
+ event_name: 'Solo Singing Contest #1 Yay!',
60
+ issuer_name: 'iChar System',
61
+
62
+ # other fields
63
+ event_id: '123456',
64
+ logo_url: 'https://images.unsplash.com/photo-1475721027785-f74eccf877e2?auto=format&fit=crop&w=360&h=360',
65
+ hero_image_url: 'https://images.unsplash.com/photo-1501281668745-f7f57925c3b4?auto=format&fit=crop&w=1032&h=336',
66
+ homepage_url: 'https://example.com',
67
+ country_code: 'no',
68
+ venue_name: 'Opera Theater',
69
+ venue_address: "Shevchenka street 41/5, Ukraine, Kyiv",
70
+ start_date_time: '2023-09-27T22:30',
71
+ end_date_time: '2023-09-28T01:30',
72
+ hex_background_color: '#ff0077',
73
+ callback_url: 'https://example.com/gpass_callback'
74
+ }
75
+
76
+
77
+ # Create Resource of EventTicket Class
78
+ event = GoogleWallet::Resources::EventTicket::Class.new(attributes: event_attributes)
79
+
80
+ # Push Class to Google Wallet API
81
+ event.push
82
+ ```
83
+
84
+ #### Create object (ticket representation):
85
+ ```ruby
86
+ ticket_attributes = {
87
+ # required fields
88
+ object_identifier: 'fd9b637f-0381-42ad-9161-b4d887d79d9f',
89
+ class_identifier: 'Event-12345',
90
+
91
+ # other fields
92
+ grouping_id: 'order-12345',
93
+ ticket_type: 'VIP Adult Plus',
94
+ section: 'The Sponsor Felt-F Overpower',
95
+ seat: '65',
96
+ row: '17',
97
+ gate: 'G3, G4',
98
+ ticket_holder_name: 'Yaro Developer',
99
+ qr_code_value: '12345678',
100
+ ref_number: 'cdeqw',
101
+ valid_time_start: '2023-09-27T22:30',
102
+ valid_time_end: '2023-09-28T02:00',
103
+ micros: 82_000_000,
104
+ currency_code: 'NOK',
105
+ hex_background_color: '#0090ff'
106
+ }
107
+
108
+ # Create Resource of EventTicket Object
109
+ ticket = GoogleWallet::Resources::EventTicket::Object.new(attributes: ticket_attributes)
110
+
111
+ # Push Object to Google Wallet API
112
+
113
+ # separated push and sign
114
+ ticket.push
115
+ jwt = ticket.sign(push_resource: false)
116
+
117
+ # or combined - just use sign
118
+ jwt = ticket.sign # default, push_resource: true
119
+
120
+ "https://pay.google.com/gp/v/save/#{jwt}"
121
+
122
+ ```
123
+
124
+ ### Result
125
+
126
+ <p align="center">
127
+ <a href="https://rubygems.org/gems/repost">
128
+ <img src="https://github.com/vergilet/google_wallet/assets/2478436/df8f6ec9-ec45-4226-a0cf-65dc6f69f9b5"></a>
129
+ </p>
130
+
20
131
 
21
132
  ## Development
22
133
 
@@ -26,7 +137,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
26
137
 
27
138
  ## Contributing
28
139
 
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/google_wallet.
140
+ Bug reports and pull requests are welcome on GitHub at https://github.com/vergilet/google_wallet.
30
141
 
31
142
  ## License
32
143
 
@@ -0,0 +1,33 @@
1
+ # lib/google_wallet/authentication.rb
2
+
3
+ require 'googleauth'
4
+
5
+ module GoogleWallet
6
+ class Authentication
7
+ SCOPE = 'https://www.googleapis.com/auth/wallet_object.issuer'
8
+
9
+ def initialize
10
+ @credentials = GoogleWallet.configuration.json_credentials
11
+ end
12
+
13
+ def access_token
14
+ if @credentials
15
+ begin
16
+ credentials = Google::Auth::ServiceAccountCredentials.make_creds(
17
+ json_key_io: StringIO.new(@credentials.to_json),
18
+ scope: SCOPE
19
+ )
20
+
21
+ credentials.fetch_access_token!
22
+ credentials.access_token
23
+ rescue StandardError => e
24
+ puts "Error while fetching access token: #{e.message}"
25
+ nil
26
+ end
27
+ else
28
+ puts "No credentials provided."
29
+ nil
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,30 @@
1
+ # google_wallet/configuration.rb
2
+
3
+ require 'json'
4
+
5
+ module GoogleWallet
6
+ class Configuration
7
+ attr_accessor :json_credentials, :issuer_id, :api_endpoint, :debug_mode, :logger
8
+
9
+ def initialize
10
+ @api_endpoint = 'https://walletobjects.googleapis.com/walletobjects/v1'
11
+ @json_credentials = nil
12
+ @issuer_id = nil
13
+ @debug_mode = false
14
+ @logger = Logger.new(STDOUT)
15
+ end
16
+
17
+ def self.logger
18
+ @logger
19
+ end
20
+
21
+ def load_credentials_from_file(file_path)
22
+ begin
23
+ json_data = JSON.parse(File.read(file_path))
24
+ @json_credentials = json_data
25
+ rescue JSON::ParserError, Errno::ENOENT => e
26
+ raise "Error loading JSON credentials from file: #{e.message}"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+
5
+ module GoogleWallet
6
+ module Operations
7
+ module EventTicket
8
+ class PushClass
9
+ ENDPOINT = 'eventTicketClass'
10
+
11
+ def initialize(resource:, access_token:)
12
+ @resource = resource
13
+ @access_token = access_token
14
+ end
15
+
16
+ def call
17
+ return update_class if exists?
18
+ create_class
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :resource, :access_token
24
+
25
+ def exists?
26
+ response = HTTParty.get(
27
+ "#{GoogleWallet.configuration.api_endpoint}/#{ENDPOINT}/#{resource.id}",
28
+ query: { access_token: access_token }
29
+ )
30
+
31
+ if GoogleWallet.debug_mode?
32
+ GoogleWallet.logger.debug(self.class.name)
33
+ GoogleWallet.logger.debug(__method__)
34
+ GoogleWallet.logger.debug(response.inspect)
35
+ end
36
+
37
+ response.success?
38
+ end
39
+
40
+ def create_class
41
+ response = HTTParty.post(
42
+ "#{GoogleWallet.configuration.api_endpoint}/#{ENDPOINT}",
43
+ query: { access_token: access_token },
44
+ body: resource.attributes.to_json,
45
+ headers: { 'Content-Type' => 'application/json' }
46
+ )
47
+ if GoogleWallet.debug_mode?
48
+ GoogleWallet.logger.debug(self.class.name)
49
+ GoogleWallet.logger.debug(__method__)
50
+ GoogleWallet.logger.debug(response.inspect)
51
+ end
52
+
53
+ response.success?
54
+ end
55
+
56
+ def update_class
57
+ response = HTTParty.put(
58
+ "#{GoogleWallet.configuration.api_endpoint}/#{ENDPOINT}/#{resource.id}",
59
+ query: {access_token: access_token},
60
+ body: resource.attributes.to_json,
61
+ headers: { 'Content-Type' => 'application/json' }
62
+ )
63
+
64
+ if GoogleWallet.debug_mode?
65
+ GoogleWallet.logger.debug(self.class.name)
66
+ GoogleWallet.logger.debug(__method__)
67
+ GoogleWallet.logger.debug(response.inspect)
68
+ end
69
+
70
+ response.success?
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+
5
+ module GoogleWallet
6
+ module Operations
7
+ module EventTicket
8
+ class PushObject
9
+ ENDPOINT = 'eventTicketObject'
10
+
11
+ def initialize(resource:, access_token:)
12
+ @resource = resource
13
+ @access_token = access_token
14
+ end
15
+
16
+ def call
17
+ return update_class if exists?
18
+ create_class
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :resource, :access_token
24
+
25
+ def exists?
26
+ response = HTTParty.get(
27
+ "#{GoogleWallet.configuration.api_endpoint}/#{ENDPOINT}/#{resource.id}",
28
+ query: { access_token: access_token }
29
+ )
30
+
31
+ if GoogleWallet.debug_mode?
32
+ GoogleWallet.logger.debug(self.class.name)
33
+ GoogleWallet.logger.debug(__method__)
34
+ GoogleWallet.logger.debug(response.inspect)
35
+ end
36
+
37
+ response.success?
38
+ end
39
+
40
+ def create_class
41
+ response = HTTParty.post(
42
+ "#{GoogleWallet.configuration.api_endpoint}/#{ENDPOINT}",
43
+ query: { access_token: access_token },
44
+ body: resource.attributes.to_json,
45
+ headers: { 'Content-Type' => 'application/json' }
46
+ )
47
+
48
+ if GoogleWallet.debug_mode?
49
+ GoogleWallet.logger.debug(self.class.name)
50
+ GoogleWallet.logger.debug(__method__)
51
+ GoogleWallet.logger.debug(response.inspect)
52
+ end
53
+
54
+ response.success?
55
+ end
56
+
57
+ def update_class
58
+ response = HTTParty.put(
59
+ "#{GoogleWallet.configuration.api_endpoint}/#{ENDPOINT}/#{resource.id}",
60
+ query: {access_token: access_token},
61
+ body: resource.attributes.to_json,
62
+ headers: { 'Content-Type' => 'application/json' }
63
+ )
64
+
65
+ if GoogleWallet.debug_mode?
66
+ GoogleWallet.logger.debug(self.class.name)
67
+ GoogleWallet.logger.debug(__method__)
68
+ GoogleWallet.logger.debug(response.inspect)
69
+ end
70
+
71
+ response.success?
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jwt'
4
+
5
+ module GoogleWallet
6
+ module Operations
7
+ class SignObjects
8
+ attr_reader :jwt, :resources, :resource_ids, :objects_type
9
+ DEFAULT_OBJECTS_TYPE = 'genericObjects'
10
+
11
+ def initialize(resources: [], resource_ids: [], objects_type: DEFAULT_OBJECTS_TYPE)
12
+ @resources = resources.kind_of?(Array) ? resources : [resources]
13
+ @resource_ids = resource_ids.kind_of?(Array) ? resource_ids : [resource_ids]
14
+ @objects_type = objects_type
15
+ unless resource_ids.empty?
16
+ GoogleWallet.logger.info("You didn't provide objects_type, fallback to use default #{DEFAULT_OBJECTS_TYPE}")
17
+ end
18
+ end
19
+
20
+ def call
21
+ payload = {
22
+ iss: GoogleWallet.configuration.json_credentials["client_email"],
23
+ aud: 'google',
24
+ typ: 'savetowallet',
25
+ payload: objects_payload,
26
+ origins: []
27
+ }
28
+
29
+ @jwt = JWT.encode(payload, rsa_private_key, 'RS256')
30
+
31
+ true
32
+ end
33
+
34
+ private
35
+
36
+ def objects_payload
37
+ objects.merge(object_ids) { |_key, old_val, new_val| old_val + new_val }
38
+ end
39
+
40
+ def objects
41
+ @objects ||= resources.each_with_object({}) do |resource, memo|
42
+ memo[resource.payload_key.to_sym] ||= []
43
+ memo[resource.payload_key.to_sym] << resource.attributes
44
+ end
45
+ end
46
+
47
+ def object_ids
48
+ return {} if resource_ids.empty?
49
+
50
+ { objects_type.to_sym => resource_ids.map { |resource_id| { id: resource_id } } }
51
+ end
52
+
53
+ def rsa_private_key
54
+ @rsa_private_key ||= OpenSSL::PKey::RSA.new(GoogleWallet.configuration.json_credentials["private_key"])
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GoogleWallet
4
+ module Resources
5
+ class Base
6
+ attr_reader :options
7
+
8
+ def initialize(attributes: {}, options: {})
9
+ @options = options
10
+
11
+ attributes.each do |key, value|
12
+ instance_variable_set("@#{key}", value)
13
+ end
14
+ end
15
+
16
+ def attributes
17
+ hash = deep_merge(template, options)
18
+ remove_empty_values(hash)
19
+ end
20
+
21
+ def payload_key
22
+ raise 'Define in resource'
23
+ end
24
+
25
+ private
26
+
27
+ def payload_key_logic
28
+ self.class.name.split("::")[-2].tap { |obj| obj[0] = obj[0].downcase }
29
+ end
30
+
31
+ def validate_fields(fields = [])
32
+ fields.each do |field|
33
+ raise "#{self.class.name} - #{field} is required" if blank?(instance_variable_get("@#{field}"))
34
+ end
35
+ end
36
+
37
+ def deep_merge(hash1, hash2)
38
+ hash1.merge(hash2) do |_key, old_val, new_val|
39
+ old_val.is_a?(Hash) && new_val.is_a?(Hash) ? deep_merge(old_val, new_val) : new_val
40
+ end
41
+ end
42
+
43
+ def remove_empty_values(hash)
44
+ hash.reject { |_key, value| value.nil? || value == '' || value == {} }
45
+ end
46
+
47
+ def blank?(value)
48
+ value.nil? || value.to_s.strip.empty?
49
+ end
50
+
51
+ def present?(value)
52
+ !blank?(value)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GoogleWallet
4
+ module Resources
5
+ module EventTicket
6
+ class Class < Base
7
+ attr_reader :class_identifier, :issuer_name, :logo_url, :event_id, :event_name,
8
+ :venue_name, :venue_address, :start_date_time, :end_date_time, :country_code,
9
+ :hex_background_color, :hero_image_url, :homepage_url, :callback_url, :id
10
+
11
+
12
+ # attributes = {
13
+ # class_identifier: 'Event-1234',
14
+ # issuer_name: 'iChar System',
15
+ # event_name: 'Solo Singing Contest #1 Yay!',
16
+ # event_id: '123456',
17
+ # logo_url: 'https://images.unsplash.com/photo-1475721027785-f74eccf877e2?auto=format&fit=crop&w=360&h=360',
18
+ # hero_image_url: 'https://images.unsplash.com/photo-1501281668745-f7f57925c3b4?auto=format&fit=crop&w=1032&h=336'
19
+ # homepage_url: 'https://arrangement.ticketco.events',
20
+ # country_code: 'no',
21
+ # venue_name: 'Opera Theater',
22
+ # venue_address: "Shevchenka street 41/5, Ukraine, Lviv",
23
+ # start_date_time: '2023-08-27T22:30',
24
+ # end_date_time: '2023-08-28T01:30',
25
+ # hex_background_color: '#ff0077',
26
+ # callback_url: 'https://example.com/gpass_callback'
27
+ # }
28
+
29
+
30
+ def initialize(attributes: {}, options: {})
31
+ super
32
+ validate_fields( %w[class_identifier event_name issuer_name])
33
+ @id = "#{GoogleWallet.configuration.issuer_id}.#{@class_identifier}"
34
+ end
35
+
36
+ def push
37
+ access_token = GoogleWallet::Authentication.new.access_token
38
+ GoogleWallet::Operations::EventTicket::PushClass.new(resource: self, access_token: access_token).call
39
+ end
40
+
41
+ def sign(push_resource: true)
42
+ raise "Class cannot be signed without Object,
43
+ use GoogleWallet::Operations::SignObjects.new(...)
44
+ to create/modify simultaneously classes and objects by following jwt link"
45
+ end
46
+
47
+ def payload_key
48
+ "#{payload_key_logic}Classes"
49
+ end
50
+
51
+ private
52
+
53
+ def template
54
+ template = {}
55
+
56
+ template[:id] = id
57
+ template[:issuerName] = issuer_name
58
+ template[:eventName] = { defaultValue: { language: "en-US", value: event_name } }
59
+ template[:reviewStatus] = "UNDER_REVIEW"
60
+
61
+ template[:eventId] = event_id if present?(event_id)
62
+ template[:logo] = { sourceUri: { uri: logo_url } } if present?(logo_url)
63
+ template[:heroImage] = { sourceUri: { uri: hero_image_url } } if present?(hero_image_url)
64
+
65
+ template[:homepageUri] = { uri: homepage_url, description: 'Homepage' } if present?(homepage_url)
66
+ template[:countryCode] = country_code if present?(country_code)
67
+ template[:hexBackgroundColor] = hex_background_color if present?(hex_background_color)
68
+ template[:callbackOptions] = { url: callback_url } if present?(callback_url)
69
+
70
+ template[:securityAnimation] = { animationType: "FOIL_SHIMMER" }
71
+
72
+ template[:venue] = {}
73
+ template[:venue][:name] = { defaultValue: { language: "en-US", value: venue_name } } if present?(venue_name)
74
+ template[:venue][:address] = { defaultValue: { language: "en-US", value: venue_address } } if present?(venue_address)
75
+
76
+ template[:dateTime] = {}
77
+ template[:dateTime][:start] = start_date_time if present?(start_date_time)
78
+ template[:dateTime][:end] = end_date_time if present?(end_date_time)
79
+
80
+ template
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GoogleWallet
4
+ module Resources
5
+ module EventTicket
6
+ class Object < Base
7
+
8
+ attr_reader :object_identifier, :class_identifier, :seat, :row, :section, :gate,
9
+ :ticket_type, :grouping_id, :qr_code_value, :ticket_holder_name,
10
+ :valid_time_start, :valid_time_end, :micros, :currency_code,
11
+ :hex_background_color, :ticket_number, :id, :class_id, :options
12
+
13
+
14
+ # attributes = {
15
+ # object_identifier: 'fd9b637f-0381-42ad-9161-b4d887d79d9f',
16
+ # class_identifier: 'Event-1234',
17
+ # grouping_id: 'order-12345',
18
+ # ticket_type: 'Vip Pass + Priority24',
19
+ # section: 'The Sponsor Felt-F Overpower',
20
+ # seat: '65',
21
+ # row: '17',
22
+ # gate: 'G3, G4',
23
+ # ticket_holder_name: 'Yaro Developer',
24
+ # qr_code_value: '12345678',
25
+ # ref_number: 'cdeqw',
26
+ # valid_time_start: '2023-09-27T22:30',
27
+ # valid_time_end: '2023-09-28T02:00',
28
+ # micros: 82_000_000,
29
+ # currency_code: 'NOK',
30
+ # hex_background_color: '#45ffaa'
31
+ # }
32
+
33
+ def initialize(attributes: {}, options: {})
34
+ super
35
+
36
+ validate_fields( %w[object_identifier class_identifier])
37
+ @id = "#{GoogleWallet.configuration.issuer_id}.#{@object_identifier}"
38
+ @class_id = "#{GoogleWallet.configuration.issuer_id}.#{@class_identifier}"
39
+ end
40
+
41
+ def push
42
+ access_token = GoogleWallet::Authentication.new.access_token
43
+ GoogleWallet::Operations::EventTicket::PushObject.new(resource: self, access_token: access_token).call
44
+ end
45
+
46
+ def sign(push_resource: true)
47
+ sign_operation =
48
+ if push_resource
49
+ push
50
+ GoogleWallet::Operations::SignObjects.new(resource_ids: [id], objects_type: self.payload_key)
51
+ else
52
+ GoogleWallet::Operations::SignObjects.new(resources: [itself])
53
+ end
54
+
55
+ sign_operation.call
56
+ sign_operation.jwt
57
+ end
58
+
59
+ def payload_key
60
+ "#{payload_key_logic}Objects"
61
+ end
62
+
63
+ private
64
+
65
+ def template
66
+ template = {}
67
+
68
+ template[:id] = id
69
+ template[:classId] = class_id
70
+ template[:state] = "ACTIVE"
71
+
72
+ template[:ticketType] = { defaultValue: { language: "en-us", value: ticket_type } } if present?(ticket_type)
73
+ template[:groupingInfo] = { groupingId: grouping_id } if present?(grouping_id)
74
+ template[:barcode] = { type: "QR_CODE", value: qr_code_value, alternateText: qr_code_value } if present?(qr_code_value)
75
+ template[:faceValue] = { micros: micros, currencyCode: currency_code } if present?(micros) && present?(currency_code)
76
+
77
+ template[:seatInfo] = {}
78
+ template[:seatInfo][:seat] = { defaultValue: { language: "en-us", value: seat } } if present?(seat)
79
+ template[:seatInfo][:row] = { defaultValue: { language: "en-us", value: row } } if present?(row)
80
+ template[:seatInfo][:section] = { defaultValue: { language: "en-us", value: section } } if present?(section)
81
+ template[:seatInfo][:gate] = { defaultValue: { language: "en-us", value: gate } } if present?(gate)
82
+
83
+ template[:validTimeInterval] = {}
84
+ template[:validTimeInterval][:start] = { date: valid_time_start } if present?(valid_time_start)
85
+ template[:validTimeInterval][:end] = { date: valid_time_end } if present?(valid_time_end)
86
+
87
+ template[:hexBackgroundColor] = hex_background_color if present?(hex_background_color)
88
+ template[:ticketHolderName] = ticket_holder_name if present?(ticket_holder_name)
89
+ template[:ticketNumber] = ticket_number if present?(ticket_number)
90
+
91
+ template
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GoogleWallet
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/google_wallet.rb CHANGED
@@ -1,8 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "google_wallet/version"
4
+ require_relative "google_wallet/configuration"
5
+ require_relative "google_wallet/authentication"
6
+
7
+ require_relative "google_wallet/resources/base"
8
+ require_relative "google_wallet/resources/event_ticket/class"
9
+ require_relative "google_wallet/resources/event_ticket/object"
10
+
11
+ require_relative "google_wallet/operations/sign_objects"
12
+ require_relative "google_wallet/operations/event_ticket/push_class"
13
+ require_relative "google_wallet/operations/event_ticket/push_object"
4
14
 
5
15
  module GoogleWallet
6
16
  class Error < StandardError; end
7
- # Your code goes here...
17
+
18
+ class << self
19
+ attr_accessor :configuration
20
+ end
21
+
22
+ def self.configure
23
+ self.configuration ||= Configuration.new
24
+ yield(configuration)
25
+ end
26
+
27
+ def self.logger
28
+ configuration.logger
29
+ end
30
+
31
+ def self.debug_mode?
32
+ configuration.debug_mode
33
+ end
8
34
  end
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_wallet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-18 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2023-09-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jwt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: googleauth
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
13
55
  description: google wallet
14
56
  email:
15
57
  - osyaroslav@gmail.com
@@ -22,8 +64,15 @@ files:
22
64
  - README.md
23
65
  - Rakefile
24
66
  - lib/google_wallet.rb
67
+ - lib/google_wallet/authentication.rb
68
+ - lib/google_wallet/configuration.rb
69
+ - lib/google_wallet/operations/event_ticket/push_class.rb
70
+ - lib/google_wallet/operations/event_ticket/push_object.rb
71
+ - lib/google_wallet/operations/sign_objects.rb
72
+ - lib/google_wallet/resources/base.rb
73
+ - lib/google_wallet/resources/event_ticket/class.rb
74
+ - lib/google_wallet/resources/event_ticket/object.rb
25
75
  - lib/google_wallet/version.rb
26
- - sig/google_wallet.rbs
27
76
  homepage: https://github.com/vergilet/google_wallet
28
77
  licenses:
29
78
  - MIT
@@ -46,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
95
  - !ruby/object:Gem::Version
47
96
  version: '0'
48
97
  requirements: []
49
- rubygems_version: 3.4.17
98
+ rubygems_version: 3.4.19
50
99
  signing_key:
51
100
  specification_version: 4
52
101
  summary: google wallet
@@ -1,4 +0,0 @@
1
- module GoogleWallet
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end