podcast_index 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/.rubocop.yml +43 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +118 -0
- data/LICENSE.txt +21 -0
- data/README.md +89 -0
- data/Rakefile +10 -0
- data/lib/podcast_index/api/episodes.rb +34 -0
- data/lib/podcast_index/api/podcasts.rb +29 -0
- data/lib/podcast_index/api/request.rb +78 -0
- data/lib/podcast_index/api/search.rb +29 -0
- data/lib/podcast_index/episode.rb +52 -0
- data/lib/podcast_index/podcast.rb +52 -0
- data/lib/podcast_index/version.rb +3 -0
- data/lib/podcast_index.rb +24 -0
- data/podcast_index.gemspec +41 -0
- metadata +209 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 6b65c6fe11a9ccf6a3747e6c3c5cd862686978ee63cfcf7b1fd88ad79dc46367
|
|
4
|
+
data.tar.gz: 9695467e8f4bcfe6507ef16d8a91e6745de89fc0601d0cc63899886766b96e88
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6a24dfe1841426f4b8aede0afa6470060e6dcbcbaca97312b249d7918b0c45d19bcf26cb201ffb0f38a40285e71ecea42613b42424d58f67968bc0c91b0e9da0
|
|
7
|
+
data.tar.gz: 4bd0f8edc4931a7b8c54a46fa56c80ae12247903ae546bde090051cd7fb61efc44da3b2884675fe211247f90f04ce2e94abdcedf610329a3d029ef32f0338227
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require:
|
|
2
|
+
- rubocop-performance
|
|
3
|
+
- rubocop-rake
|
|
4
|
+
- rubocop-rspec
|
|
5
|
+
|
|
6
|
+
AllCops:
|
|
7
|
+
TargetRubyVersion: 3.0
|
|
8
|
+
NewCops: enable
|
|
9
|
+
|
|
10
|
+
Layout/AccessModifierIndentation:
|
|
11
|
+
EnforcedStyle: outdent
|
|
12
|
+
|
|
13
|
+
Layout/LineLength:
|
|
14
|
+
Max: 120
|
|
15
|
+
|
|
16
|
+
Metrics/AbcSize:
|
|
17
|
+
Exclude:
|
|
18
|
+
- spec/**/*
|
|
19
|
+
|
|
20
|
+
Metrics/BlockLength:
|
|
21
|
+
Exclude:
|
|
22
|
+
- spec/**/*
|
|
23
|
+
- "*.gemspec"
|
|
24
|
+
|
|
25
|
+
RSpec/NestedGroups:
|
|
26
|
+
Enabled: false
|
|
27
|
+
|
|
28
|
+
Style/FrozenStringLiteralComment:
|
|
29
|
+
Enabled: false
|
|
30
|
+
|
|
31
|
+
Style/Documentation:
|
|
32
|
+
Enabled: false
|
|
33
|
+
|
|
34
|
+
Style/StringLiterals:
|
|
35
|
+
Enabled: true
|
|
36
|
+
EnforcedStyle: double_quotes
|
|
37
|
+
|
|
38
|
+
Style/NumericLiterals:
|
|
39
|
+
Enabled: false
|
|
40
|
+
|
|
41
|
+
Style/StringLiteralsInInterpolation:
|
|
42
|
+
Enabled: true
|
|
43
|
+
EnforcedStyle: double_quotes
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
podcast_index (0.1.0)
|
|
5
|
+
activesupport (>= 6.0, < 8)
|
|
6
|
+
addressable (~> 2)
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
activesupport (6.1.7)
|
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
13
|
+
i18n (>= 1.6, < 2)
|
|
14
|
+
minitest (>= 5.1)
|
|
15
|
+
tzinfo (~> 2.0)
|
|
16
|
+
zeitwerk (~> 2.3)
|
|
17
|
+
addressable (2.8.1)
|
|
18
|
+
public_suffix (>= 2.0.2, < 6.0)
|
|
19
|
+
ast (2.4.2)
|
|
20
|
+
codecov (0.6.0)
|
|
21
|
+
simplecov (>= 0.15, < 0.22)
|
|
22
|
+
concurrent-ruby (1.1.10)
|
|
23
|
+
crack (0.4.5)
|
|
24
|
+
rexml
|
|
25
|
+
debug (1.7.1)
|
|
26
|
+
irb (>= 1.5.0)
|
|
27
|
+
reline (>= 0.3.1)
|
|
28
|
+
diff-lcs (1.5.0)
|
|
29
|
+
docile (1.4.0)
|
|
30
|
+
hashdiff (1.0.1)
|
|
31
|
+
i18n (1.12.0)
|
|
32
|
+
concurrent-ruby (~> 1.0)
|
|
33
|
+
io-console (0.6.0)
|
|
34
|
+
irb (1.6.2)
|
|
35
|
+
reline (>= 0.3.0)
|
|
36
|
+
json (2.6.3)
|
|
37
|
+
minitest (5.17.0)
|
|
38
|
+
parallel (1.22.1)
|
|
39
|
+
parser (3.1.3.0)
|
|
40
|
+
ast (~> 2.4.1)
|
|
41
|
+
public_suffix (5.0.1)
|
|
42
|
+
rainbow (3.1.1)
|
|
43
|
+
rake (13.0.6)
|
|
44
|
+
regexp_parser (2.6.1)
|
|
45
|
+
reline (0.3.2)
|
|
46
|
+
io-console (~> 0.5)
|
|
47
|
+
rexml (3.2.5)
|
|
48
|
+
rspec (3.12.0)
|
|
49
|
+
rspec-core (~> 3.12.0)
|
|
50
|
+
rspec-expectations (~> 3.12.0)
|
|
51
|
+
rspec-mocks (~> 3.12.0)
|
|
52
|
+
rspec-core (3.12.0)
|
|
53
|
+
rspec-support (~> 3.12.0)
|
|
54
|
+
rspec-expectations (3.12.1)
|
|
55
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
56
|
+
rspec-support (~> 3.12.0)
|
|
57
|
+
rspec-its (1.3.0)
|
|
58
|
+
rspec-core (>= 3.0.0)
|
|
59
|
+
rspec-expectations (>= 3.0.0)
|
|
60
|
+
rspec-mocks (3.12.1)
|
|
61
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
62
|
+
rspec-support (~> 3.12.0)
|
|
63
|
+
rspec-support (3.12.0)
|
|
64
|
+
rubocop (1.42.0)
|
|
65
|
+
json (~> 2.3)
|
|
66
|
+
parallel (~> 1.10)
|
|
67
|
+
parser (>= 3.1.2.1)
|
|
68
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
69
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
70
|
+
rexml (>= 3.2.5, < 4.0)
|
|
71
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
|
72
|
+
ruby-progressbar (~> 1.7)
|
|
73
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
74
|
+
rubocop-ast (1.24.1)
|
|
75
|
+
parser (>= 3.1.1.0)
|
|
76
|
+
rubocop-performance (1.14.2)
|
|
77
|
+
rubocop (>= 1.7.0, < 2.0)
|
|
78
|
+
rubocop-ast (>= 0.4.0)
|
|
79
|
+
rubocop-rake (0.6.0)
|
|
80
|
+
rubocop (~> 1.0)
|
|
81
|
+
rubocop-rspec (2.16.0)
|
|
82
|
+
rubocop (~> 1.33)
|
|
83
|
+
ruby-progressbar (1.11.0)
|
|
84
|
+
simplecov (0.21.2)
|
|
85
|
+
docile (~> 1.1)
|
|
86
|
+
simplecov-html (~> 0.11)
|
|
87
|
+
simplecov_json_formatter (~> 0.1)
|
|
88
|
+
simplecov-html (0.12.3)
|
|
89
|
+
simplecov_json_formatter (0.1.4)
|
|
90
|
+
tzinfo (2.0.5)
|
|
91
|
+
concurrent-ruby (~> 1.0)
|
|
92
|
+
unicode-display_width (2.3.0)
|
|
93
|
+
webmock (3.14.0)
|
|
94
|
+
addressable (>= 2.8.0)
|
|
95
|
+
crack (>= 0.3.2)
|
|
96
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
|
97
|
+
zeitwerk (2.6.6)
|
|
98
|
+
|
|
99
|
+
PLATFORMS
|
|
100
|
+
x86_64-darwin-20
|
|
101
|
+
x86_64-linux
|
|
102
|
+
|
|
103
|
+
DEPENDENCIES
|
|
104
|
+
codecov (~> 0.4)
|
|
105
|
+
debug (~> 1)
|
|
106
|
+
podcast_index!
|
|
107
|
+
rake (~> 13.0)
|
|
108
|
+
rspec (~> 3.0)
|
|
109
|
+
rspec-core (~> 3)
|
|
110
|
+
rspec-its (~> 1)
|
|
111
|
+
rubocop (~> 1.21)
|
|
112
|
+
rubocop-performance (~> 1)
|
|
113
|
+
rubocop-rake (~> 0.6)
|
|
114
|
+
rubocop-rspec (~> 2)
|
|
115
|
+
webmock (~> 3)
|
|
116
|
+
|
|
117
|
+
BUNDLED WITH
|
|
118
|
+
2.3.6
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Jason York
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# PodcastIndex
|
|
2
|
+
|
|
3
|
+
A Ruby client for the [podcastindex.org API](https://podcastindex-org.github.io/docs-api)
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
8
|
+
|
|
9
|
+
$ bundle add podcast_index
|
|
10
|
+
|
|
11
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
12
|
+
|
|
13
|
+
$ gem install podcast_index
|
|
14
|
+
|
|
15
|
+
## Configuration
|
|
16
|
+
|
|
17
|
+
Configure the [podcastindex.org API credentials](https://podcastindex-org.github.io/docs-api/#overview--authentication-details) before making any requests:
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
PodcastIndex.configure do |config|
|
|
21
|
+
config.api_key = "<your api key>"
|
|
22
|
+
config.api_secret = "<your api secret>"
|
|
23
|
+
end
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Additionally, the base url of the API defaults to `https://api.podcastindex.org/api/1.0`, but can be overridden in the configure block if necessary:
|
|
27
|
+
```ruby
|
|
28
|
+
config.base_url = "<new base url>"
|
|
29
|
+
````
|
|
30
|
+
|
|
31
|
+
In a Rails app, this configuration would typically be placed in an initializer file.
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
### Examples
|
|
36
|
+
|
|
37
|
+
Find a podcast by podcastindex id:
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
podcast = PodcastIndex::Podcast.find(920666)
|
|
41
|
+
podcast.title # => "Podcasting 2.0"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Find an episode by guid:
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
episode = PodcastIndex::Episode.find_by_guid("PC2084", feedurl: "http://mp3s.nashownotes.com/pc20rss.xml")
|
|
48
|
+
episode.title # => "Episode 84: All Aboard to On-Board!"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Methods that return multiple results are represented as an array of objects:
|
|
52
|
+
|
|
53
|
+
```ruby
|
|
54
|
+
episodes = PodcastIndex::Episode.find_by_person("Adam Curry")
|
|
55
|
+
episodes.count # => 57
|
|
56
|
+
episodes.first.title # => "Episode #2: A conversation with Adam Curry"
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Supported Methods
|
|
60
|
+
|
|
61
|
+
This client currently implements most of the API, focusing on searching for Podcasts and Episodes. For the list of supported methods, see the [Podcast](lib/podcast_index/podcast.rb) and [Episode](lib/podcast_index/episode.rb) models.
|
|
62
|
+
|
|
63
|
+
The attributes of the response object mirror the names in the API, but have been translated to "underscore" format more closely follow Ruby conventions. For example, the `lastUpdateTime` attribute for a `Podcast` is renamed to `last_update_time`.
|
|
64
|
+
|
|
65
|
+
### Exception Handling
|
|
66
|
+
|
|
67
|
+
If an error occurs, the client will raise a `PodcastIndex::Error` exception. The `message` field will contain the description returned from the server if available, or the exception message. For example, some request require one of three optional params:
|
|
68
|
+
|
|
69
|
+
```ruby
|
|
70
|
+
begin
|
|
71
|
+
episode = PodcastIndex::Episode.find_by_guid("PC2084")
|
|
72
|
+
rescue PodcastIndex::Error => e
|
|
73
|
+
puts e.message # => "This call requires either a valid `feedid`, `feedurl` or `podcastguid` argument. "
|
|
74
|
+
end
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Development
|
|
78
|
+
|
|
79
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
80
|
+
|
|
81
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
|
82
|
+
|
|
83
|
+
## Contributing
|
|
84
|
+
|
|
85
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jasonyork/podcast_index.
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module PodcastIndex
|
|
2
|
+
module Api
|
|
3
|
+
class Episodes
|
|
4
|
+
extend Request
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
def by_id(id:, fulltext: nil)
|
|
8
|
+
response = get("/episodes/byid", id: id, fulltext: fulltext)
|
|
9
|
+
JSON.parse(response.body)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def by_feed_id(id:, since: nil, max: nil, fulltext: nil)
|
|
13
|
+
response = get("/episodes/byfeedid", id: id, since: since, max: max, fulltext: fulltext)
|
|
14
|
+
JSON.parse(response.body)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def by_feed_url(url:, since: nil, max: nil, fulltext: nil)
|
|
18
|
+
response = get("/episodes/byfeedurl", url: url, since: since, max: max, fulltext: fulltext)
|
|
19
|
+
JSON.parse(response.body)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def by_guid(guid:, feedurl: nil, feedid: nil, fulltext: nil)
|
|
23
|
+
response = get("/episodes/byguid", guid: guid, feedurl: feedurl, feedid: feedid, fulltext: fulltext)
|
|
24
|
+
JSON.parse(response.body)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def by_itunes_id(id:, since: nil, max: nil, fulltext: nil)
|
|
28
|
+
response = get("/episodes/byitunesid", id: id, since: since, max: max, fulltext: fulltext)
|
|
29
|
+
JSON.parse(response.body)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module PodcastIndex
|
|
2
|
+
module Api
|
|
3
|
+
class Podcasts
|
|
4
|
+
extend Request
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
def by_feed_id(id:)
|
|
8
|
+
response = get("/podcasts/byfeedid", id: id)
|
|
9
|
+
JSON.parse(response.body)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def by_feed_url(url:)
|
|
13
|
+
response = get("/podcasts/byfeedurl", url: url)
|
|
14
|
+
JSON.parse(response.body)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def by_itunes_id(id:)
|
|
18
|
+
response = get("/podcasts/byitunesid", id: id)
|
|
19
|
+
JSON.parse(response.body)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def by_guid(guid:)
|
|
23
|
+
response = get("/podcasts/byguid", guid: guid)
|
|
24
|
+
JSON.parse(response.body)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require "addressable"
|
|
2
|
+
require "digest"
|
|
3
|
+
require "net/http"
|
|
4
|
+
|
|
5
|
+
module PodcastIndex
|
|
6
|
+
module Api
|
|
7
|
+
module Request
|
|
8
|
+
def get(path, params)
|
|
9
|
+
template = Addressable::Template.new("#{base_url}#{path}{?query*}")
|
|
10
|
+
uri = template.expand(query: sanitized_params(params))
|
|
11
|
+
handle_response(response_to(uri))
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def sanitized_params(params)
|
|
17
|
+
# The API only requires boolean params to only be present, so passing param like `clean=false` could provide
|
|
18
|
+
# unexpected results. This ensures `nil` and `false` values are removed.
|
|
19
|
+
params.select { |_k, v| v.present? }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def response_to(uri)
|
|
23
|
+
req = Net::HTTP::Get.new(uri)
|
|
24
|
+
add_headers(req)
|
|
25
|
+
|
|
26
|
+
Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
|
|
27
|
+
http.request(req)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def handle_response(response)
|
|
32
|
+
return response if response.is_a? Net::HTTPSuccess
|
|
33
|
+
|
|
34
|
+
message = begin
|
|
35
|
+
JSON.parse(response.body)["description"]
|
|
36
|
+
rescue JSON::ParserError
|
|
37
|
+
response.body.strip.present? ? response.body : response.message
|
|
38
|
+
end
|
|
39
|
+
raise PodcastIndex::Error, message
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def base_url
|
|
43
|
+
raise PodcastIndex::Error, "PodcastIndex: base_url must be configured." unless PodcastIndex.base_url.present?
|
|
44
|
+
|
|
45
|
+
PodcastIndex.base_url
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def api_key
|
|
49
|
+
raise PodcastIndex::Error, "PodcastIndex: api_key must be configured." unless PodcastIndex.api_key.present?
|
|
50
|
+
|
|
51
|
+
PodcastIndex.api_key
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def api_secret
|
|
55
|
+
unless PodcastIndex.api_secret.present?
|
|
56
|
+
raise PodcastIndex::Error, "PodcastIndex: api_secret must be configured."
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
PodcastIndex.api_secret
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def add_headers(request)
|
|
63
|
+
time = Time.now.to_i
|
|
64
|
+
|
|
65
|
+
request["User-Agent"] = "ruby-nethttp-podcast-index/#{PodcastIndex::VERSION}"
|
|
66
|
+
request["X-Auth-Key"] = api_key
|
|
67
|
+
request["X-Auth-Date"] = time
|
|
68
|
+
request["Authorization"] = request_digest(time)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def request_digest(time)
|
|
72
|
+
sha1 = Digest::SHA1.new
|
|
73
|
+
sha1.update [api_key, api_secret, time.to_s].join
|
|
74
|
+
sha1.hexdigest
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module PodcastIndex
|
|
2
|
+
module Api
|
|
3
|
+
class Search
|
|
4
|
+
extend Request
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
def by_term(term:, val: nil, aponly: nil, clean: nil, fulltext: nil)
|
|
8
|
+
response = get("/search/byterm", q: term, val: val, aponly: aponly, clean: clean, fulltext: fulltext)
|
|
9
|
+
JSON.parse(response.body)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def by_title(title:, val: nil, clean: nil, fulltext: nil, similar: nil)
|
|
13
|
+
response = get("/search/bytitle", q: title, val: val, clean: clean, fulltext: fulltext, similar: similar)
|
|
14
|
+
JSON.parse(response.body)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def by_person(person:, fulltext: nil)
|
|
18
|
+
response = get("/search/byperson", q: person, fulltext: fulltext)
|
|
19
|
+
JSON.parse(response.body)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# def music_by_term(term, val: nil, aponly: nil, clean: nil, fulltext: nil)
|
|
23
|
+
# response = get("/search/music/byterm", q: term, val:, aponly:, clean:, fulltext:)
|
|
24
|
+
# JSON.parse(response.body)
|
|
25
|
+
# end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require "ostruct"
|
|
2
|
+
require "delegate"
|
|
3
|
+
|
|
4
|
+
module PodcastIndex
|
|
5
|
+
class Episode < SimpleDelegator
|
|
6
|
+
class << self
|
|
7
|
+
def find(id, fulltext: nil)
|
|
8
|
+
response = Api::Episodes.by_id(id: id, fulltext: fulltext)
|
|
9
|
+
from_response(response)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def find_by_feed_id(feed_id, since: nil, max: nil, fulltext: nil)
|
|
13
|
+
response = Api::Episodes.by_feed_id(id: feed_id, since: since, max: max, fulltext: fulltext)
|
|
14
|
+
from_response_collection(response)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def find_by_feed_url(url, since: nil, max: nil, fulltext: nil)
|
|
18
|
+
response = Api::Episodes.by_feed_url(url: url, since: since, max: max, fulltext: fulltext)
|
|
19
|
+
from_response_collection(response)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def find_by_guid(guid, feedurl: nil, feedid: nil, fulltext: nil)
|
|
23
|
+
response = Api::Episodes.by_guid(guid: guid, feedurl: feedurl, feedid: feedid, fulltext: fulltext)
|
|
24
|
+
from_response(response)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def find_by_itunes_id(itunes_id, since: nil, max: nil, fulltext: nil)
|
|
28
|
+
response = Api::Episodes.by_itunes_id(id: itunes_id, since: since, max: max, fulltext: fulltext)
|
|
29
|
+
from_response_collection(response)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def find_by_person(person, fulltext: nil)
|
|
33
|
+
response = Api::Search.by_person(person: person, fulltext: fulltext)
|
|
34
|
+
from_response_collection(response)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def from_response(response)
|
|
40
|
+
feed = response["episode"].transform_keys(&:underscore)
|
|
41
|
+
new(JSON.parse(feed.to_json, object_class: OpenStruct)) # rubocop:disable Style/OpenStructUse
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def from_response_collection(response)
|
|
45
|
+
response["items"].map do |item|
|
|
46
|
+
episode = item.transform_keys(&:underscore)
|
|
47
|
+
new(JSON.parse(episode.to_json, object_class: OpenStruct)) # rubocop:disable Style/OpenStructUse
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require "ostruct"
|
|
2
|
+
require "delegate"
|
|
3
|
+
|
|
4
|
+
module PodcastIndex
|
|
5
|
+
class Podcast < SimpleDelegator
|
|
6
|
+
class << self
|
|
7
|
+
def find(id)
|
|
8
|
+
response = Api::Podcasts.by_feed_id(id: id)
|
|
9
|
+
from_response(response)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def find_by_feed_url(url)
|
|
13
|
+
response = Api::Podcasts.by_feed_url(url: url)
|
|
14
|
+
from_response(response)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def find_by_guid(guid)
|
|
18
|
+
response = Api::Podcasts.by_guid(guid: guid)
|
|
19
|
+
from_response(response)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def find_by_itunes_id(id)
|
|
23
|
+
response = Api::Podcasts.by_itunes_id(id: id)
|
|
24
|
+
from_response(response)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def find_by_term(term, val: nil, aponly: nil, clean: nil, fulltext: nil)
|
|
28
|
+
response = Api::Search.by_term(term: term, val: val, aponly: aponly, clean: clean, fulltext: fulltext)
|
|
29
|
+
from_response_collection(response)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def find_by_title(title, val: nil, clean: nil, fulltext: nil)
|
|
33
|
+
response = Api::Search.by_title(title: title, val: val, clean: clean, fulltext: fulltext)
|
|
34
|
+
from_response_collection(response)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def from_response(response)
|
|
40
|
+
feed = response["feed"].transform_keys(&:underscore)
|
|
41
|
+
new(JSON.parse(feed.to_json, object_class: OpenStruct)) # rubocop:disable Style/OpenStructUse
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def from_response_collection(response)
|
|
45
|
+
response["feeds"].map do |item|
|
|
46
|
+
episode = item.transform_keys(&:underscore)
|
|
47
|
+
new(JSON.parse(episode.to_json, object_class: OpenStruct)) # rubocop:disable Style/OpenStructUse
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require_relative "podcast_index/version"
|
|
2
|
+
require "active_support/configurable"
|
|
3
|
+
require "active_support/core_ext/string/inflections"
|
|
4
|
+
require "json"
|
|
5
|
+
|
|
6
|
+
require_relative "podcast_index/api/request"
|
|
7
|
+
require_relative "podcast_index/api/podcasts"
|
|
8
|
+
require_relative "podcast_index/api/episodes"
|
|
9
|
+
require_relative "podcast_index/api/search"
|
|
10
|
+
require_relative "podcast_index/podcast"
|
|
11
|
+
require_relative "podcast_index/episode"
|
|
12
|
+
|
|
13
|
+
module PodcastIndex
|
|
14
|
+
include ActiveSupport::Configurable
|
|
15
|
+
|
|
16
|
+
config_accessor :api_key, :api_secret, :base_url
|
|
17
|
+
|
|
18
|
+
class Error < StandardError; end
|
|
19
|
+
|
|
20
|
+
def self.configure
|
|
21
|
+
self.base_url = "https://api.podcastindex.org/api/1.0".freeze
|
|
22
|
+
super
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require_relative "lib/podcast_index/version"
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = "podcast_index"
|
|
5
|
+
spec.version = PodcastIndex::VERSION
|
|
6
|
+
spec.authors = ["Jason York"]
|
|
7
|
+
|
|
8
|
+
spec.summary = "Ruby client for the podcastindex.org API"
|
|
9
|
+
spec.description = "Exposes the podcastindex.org API through Ruby domain models."
|
|
10
|
+
spec.homepage = "https://github.com/jasonyork/podcast-index"
|
|
11
|
+
spec.license = "MIT"
|
|
12
|
+
spec.required_ruby_version = ">= 3.0.0"
|
|
13
|
+
|
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
15
|
+
spec.metadata["source_code_uri"] = "https://github.com/jasonyork/podcast-index"
|
|
16
|
+
spec.metadata["changelog_uri"] = "https://github.com/jasonyork/podcast-index/blob/master/CHANGELOG.md"
|
|
17
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
18
|
+
|
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
21
|
+
spec.files = Dir.chdir(__dir__) do
|
|
22
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
23
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
spec.bindir = "exe"
|
|
27
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
28
|
+
spec.require_paths = ["lib"]
|
|
29
|
+
|
|
30
|
+
spec.add_dependency "activesupport", ">= 6.0", "< 8"
|
|
31
|
+
spec.add_dependency "addressable", "~> 2"
|
|
32
|
+
|
|
33
|
+
spec.add_development_dependency "codecov", "~> 0.4"
|
|
34
|
+
spec.add_development_dependency "debug", "~> 1"
|
|
35
|
+
spec.add_development_dependency "rspec-core", "~> 3"
|
|
36
|
+
spec.add_development_dependency "rspec-its", "~> 1"
|
|
37
|
+
spec.add_development_dependency "rubocop-performance", "~> 1"
|
|
38
|
+
spec.add_development_dependency "rubocop-rake", "~> 0.6"
|
|
39
|
+
spec.add_development_dependency "rubocop-rspec", "~> 2"
|
|
40
|
+
spec.add_development_dependency "webmock", "~> 3"
|
|
41
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: podcast_index
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jason York
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2023-01-07 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activesupport
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '6.0'
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '8'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '6.0'
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '8'
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: addressable
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '2'
|
|
40
|
+
type: :runtime
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '2'
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: codecov
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0.4'
|
|
54
|
+
type: :development
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0.4'
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: debug
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '1'
|
|
68
|
+
type: :development
|
|
69
|
+
prerelease: false
|
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '1'
|
|
75
|
+
- !ruby/object:Gem::Dependency
|
|
76
|
+
name: rspec-core
|
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '3'
|
|
82
|
+
type: :development
|
|
83
|
+
prerelease: false
|
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '3'
|
|
89
|
+
- !ruby/object:Gem::Dependency
|
|
90
|
+
name: rspec-its
|
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - "~>"
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '1'
|
|
96
|
+
type: :development
|
|
97
|
+
prerelease: false
|
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - "~>"
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '1'
|
|
103
|
+
- !ruby/object:Gem::Dependency
|
|
104
|
+
name: rubocop-performance
|
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - "~>"
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '1'
|
|
110
|
+
type: :development
|
|
111
|
+
prerelease: false
|
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - "~>"
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '1'
|
|
117
|
+
- !ruby/object:Gem::Dependency
|
|
118
|
+
name: rubocop-rake
|
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - "~>"
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '0.6'
|
|
124
|
+
type: :development
|
|
125
|
+
prerelease: false
|
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - "~>"
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '0.6'
|
|
131
|
+
- !ruby/object:Gem::Dependency
|
|
132
|
+
name: rubocop-rspec
|
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - "~>"
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '2'
|
|
138
|
+
type: :development
|
|
139
|
+
prerelease: false
|
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
141
|
+
requirements:
|
|
142
|
+
- - "~>"
|
|
143
|
+
- !ruby/object:Gem::Version
|
|
144
|
+
version: '2'
|
|
145
|
+
- !ruby/object:Gem::Dependency
|
|
146
|
+
name: webmock
|
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
|
148
|
+
requirements:
|
|
149
|
+
- - "~>"
|
|
150
|
+
- !ruby/object:Gem::Version
|
|
151
|
+
version: '3'
|
|
152
|
+
type: :development
|
|
153
|
+
prerelease: false
|
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
155
|
+
requirements:
|
|
156
|
+
- - "~>"
|
|
157
|
+
- !ruby/object:Gem::Version
|
|
158
|
+
version: '3'
|
|
159
|
+
description: Exposes the podcastindex.org API through Ruby domain models.
|
|
160
|
+
email:
|
|
161
|
+
executables: []
|
|
162
|
+
extensions: []
|
|
163
|
+
extra_rdoc_files: []
|
|
164
|
+
files:
|
|
165
|
+
- ".rspec"
|
|
166
|
+
- ".rubocop.yml"
|
|
167
|
+
- CHANGELOG.md
|
|
168
|
+
- Gemfile
|
|
169
|
+
- Gemfile.lock
|
|
170
|
+
- LICENSE.txt
|
|
171
|
+
- README.md
|
|
172
|
+
- Rakefile
|
|
173
|
+
- lib/podcast_index.rb
|
|
174
|
+
- lib/podcast_index/api/episodes.rb
|
|
175
|
+
- lib/podcast_index/api/podcasts.rb
|
|
176
|
+
- lib/podcast_index/api/request.rb
|
|
177
|
+
- lib/podcast_index/api/search.rb
|
|
178
|
+
- lib/podcast_index/episode.rb
|
|
179
|
+
- lib/podcast_index/podcast.rb
|
|
180
|
+
- lib/podcast_index/version.rb
|
|
181
|
+
- podcast_index.gemspec
|
|
182
|
+
homepage: https://github.com/jasonyork/podcast-index
|
|
183
|
+
licenses:
|
|
184
|
+
- MIT
|
|
185
|
+
metadata:
|
|
186
|
+
homepage_uri: https://github.com/jasonyork/podcast-index
|
|
187
|
+
source_code_uri: https://github.com/jasonyork/podcast-index
|
|
188
|
+
changelog_uri: https://github.com/jasonyork/podcast-index/blob/master/CHANGELOG.md
|
|
189
|
+
rubygems_mfa_required: 'true'
|
|
190
|
+
post_install_message:
|
|
191
|
+
rdoc_options: []
|
|
192
|
+
require_paths:
|
|
193
|
+
- lib
|
|
194
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
195
|
+
requirements:
|
|
196
|
+
- - ">="
|
|
197
|
+
- !ruby/object:Gem::Version
|
|
198
|
+
version: 3.0.0
|
|
199
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
|
+
requirements:
|
|
201
|
+
- - ">="
|
|
202
|
+
- !ruby/object:Gem::Version
|
|
203
|
+
version: '0'
|
|
204
|
+
requirements: []
|
|
205
|
+
rubygems_version: 3.3.4
|
|
206
|
+
signing_key:
|
|
207
|
+
specification_version: 4
|
|
208
|
+
summary: Ruby client for the podcastindex.org API
|
|
209
|
+
test_files: []
|