Class: SpreeCmCommissioner::Integrations::StadiumXV1::ExternalClient::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#integrationObject (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

Parameters:

  • match_id (String)

    The match ID

  • user_id (String)

    The user ID

  • club_id (String)

    The club ID

  • zone_id (String)

    The zone ID

  • quantity (Integer)

    The quantity of tickets to create

Returns:



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

Parameters:

  • id (String)

    The match ID

Returns:



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

Returns:



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

Parameters:

  • id (String)

    The ticket ID

Returns:



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

Parameters:

  • user_id (String)

    The user ID

Returns:



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

Parameters:

  • club_id (String)

    The club ID

  • match_id (String)

    The match ID

Returns:



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