podwrap 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f4d857c9eaf0dcd50574845c92b81fdd45811d7c58a1e4d4e9d66ca5389db54c
4
+ data.tar.gz: bf6ade576d33491b0f38e3a147b4b4bf9ae3fb75f9778b0e803f871ff2153ee9
5
+ SHA512:
6
+ metadata.gz: ac83b3713bb25dddc4f59b76ff836823222fae5debe26bc799447ed458677daf04d9d7ca3d0c11ee8dda7606d8aa82b7cad8d5f9866e0881e1f7be5b92772b7b
7
+ data.tar.gz: 57a9187206cf3565300336727d535b1e618f9066fde118cf9245cf67ed73061a1ec219368fa545c437873166e836565205e6e1eab0522d52302f1c16fc0300e2
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 2.0.1
8
+
9
+ script: bundle exec rspec -f p
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in podwrap.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ podwrap (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.8.0)
12
+ rspec-core (~> 3.8.0)
13
+ rspec-expectations (~> 3.8.0)
14
+ rspec-mocks (~> 3.8.0)
15
+ rspec-core (3.8.0)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-expectations (3.8.2)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-mocks (3.8.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-support (3.8.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 2.0)
30
+ podwrap!
31
+ rake (~> 10.0)
32
+ rspec (~> 3.0)
33
+
34
+ BUNDLED WITH
35
+ 2.0.1
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ [![Build
2
+ Status](https://travis-ci.com/prrrnd/podwrap.svg?branch=master)](https://travis-ci.com/prrrnd/podwrap)
3
+
4
+ # Podwrap
5
+
6
+ Simple RSS wrapper for podcast feed parsing
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'podwrap'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install podwrap
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ require 'open-uri'
28
+
29
+ rss = open("https://www.listennotes.com/c/r/a1288f394105460dbafc09587acfa336")
30
+ show = Podwrap::Parser.new(rss).build
31
+
32
+ show.title # => "TRAINED"
33
+ show.episodes.size # => 12
34
+ ```
35
+
36
+ ## Development
37
+
38
+ 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.
39
+
40
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/prrrnd/podwrap.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "podwrap"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/episode.rb ADDED
@@ -0,0 +1,22 @@
1
+ module Podwrap
2
+ class Episode
3
+ MAPPING = {
4
+ title: [:title],
5
+ description: [:content_encoded, :content, :description, :itunes_summary],
6
+ published_at: [:pubDate, :published, :dc_date, :issued],
7
+ explicit: [:explicit, :itunes_explicit],
8
+ keywords: [:keywords, :itunes_keywords],
9
+ track: [:enclosure]
10
+ }.freeze
11
+
12
+ attr_accessor(*MAPPING.keys.freeze)
13
+
14
+ def track=(value)
15
+ @track = value&.url
16
+ end
17
+
18
+ def explicit=(value)
19
+ @explicit = value == "yes" || false
20
+ end
21
+ end
22
+ end
data/lib/podwrap.rb ADDED
@@ -0,0 +1,56 @@
1
+ require "podwrap/version"
2
+
3
+ require "rss"
4
+
5
+ require_relative "show"
6
+ require_relative "episode"
7
+
8
+ module Podwrap
9
+ class Error < StandardError; end
10
+
11
+ class Parser
12
+ attr_reader :rss, :xml
13
+
14
+ def initialize(xml)
15
+ @xml = xml
16
+ @rss = RSS::Parser.parse(xml)
17
+ end
18
+
19
+ def build
20
+ show = build_show(rss.channel)
21
+ show.episodes = build_episodes(rss.channel.items)
22
+ show
23
+ end
24
+
25
+ private
26
+
27
+ def build_show(channel)
28
+ show = ::Podwrap::Show.new
29
+ ::Podwrap::Show::MAPPING.each do |attr, methods|
30
+ show.send(:"#{attr}=", grab(methods, channel))
31
+ end
32
+ show
33
+ end
34
+
35
+ def build_episodes(items)
36
+ items.map do |item|
37
+ episode = ::Podwrap::Episode.new
38
+ ::Podwrap::Episode::MAPPING.each do |attr, methods|
39
+ episode.send(:"#{attr}=", grab(methods, item))
40
+ end
41
+ episode
42
+ end
43
+ end
44
+
45
+ def grab(methods, src)
46
+ methods.each do |m|
47
+ if src.respond_to?(m)
48
+ value = src.send(m)
49
+ return value unless value.nil?
50
+ end
51
+ end
52
+
53
+ nil
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ module Podwrap
2
+ VERSION = "0.1.0"
3
+ end
data/lib/show.rb ADDED
@@ -0,0 +1,28 @@
1
+ module Podwrap
2
+ class Show
3
+ MAPPING = {
4
+ title: [:title],
5
+ language: [:language],
6
+ description: [:content_encoded, :content, :description],
7
+ cover: [:itunes_image, :image],
8
+ category: [:itunes_category],
9
+ author: [:author, :itunes_author],
10
+ }.freeze
11
+
12
+ attr_accessor(*MAPPING.keys.freeze)
13
+ attr_accessor :episodes
14
+
15
+ def cover=(value)
16
+ case value.class.to_s
17
+ when "RSS::ITunesChannelModel::ITunesImage"
18
+ @cover = value&.href
19
+ else
20
+ @cover = value&.url
21
+ end
22
+ end
23
+
24
+ def category=(value)
25
+ @category = value&.text
26
+ end
27
+ end
28
+ end
data/podwrap.gemspec ADDED
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "podwrap/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "podwrap"
8
+ spec.version = Podwrap::VERSION
9
+ spec.authors = ["prrrnd"]
10
+ spec.email = ["pierre.baciocchini@gmail.com"]
11
+
12
+ spec.summary = %q{Simple RSS wrapper for podcast feed parsing}
13
+ spec.homepage = "https://github.com/prrrnd/podwrap"
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = spec.homepage
21
+ spec.metadata["changelog_uri"] = "https://github.com/prrrnd/podwrap/blob/master/CHANGELOG.md"
22
+ else
23
+ raise "RubyGems 2.0 or newer is required to protect against " \
24
+ "public gem pushes."
25
+ end
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ end
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_development_dependency "bundler", "~> 2.0"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: podwrap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - prrrnd
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - pierre.baciocchini@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/episode.rb
72
+ - lib/podwrap.rb
73
+ - lib/podwrap/version.rb
74
+ - lib/show.rb
75
+ - podwrap.gemspec
76
+ homepage: https://github.com/prrrnd/podwrap
77
+ licenses: []
78
+ metadata:
79
+ allowed_push_host: https://rubygems.org
80
+ homepage_uri: https://github.com/prrrnd/podwrap
81
+ source_code_uri: https://github.com/prrrnd/podwrap
82
+ changelog_uri: https://github.com/prrrnd/podwrap/blob/master/CHANGELOG.md
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.7.6
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Simple RSS wrapper for podcast feed parsing
103
+ test_files: []