diff --git a/.rubocop.yml b/.rubocop.yml index 32f768a..92b1ac3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -21,5 +21,6 @@ Style/Documentation: Metrics/LineLength: Enabled: false -Style/StructInheritance: +Metrics/ClassLength: Enabled: false + diff --git a/Gemfile.lock b/Gemfile.lock index a3bd668..1f45830 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - app_store_connect (0.7.0) + app_store_connect (0.8.0) activesupport (~> 5.2.3) jwt (~> 2.1) diff --git a/lib/app_store_connect/client.rb b/lib/app_store_connect/client.rb index b373958..19377e3 100644 --- a/lib/app_store_connect/client.rb +++ b/lib/app_store_connect/client.rb @@ -50,6 +50,8 @@ def call(web_service_endpoint, **kwargs) get(web_service_endpoint, **kwargs, &parser) when :post post(web_service_endpoint, **kwargs, &parser) + when :delete + delete(web_service_endpoint, **kwargs) else raise "invalid http method: #{web_service_endpoint.http_method}" end @@ -106,6 +108,20 @@ def http_body(web_service_endpoint, **kwargs) .to_json end + def delete(web_service_endpoint, **kwargs) + request = Request.new( + web_service_endpoint: web_service_endpoint, + kwargs: kwargs, + http_method: :delete, + uri: build_uri(web_service_endpoint, **kwargs), + headers: headers + ) + + request.execute + + true + end + def post(web_service_endpoint, **kwargs, &block) request = Request.new( web_service_endpoint: web_service_endpoint, diff --git a/lib/app_store_connect/request.rb b/lib/app_store_connect/request.rb index 8a675c7..9581b4c 100644 --- a/lib/app_store_connect/request.rb +++ b/lib/app_store_connect/request.rb @@ -5,6 +5,12 @@ module AppStoreConnect attr_reader :uri + class UnsupportedHTTPMethod < ArgumentError + def initialize(http_method) + super "Unsupported HTTP Method: #{http_method}" + end + end + class Request def initialize(**options) @uri = options.fetch(:uri) @@ -70,17 +76,21 @@ def url_parameter_names(web_service_endpoint) .map { |_, n| n.to_sym } end - def request + def net_http_request_class case http_method - when :get - Net::HTTP::Get.new(uri, headers) - when :post - Net::HTTP::Post.new(uri, headers).tap do |request| - request.body = body - end + when :get then Net::HTTP::Get + when :post then Net::HTTP::Post + when :delete then Net::HTTP::Delete + when :patch then Net::HTTP::Patch else - raise "unsupported http method: #{http_method}" + raise UnsupportedHTTPMethod, http_method end end + + def request + net_http_request_class + .new(uri, headers) + .tap { |r| r.body = body if r.request_body_permitted? } + end end end diff --git a/lib/config/api.json b/lib/config/api.json index 643f0be..7feed24 100644 --- a/lib/config/api.json +++ b/lib/config/api.json @@ -1,5 +1,10 @@ { - "web_service_endpoints": [ + "web_service_endpoints": [ + { + "alias": "delete_user_invitation", + "http_method": "delete", + "url": "https://api.appstoreconnect.apple.com/v1/userInvitations/{id}" + }, { "alias": "apps", "http_method": "get",