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 Attribute Summary collapse
-
#integration ⇒ Object
readonly
Returns the value of attribute integration.
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(integration:) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(integration:) ⇒ Client
Returns a new instance of Client.
9 10 11 |
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/external_client/client.rb', line 9 def initialize(integration:) @integration = integration end |
Instance Attribute Details
#integration ⇒ Object (readonly)
Returns the value of attribute integration.
7 8 9 |
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/external_client/client.rb', line 7 def integration @integration end |
Instance Method Details
#create_tickets!(match_id:, user_id:, club_id:, zone_id:, quantity:) ⇒ Array<Resources::Ticket>
Create a new ticket
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/external_client/client.rb', line 44 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
76 77 78 79 80 81 82 |
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/external_client/client.rb', line 76 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
65 66 67 68 69 70 71 |
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/external_client/client.rb', line 65 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
18 19 20 21 22 23 24 |
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/external_client/client.rb', line 18 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
29 30 31 32 33 34 35 |
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/external_client/client.rb', line 29 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
90 91 92 93 94 95 96 97 98 99 |
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/external_client/client.rb', line 90 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 |