Class: PetstoreApiClient::ApiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/petstore_api_client/api_client.rb

Overview

Main API client - this is what users interact with

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ ApiClient

Returns a new instance of ApiClient.



8
9
10
11
# File 'lib/petstore_api_client/api_client.rb', line 8

def initialize(config = nil)
  @configuration = config || Configuration.new
  @configuration.validate!
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



6
7
8
# File 'lib/petstore_api_client/api_client.rb', line 6

def configuration
  @configuration
end

Instance Method Details

#configure {|configuration| ... } ⇒ Object

Yields:



13
14
15
16
17
18
19
# File 'lib/petstore_api_client/api_client.rb', line 13

def configure
  yield(configuration) if block_given?
  # Reset clients when configuration changes
  @pet_client = nil
  @store_client = nil
  self
end

#create_order(order_data) ⇒ Object



48
49
50
# File 'lib/petstore_api_client/api_client.rb', line 48

def create_order(order_data)
  store.create_order(order_data)
end

#create_pet(pet_data) ⇒ Object

Convenience methods so you can do client.create_pet instead of client.pets.create_pet



32
33
34
# File 'lib/petstore_api_client/api_client.rb', line 32

def create_pet(pet_data)
  pets.create_pet(pet_data)
end

#delete_order(order_id) ⇒ Object



56
57
58
# File 'lib/petstore_api_client/api_client.rb', line 56

def delete_order(order_id)
  store.delete_order(order_id)
end

#delete_pet(pet_id) ⇒ Object



44
45
46
# File 'lib/petstore_api_client/api_client.rb', line 44

def delete_pet(pet_id)
  pets.delete_pet(pet_id)
end

#get_order(order_id) ⇒ Object



52
53
54
# File 'lib/petstore_api_client/api_client.rb', line 52

def get_order(order_id)
  store.get_order(order_id)
end

#get_pet(pet_id) ⇒ Object



36
37
38
# File 'lib/petstore_api_client/api_client.rb', line 36

def get_pet(pet_id)
  pets.get_pet(pet_id)
end

#petsObject

Access to Pet endpoints



22
23
24
# File 'lib/petstore_api_client/api_client.rb', line 22

def pets
  @pets ||= Clients::PetClient.new(configuration)
end

#storeObject

Access to Store endpoints



27
28
29
# File 'lib/petstore_api_client/api_client.rb', line 27

def store
  @store ||= Clients::StoreClient.new(configuration)
end

#update_pet(pet_data) ⇒ Object



40
41
42
# File 'lib/petstore_api_client/api_client.rb', line 40

def update_pet(pet_data)
  pets.update_pet(pet_data)
end