Skip to content

Commit

Permalink
Initial version 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonyork committed Jan 7, 2023
0 parents commit f78a324
Show file tree
Hide file tree
Showing 42 changed files with 14,193 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Ruby

on:
push:
branches:
- master

pull_request:

jobs:
build:
runs-on: ubuntu-latest
name: Ruby ${{ matrix.ruby }}
strategy:
matrix:
ruby:
- '3.1.2'

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run the default task
run: bundle exec rake
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/

# rspec failure tracking
.rspec_status

# rubymine
/.idea/

*.gem

2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
43 changes: 43 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require:
- rubocop-performance
- rubocop-rake
- rubocop-rspec

AllCops:
TargetRubyVersion: 3.0
NewCops: enable

Layout/AccessModifierIndentation:
EnforcedStyle: outdent

Layout/LineLength:
Max: 120

Metrics/AbcSize:
Exclude:
- spec/**/*

Metrics/BlockLength:
Exclude:
- spec/**/*
- "*.gemspec"

RSpec/NestedGroups:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: false

Style/Documentation:
Enabled: false

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes

Style/NumericLiterals:
Enabled: false

Style/StringLiteralsInInterpolation:
Enabled: true
EnforcedStyle: double_quotes
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## [Unreleased]

## [0.1.0] - 2023-01-06

- Initial release
10 changes: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
source "https://rubygems.org"

# Specify your gem's dependencies in podcast_index.gemspec
gemspec

gem "rake", "~> 13.0"

gem "rspec", "~> 3.0"

gem "rubocop", "~> 1.21"
118 changes: 118 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
PATH
remote: .
specs:
podcast_index (0.1.0)
activesupport (>= 6.0, < 8)
addressable (~> 2)

GEM
remote: https://rubygems.org/
specs:
activesupport (6.1.7)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.8.1)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
codecov (0.6.0)
simplecov (>= 0.15, < 0.22)
concurrent-ruby (1.1.10)
crack (0.4.5)
rexml
debug (1.7.1)
irb (>= 1.5.0)
reline (>= 0.3.1)
diff-lcs (1.5.0)
docile (1.4.0)
hashdiff (1.0.1)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
io-console (0.6.0)
irb (1.6.2)
reline (>= 0.3.0)
json (2.6.3)
minitest (5.17.0)
parallel (1.22.1)
parser (3.1.3.0)
ast (~> 2.4.1)
public_suffix (5.0.1)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.6.1)
reline (0.3.2)
io-console (~> 0.5)
rexml (3.2.5)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.0)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-its (1.3.0)
rspec-core (>= 3.0.0)
rspec-expectations (>= 3.0.0)
rspec-mocks (3.12.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.0)
rubocop (1.42.0)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.1.2.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.24.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.24.1)
parser (>= 3.1.1.0)
rubocop-performance (1.14.2)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (2.16.0)
rubocop (~> 1.33)
ruby-progressbar (1.11.0)
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
unicode-display_width (2.3.0)
webmock (3.14.0)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
zeitwerk (2.6.6)

PLATFORMS
x86_64-darwin-20
x86_64-linux

DEPENDENCIES
codecov (~> 0.4)
debug (~> 1)
podcast_index!
rake (~> 13.0)
rspec (~> 3.0)
rspec-core (~> 3)
rspec-its (~> 1)
rubocop (~> 1.21)
rubocop-performance (~> 1)
rubocop-rake (~> 0.6)
rubocop-rspec (~> 2)
webmock (~> 3)

BUNDLED WITH
2.3.6
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2023 Jason York

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
89 changes: 89 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# PodcastIndex

A Ruby client for the [podcastindex.org API](https://podcastindex-org.github.io/docs-api)

## Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add podcast_index

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install podcast_index

## Configuration

Configure the [podcastindex.org API credentials](https://podcastindex-org.github.io/docs-api/#overview--authentication-details) before making any requests:

```ruby
PodcastIndex.configure do |config|
config.api_key = "<your api key>"
config.api_secret = "<your api secret>"
end
```

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:
```ruby
config.base_url = "<new base url>"
````

In a Rails app, this configuration would typically be placed in an initializer file.

## Usage

### Examples

Find a podcast by podcastindex id:

```ruby
podcast = PodcastIndex::Podcast.find(920666)
podcast.title # => "Podcasting 2.0"
```

Find an episode by guid:

```ruby
episode = PodcastIndex::Episode.find_by_guid("PC2084", feedurl: "http://mp3s.nashownotes.com/pc20rss.xml")
episode.title # => "Episode 84: All Aboard to On-Board!"
```

Methods that return multiple results are represented as an array of objects:

```ruby
episodes = PodcastIndex::Episode.find_by_person("Adam Curry")
episodes.count # => 57
episodes.first.title # => "Episode #2: A conversation with Adam Curry"
```

### Supported Methods

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.

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`.

### Exception Handling

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:

```ruby
begin
episode = PodcastIndex::Episode.find_by_guid("PC2084")
rescue PodcastIndex::Error => e
puts e.message # => "This call requires either a valid `feedid`, `feedurl` or `podcastguid` argument. "
end
```

## Development

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.

To install this gem onto your local machine, run `bundle exec rake install`.

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/jasonyork/podcast_index.

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

require "rubocop/rake_task"

RuboCop::RakeTask.new

task default: %i[spec rubocop]
13 changes: 13 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env ruby
require "bundler/setup"
require "podcast_index"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start

require "irb"
IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
24 changes: 24 additions & 0 deletions lib/podcast_index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require_relative "podcast_index/version"
require "active_support/configurable"
require "active_support/core_ext/string/inflections"
require "json"

require_relative "podcast_index/api/request"
require_relative "podcast_index/api/podcasts"
require_relative "podcast_index/api/episodes"
require_relative "podcast_index/api/search"
require_relative "podcast_index/podcast"
require_relative "podcast_index/episode"

module PodcastIndex
include ActiveSupport::Configurable

config_accessor :api_key, :api_secret, :base_url

class Error < StandardError; end

def self.configure
self.base_url = "https://api.podcastindex.org/api/1.0".freeze
super
end
end
Loading

0 comments on commit f78a324

Please sign in to comment.