Skip to content

Commit 0f9b666

Browse files
authored
Merge pull request #1457 from PRX/fix/apple_info
Remove api url
2 parents 48fe4c4 + 546d112 commit 0f9b666

File tree

9 files changed

+28
-18
lines changed

9 files changed

+28
-18
lines changed

app/models/apple/api.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# frozen_string_literal: true
22

3+
# NOTE: This code does not connect directly to Apple, a bridge lambda is used in between to handle communication and API calls.
4+
# This is not an official Apple API client, and to use Apple API you will need to have your own agreement with Apple to access their APIs.
5+
36
module Apple
47
class Api
5-
API_BASE = "https://api.podcastsconnect.apple.com/v1/"
6-
78
ERROR_RETRIES = 3
89
SUCCESS_CODES = [200, 201].freeze
910
DEFAULT_BATCH_SIZE = 5
@@ -28,6 +29,14 @@ def self.from_env
2829
key: apple_key_pem)
2930
end
3031

32+
def self.api_base
33+
ENV["APPLE_PODCASTS_CONNECT_API_URL"]
34+
end
35+
36+
def self.api_aud_name
37+
ENV["APPLE_PODCASTS_CONNECT_AUD_NAME"]
38+
end
39+
3140
def self.from_key(apple_key)
3241
new(provider_id: apple_key.provider_id,
3342
key_id: apple_key.key_id,
@@ -70,7 +79,7 @@ def jwt_payload
7079

7180
{iss: provider_id,
7281
exp: now.to_i + (60 * 15),
73-
aud: "podcastsconnect-v1"}
82+
aud: self.class.api_aud_name}
7483
end
7584

7685
def jwt_headers
@@ -114,7 +123,7 @@ def get_paged_collection(api_frag)
114123
end
115124

116125
def self.join_url(api_frag)
117-
URI.join(API_BASE, api_frag)
126+
URI.join(api_base, api_frag)
118127
end
119128

120129
def join_url(api_frag)

test/factories/apple_podcast_container_api_response_factory.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
after(:build) do |response_container, evaluator|
1616
response_container["api_response"] = {"request_metadata" => {},
17-
"api_url" => "https://api.podcastsconnect.apple.com/v1/podcastContainers/#{evaluator.podcast_container_id}",
17+
"api_url" => "https://aardvark.prx.org/podcastContainers/#{evaluator.podcast_container_id}",
1818
"api_parameters" => {},
1919
"api_response" =>
2020
{"ok" => true,
@@ -31,11 +31,11 @@
3131
"relationships" =>
3232
{"podcastDeliveries" =>
3333
{"links" =>
34-
{"self" => "https://api.podcastsconnect.apple.com/v1/podcastContainers/#{evaluator.podcast_container_id}/relationships/podcastDeliveries",
35-
"related" => "https://api.podcastsconnect.apple.com/v1/podcastContainers/#{evaluator.podcast_container_id}/podcastDeliveries",
36-
"include" => "https://api.podcastsconnect.apple.com/v1/podcastContainers/#{evaluator.podcast_container_id}?include=podcastDeliveries"}}},
37-
"links" => {"self" => "https://api.podcastsconnect.apple.com/v1/podcastContainers/#{evaluator.podcast_container_id}"}},
38-
"links" => {"self" => "https://api.podcastsconnect.apple.com/v1/podcastContainers/#{evaluator.podcast_container_id}"}}}}
34+
{"self" => "https://aardvark.prx.org/podcastContainers/#{evaluator.podcast_container_id}/relationships/podcastDeliveries",
35+
"related" => "https://aardvark.prx.org/podcastContainers/#{evaluator.podcast_container_id}/podcastDeliveries",
36+
"include" => "https://aardvark.prx.org/podcastContainers/#{evaluator.podcast_container_id}?include=podcastDeliveries"}}},
37+
"links" => {"self" => "https://aardvark.prx.org/podcastContainers/#{evaluator.podcast_container_id}"}},
38+
"links" => {"self" => "https://aardvark.prx.org/podcastContainers/#{evaluator.podcast_container_id}"}}}}
3939
response_container
4040
end
4141

test/factories/apple_podcast_delivery_file_api_response_factory.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
response_container["external_id"] = evaluator.podcast_delivery_file_id
2020
response_container["feeder_type"] = :podcast_delivery_files
2121
response_container["api_response"] = {"request_metadata" => {"apple_episode_id" => evaluator.apple_episode_id, "podcast_delivery_id" => evaluator.podcast_delivery_id},
22-
"api_url" => "https://api.podcastsconnect.apple.com/v1/podcastDeliveryFiles/#{evaluator.podcast_delivery_file_id}",
22+
"api_url" => "https://aardvark.prx.org/podcastDeliveryFiles/#{evaluator.podcast_delivery_file_id}",
2323
"api_parameters" => {},
2424
"api_response" =>
2525
{"ok" => true,

test/fixtures/apple_countries_and_regions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
"name": "AA country"
88
},
99
"links": {
10-
"self": "https://api.podcastsconnect.apple.com/v1/countriesAndRegions/AA"
10+
"self": "https://aardvark.prx.org/countriesAndRegions/AA"
1111
}
1212
}
1313
],
1414
"links": {
15-
"self": "https://api.podcastsconnect.apple.com/v1/countriesAndRegions?limit=200"
15+
"self": "https://aardvark.prx.org/countriesAndRegions?limit=200"
1616
},
1717
"meta": {
1818
"paging": {

test/models/apple/podcast_delivery_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Apple::PodcastDeliveryTest < ActiveSupport::TestCase
8383
describe ".get_urls_for_container_podcast_deliveries" do
8484
let(:podcast_container_deliveries_json) do
8585
{"request_metadata" => {"apple_episode_id" => "apple-episode-id", "podcast_container_id" => 1},
86-
"api_url" => "https://api.podcastsconnect.apple.com/v1/podcastContainers/12345/relationships/podcastDeliveries",
86+
"api_url" => "https://aardvark.prx.org/podcastContainers/12345/relationships/podcastDeliveries",
8787
"api_parameters" => {},
8888
"api_response" => {"ok" => true,
8989
"err" => false,
@@ -94,7 +94,7 @@ class Apple::PodcastDeliveryTest < ActiveSupport::TestCase
9494
let(:apple_api) { build(:apple_api) }
9595

9696
it "should format a new set of podcast delivery urls" do
97-
assert_equal ["https://api.podcastsconnect.apple.com/v1/podcastDeliveries/1111111111111111111111111"],
97+
assert_equal ["https://aardvark.prx.org/podcastDeliveries/1111111111111111111111111"],
9898
Apple::PodcastDelivery.get_urls_for_container_podcast_deliveries(apple_api,
9999
podcast_container_deliveries_json)
100100
end

test/models/apple/publisher_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
let(:publisher) { apple_publisher }
1515

1616
before do
17-
stub_request(:get, "https://api.podcastsconnect.apple.com/v1/countriesAndRegions?limit=200")
17+
stub_request(:get, "https://aardvark.prx.org/countriesAndRegions?limit=200")
1818
.to_return(status: 200, body: json_file(:apple_countries_and_regions), headers: {})
1919

2020
public_feed.save!

test/models/apple/show_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
before do
1414
private_feed.set_default_episodes
1515

16-
stub_request(:get, "https://api.podcastsconnect.apple.com/v1/countriesAndRegions?limit=200")
16+
stub_request(:get, "https://aardvark.prx.org/countriesAndRegions?limit=200")
1717
.to_return(status: 200, body: json_file(:apple_countries_and_regions), headers: {})
1818
end
1919

test/models/feed/apple_subscription_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123

124124
it "can return a list of possible apple shows" do
125125
body = {data: [{id: "1", attributes: {title: "t1"}}, {id: "2", attributes: {title: "t2"}}], links: {}}.to_json
126-
stub_request(:get, "https://api.podcastsconnect.apple.com/v1/shows").to_return(status: 200, body: body)
126+
stub_request(:get, "https://aardvark.prx.org/shows").to_return(status: 200, body: body)
127127
assert_equal apple_feed.apple_show_options, [["1 (t1)", "1"], ["2 (t2)", "2"]]
128128
end
129129
end

test/test_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
ENV["ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY"] = "andthisisanotheronetoothankyouuu"
2424
ENV["ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT"] = "maybeyouarefeelingsaltyaboutthis"
2525
ENV["PODPING_AUTH_TOKEN"] = "test_token"
26+
ENV["APPLE_PODCASTS_CONNECT_API_URL"] = "https://aardvark.prx.org/"
2627

2728
ENV["RAILS_ENV"] ||= "test"
2829
require_relative "../config/environment"

0 commit comments

Comments
 (0)