Class: SpreeCmCommissioner::Integrations::StadiumXV1::ExternalClient::Client
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Integrations::StadiumXV1::ExternalClient::Client
- Defined in:
- app/services/spree_cm_commissioner/integrations/stadium_x_v1/external_client/client.rb
Constant Summary collapse
- BASE_PATH =
'/api/v1'.freeze
- RATE_LIMIT =
100
Instance Method Summary collapse
-
#create_tickets!(match_id:, user_id:, club_id:, zone_id:, quantity:) ⇒ Array<Resources::Ticket>
Create a new ticket.
-
#get_match!(id:) ⇒ Resources::Match
Get a specific match by ID.
-
#get_matches! ⇒ Array<Resources::Match>
Get all available matches.
-
#get_ticket!(id:) ⇒ Resources::Ticket
Get a specific ticket by ID.
-
#get_tickets_by_user!(user_id:) ⇒ Array<Resources::Ticket>
Get all tickets for a specific user.
-
#get_zones!(club_id:, match_id:) ⇒ Array<Resources::Zone>
Get available zones for a club and match.
-
#initialize(public_key:, private_key:, base_url:) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(public_key:, private_key:, base_url:) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 |
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/external_client/client.rb', line 7 def initialize(public_key:, private_key:, base_url:) @public_key = public_key @private_key = private_key @base_url = base_url @connection = build_connection end |
Instance Method Details
#create_tickets!(match_id:, user_id:, club_id:, zone_id:, quantity:) ⇒ Array<Resources::Ticket>
Create a new ticket
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/external_client/client.rb', line 45 def create_tickets!(match_id:, user_id:, club_id:, zone_id:, quantity:) params = { match_id: match_id, user_id: user_id, club_id: club_id, zone_id: zone_id, quantity: quantity } response = @connection.post("#{BASE_PATH}/tickets") do |req| req.body = auth_params.merge(params).to_json req.headers['Content-Type'] = 'application/json' end handle_response(response, Resources::Ticket, collection: true) end |
#get_match!(id:) ⇒ Resources::Match
Get a specific match by ID
77 78 79 80 81 82 83 |
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/external_client/client.rb', line 77 def get_match!(id:) response = @connection.get("#{BASE_PATH}/matches/#{id}") do |req| req.params = auth_params end handle_response(response, Resources::Match) end |
#get_matches! ⇒ Array<Resources::Match>
Get all available matches
66 67 68 69 70 71 72 |
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/external_client/client.rb', line 66 def get_matches! # rubocop:disable Naming/AccessorMethodName response = @connection.get("#{BASE_PATH}/matches") do |req| req.params = auth_params end handle_response(response, Resources::Match, collection: true) end |
#get_ticket!(id:) ⇒ Resources::Ticket
Get a specific ticket by ID
19 20 21 22 23 24 25 |
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/external_client/client.rb', line 19 def get_ticket!(id:) response = @connection.get("#{BASE_PATH}/tickets/#{id}") do |req| req.body = auth_params.to_json end handle_response(response, Resources::Ticket) end |
#get_tickets_by_user!(user_id:) ⇒ Array<Resources::Ticket>
Get all tickets for a specific user
30 31 32 33 34 35 36 |
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/external_client/client.rb', line 30 def get_tickets_by_user!(user_id:) response = @connection.get("#{BASE_PATH}/tickets/user/#{user_id}") do |req| req.body = auth_params.merge(user_id: user_id).to_json end handle_response(response, Resources::Ticket, collection: true) end |
#get_zones!(club_id:, match_id:) ⇒ Array<Resources::Zone>
Get available zones for a club and match
91 92 93 94 95 96 97 98 99 100 |
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/external_client/client.rb', line 91 def get_zones!(club_id:, match_id:) response = @connection.get("#{BASE_PATH}/zones/club") do |req| req.params = auth_params.merge( club_id: club_id, match_id: match_id ) end handle_response(response, Resources::Zone, collection: true) end |