Skip to content

Commit

Permalink
Add DELETE support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Decot committed Aug 14, 2019
1 parent 36a5398 commit c8dc0fe
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ Style/Documentation:
Metrics/LineLength:
Enabled: false

Style/StructInheritance:
Metrics/ClassLength:
Enabled: false

2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
16 changes: 16 additions & 0 deletions lib/app_store_connect/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
26 changes: 18 additions & 8 deletions lib/app_store_connect/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
7 changes: 6 additions & 1 deletion lib/config/api.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit c8dc0fe

Please sign in to comment.