Class: Lambdagate::ApiGatewayClient
- Inherits:
-
Object
- Object
- Lambdagate::ApiGatewayClient
- Defined in:
- lib/lambdagate/api_gateway_client.rb
Constant Summary collapse
- DEFAULT_AUTHORIZATION_TYPE =
"NONE"
- DEFAULT_REGION =
"us-east-1"
- SERVICE_NAME =
"apigateway"
Instance Method Summary collapse
- #create_resource(parent_id:, part:, restapi_id:) ⇒ Faraday::Response
- #create_resources(paths:, restapi_id:) ⇒ Object
- #create_restapi(name:) ⇒ Faraday::Response
- #delete_model(model_name:, restapi_id:) ⇒ Faraday::Response
- #find_resource(path:, restapi_id:) ⇒ Hash{String => Hash}?
-
#initialize(access_key_id:, host: nil, region: nil, secret_access_key:) ⇒ ApiGatewayClient
constructor
A new instance of ApiGatewayClient.
- #list_resources(restapi_id:) ⇒ Faraday::Response
- #put_method(api_key_required: nil, authorization_type: nil, http_method:, request_models: nil, request_parameters: nil, resource_id:, restapi_id:) ⇒ Faraday::Response
Constructor Details
#initialize(access_key_id:, host: nil, region: nil, secret_access_key:) ⇒ ApiGatewayClient
Returns a new instance of ApiGatewayClient.
15 16 17 18 19 20 |
# File 'lib/lambdagate/api_gateway_client.rb', line 15 def initialize(access_key_id:, host: nil, region: nil, secret_access_key:) @access_key_id = access_key_id @host = host @region = region @secret_access_key = secret_access_key end |
Instance Method Details
#create_resource(parent_id:, part:, restapi_id:) ⇒ Faraday::Response
26 27 28 29 30 |
# File 'lib/lambdagate/api_gateway_client.rb', line 26 def create_resource(parent_id:, part:, restapi_id:) post("/restapis/#{restapi_id}/resources/#{parent_id}", pathPart: part).tap do |response| puts "[DEBUG] Created " + response.body["path"] end end |
#create_resources(paths:, restapi_id:) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/lambdagate/api_gateway_client.rb', line 34 def create_resources(paths:, restapi_id:) root_resource_id = get_root_resource_id(restapi_id: restapi_id) paths.each do |path| parent_id = root_resource_id parts = path.split("/") parts[1..-1].each_with_index do |part, index| if resource = find_resource(path: parts[0 .. index + 1].join("/"), restapi_id: restapi_id) parent_id = resource["id"] else response = create_resource( parent_id: parent_id, part: part, restapi_id: restapi_id, ) parent_id = response.body["id"] end end end end |
#create_restapi(name:) ⇒ Faraday::Response
56 57 58 |
# File 'lib/lambdagate/api_gateway_client.rb', line 56 def create_restapi(name:) post("/restapis", name: name) end |
#delete_model(model_name:, restapi_id:) ⇒ Faraday::Response
63 64 65 |
# File 'lib/lambdagate/api_gateway_client.rb', line 63 def delete_model(model_name:, restapi_id:) delete("/restapis/#{restapi_id}/models/#{model_name}") end |
#find_resource(path:, restapi_id:) ⇒ Hash{String => Hash}?
70 71 72 73 74 |
# File 'lib/lambdagate/api_gateway_client.rb', line 70 def find_resource(path:, restapi_id:) list_resources(restapi_id: restapi_id).body["item"].find do |item| item["path"] == path end end |
#list_resources(restapi_id:) ⇒ Faraday::Response
78 79 80 |
# File 'lib/lambdagate/api_gateway_client.rb', line 78 def list_resources(restapi_id:) get("/restapis/#{restapi_id}/resources") end |
#put_method(api_key_required: nil, authorization_type: nil, http_method:, request_models: nil, request_parameters: nil, resource_id:, restapi_id:) ⇒ Faraday::Response
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/lambdagate/api_gateway_client.rb', line 90 def put_method(api_key_required: nil, authorization_type: nil, http_method:, request_models: nil, request_parameters: nil, resource_id:, restapi_id:) put( "/restapis/#{restapi_id}/resources/#{resource_id}/methods/#{http_method}", { apiKeyRequired: api_key_required, authorizationType: || DEFAULT_AUTHORIZATION_TYPE, requestModels: request_models, requestParameters: request_parameters, }.reject { |key, value| value.nil? }, ) end |