enklawa 0.0.1

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NjQyOTExMjY5MTJlY2UzYmU2YzA4OWQ1NjgyM2IxY2VjY2FmZjhlOA==
5
+ data.tar.gz: !binary |-
6
+ MjJlOTI1MmU3YjBiZjkwNDZkMTM3OWNmOGVjNjdiMGFmZTFkYzlkNw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZWE3ZGIzNWRlYTNiMjg0ZmU3NWZjNTNmYmYwMDM2M2I1ZThjM2EwYWE1ZTFl
10
+ YTVmNTI1ZmYzN2RmYzA3MGNmMTk0MGVkNmU3MWRiZDhhZTZjNWVhOTMzNjJl
11
+ ZTYxNjYxYWU4M2FjNTNhNTA1YmI2NDdiY2ViYzY0NDA5NmU1M2I=
12
+ data.tar.gz: !binary |-
13
+ MDhlZTE0OGEzODc0YmUzYjU1ODBmYTU3ZjJiZDUwYTFmOTY3OWFhZjY4MTMx
14
+ NjA2NTRkMTUwYzNhZDZiZmIxZTNlMjdmZjg1YTk4ZDU4YjE2ZDZhMzdkN2E1
15
+ M2MxNGRlNmFjMDQyYmFjYmQwYmFlNjQ4MWFhMzZkOWNmMGVjNDk=
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in enklawa-api.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,17 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ # Note: The cmd option is now required due to the increasing number of ways
5
+ # rspec may be run, below are examples of the most common uses.
6
+ # * bundler: 'bundle exec rspec'
7
+ # * bundler binstubs: 'bin/rspec'
8
+ # * spring: 'bin/rsspec' (This will use spring if running and you have
9
+ # installed the spring binstubs per the docs)
10
+ # * zeus: 'zeus rspec' (requires the server to be started separetly)
11
+ # * 'just' rspec: 'rspec'
12
+ guard :rspec, cmd: 'bundle exec rspec' do
13
+ watch(%r{^spec/.+_spec\.rb$})
14
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
15
+ watch('spec/spec_helper.rb') { "spec" }
16
+
17
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Arkadiusz Buras
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Enklawa::Api
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'enklawa-api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install enklawa-api
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/enklawa-api/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/enklawa ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $:.push File.expand_path("../../lib", __FILE__)
3
+ require File.join(File.expand_path("../../lib", __FILE__), "enklawa/api")
4
+ require File.join(File.expand_path("../../lib", __FILE__), "enklawa/cli")
5
+ Enklawa::Cli.start(ARGV)
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'enklawa/api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "enklawa"
8
+ spec.version = Enklawa::Api::VERSION
9
+ spec.authors = ["Arkadiusz Buras"]
10
+ spec.email = ["macbury@gmail.com"]
11
+ spec.summary = %q{Simple gem for extracting api information from enklawa.net}
12
+ spec.description = %q{Simple gem for extracting api information from enklawa.net}
13
+ spec.homepage = "http://macbury.ninja"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "json"
22
+ spec.add_dependency "pry"
23
+ spec.add_dependency "thor"
24
+ spec.add_dependency "sanitize"
25
+ spec.add_dependency "nokogiri"
26
+ spec.add_dependency "feedjira", "~> 1.4"
27
+ spec.add_development_dependency "webmock"
28
+ spec.add_development_dependency "rspec", "~> 3.1"
29
+ spec.add_development_dependency "bundler", "~> 1.6"
30
+ spec.add_development_dependency "rake"
31
+ spec.add_development_dependency "guard-rspec"
32
+ end
@@ -0,0 +1,19 @@
1
+ require "enklawa/api/version"
2
+ require "enklawa/api/response"
3
+ require "enklawa/api/program"
4
+ require "enklawa/api/episode"
5
+ require "enklawa/api/request"
6
+ require "open-uri"
7
+ require "nokogiri"
8
+ require "json"
9
+ require "cgi"
10
+ module Enklawa
11
+ module Api
12
+
13
+ def self.fetch
14
+ request = Request.new
15
+ request.get!
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ module Enklawa
2
+ module Api
3
+ class Episode < Struct.new(:id, :name, :description, :mp3, :pub_date, :link, :duration)
4
+
5
+ def image
6
+ "http://www.enklawa.net/images/episodes/#{id}.jpg"
7
+ end
8
+
9
+ def to_h
10
+ {
11
+ id: id,
12
+ name: name,
13
+ description: description,
14
+ mp3: mp3,
15
+ pub_date: pub_date,
16
+ link: link,
17
+ duration: duration,
18
+ image: image
19
+ }
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ module Enklawa
2
+ module Api
3
+ class Program < Struct.new(:id, :name, :description, :author, :live)
4
+ attr_accessor :episodes
5
+
6
+ def initialize
7
+ self.episodes = []
8
+ end
9
+
10
+ def image
11
+ "http://www.enklawa.net/images/programs/#{id}.jpg"
12
+ end
13
+
14
+ def <<(episode)
15
+ self.episodes << episode
16
+ end
17
+
18
+ def feed_url
19
+ "http://www.enklawa.net/program#{self.id}.xml"
20
+ end
21
+
22
+ def to_h
23
+ {
24
+ id: id,
25
+ name: name,
26
+ description: description,
27
+ author: author,
28
+ live: live,
29
+ image: image,
30
+ feed_url: feed_url,
31
+ episodes: episodes.map(&:to_h)
32
+ }
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,74 @@
1
+ require "feedjira"
2
+ require "sanitize"
3
+
4
+ module Enklawa
5
+ module Api
6
+ class Request
7
+ INFO_XML_URL = "http://www.enklawa.net/info.xml"
8
+
9
+ def initialize
10
+
11
+ end
12
+
13
+ def get!
14
+ @response = Response.new
15
+ get_info!
16
+ get_programs!
17
+ get_episodes!
18
+
19
+ @response
20
+ end
21
+
22
+ private
23
+
24
+ def get_info!
25
+ @info_xml_doc = Nokogiri::XML(open(INFO_XML_URL).read)
26
+
27
+ @response.skype = @info_xml_doc.search("settings call skype").text
28
+ @response.phone = @info_xml_doc.search("settings call phone").text
29
+
30
+ shoutcast_pls_url = "http:"+CGI.unescape(@info_xml_doc.search("settings listen shoutcast").text)
31
+ @response.radio = open(shoutcast_pls_url).read.strip.split("\n")[-1].gsub("File1=","")
32
+ end
33
+
34
+ def get_programs!
35
+ @info_xml_doc.search("programs p").each do |program_node|
36
+ program = Program.new
37
+ program.id = program_node[:id].to_i
38
+ program.name = program_node.search("name").text
39
+ program.description = program_node.search("description").text
40
+ program.author = program_node.search("author").text
41
+ program.live = program_node.search("live").size > 0
42
+ @response.programs << program
43
+ end
44
+ end
45
+
46
+ def get_episodes!
47
+ @response.programs.each do |program|
48
+ feed = Feedjira::Feed.fetch_and_parse(program.feed_url)
49
+ next if feed == 404
50
+ feed.entries.each do |entry|
51
+ build_episode_from_entry(entry, program)
52
+ end
53
+ end
54
+
55
+ @response.programs.reject! { |program| program.episodes.empty? }
56
+ end
57
+
58
+ def build_episode_from_entry(entry, program)
59
+ episode = Episode.new
60
+ episode.id = entry.id
61
+ episode.name = entry.title.split("-")[-1].strip
62
+ episode.mp3 = entry.enclosure_url
63
+ episode.link = entry.url
64
+ episode.description = Sanitize.clean(entry.summary).strip
65
+ episode.pub_date = entry.published
66
+
67
+ if episode.mp3
68
+ episode.duration = entry.enclosure_length.to_i
69
+ program << episode
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,33 @@
1
+ module Enklawa
2
+ module Api
3
+ class Response
4
+ attr_accessor :skype, :phone, :radio
5
+
6
+ def initialize
7
+ @programs = []
8
+ end
9
+
10
+ def programs
11
+ @programs
12
+ end
13
+
14
+ def <<(program)
15
+ @programs << program
16
+ end
17
+
18
+ def to_h
19
+ {
20
+ skype: skype,
21
+ phone: phone,
22
+ radio: radio,
23
+ programs: @programs.map(&:to_h)
24
+ }
25
+ end
26
+
27
+ def save(filename)
28
+ json = JSON.pretty_generate(to_h)
29
+ File.open(filename, "w") { |f| f.write json }
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ module Enklawa
2
+ module Api
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ require "thor"
2
+ require "pry"
3
+ module Enklawa
4
+ class Cli < Thor
5
+
6
+ desc "console", "simple console playground"
7
+ def console
8
+ @response = Enklawa::Api.fetch
9
+ binding.pry
10
+ end
11
+
12
+ desc "save", "fetch and save episodes"
13
+ def save(path)
14
+ @response = Enklawa::Api.fetch
15
+ @response.save(path)
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Enklawa::Api do
4
+ describe "for fetching all info.xml and feed data" do
5
+ let(:response) { @response ||= Enklawa::Api.fetch }
6
+
7
+ it "should have basic information about response" do
8
+ expect(response).not_to be_nil
9
+ expect(response.class).to be(Enklawa::Api::Response)
10
+ expect(response.skype).not_to be_nil
11
+ expect(response.phone).not_to be_nil
12
+ expect(response.radio).not_to be_nil
13
+ end
14
+
15
+ it "should have programs and episodes" do
16
+ response.programs.each do |program|
17
+ expect(program.id).not_to be_nil
18
+ expect(program.image).not_to be_nil
19
+ expect(program.name).not_to be_nil
20
+ expect(program.description).not_to be_nil
21
+ expect(program.author).not_to be_nil
22
+ expect(program.live).not_to be_nil
23
+
24
+ program.episodes.each do |episode|
25
+ expect(episode.id).not_to be_nil
26
+ expect(episode.name).not_to be_nil
27
+ expect(episode.description).not_to be_nil
28
+ expect(episode.image).not_to be_nil
29
+ expect(episode.mp3).not_to be_nil
30
+ expect(episode.pub_date).not_to be_nil
31
+ expect(episode.link).not_to be_nil
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,10 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'enklawa/api'
5
+
6
+ RSpec.configure do |config|
7
+
8
+
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,219 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enklawa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Arkadiusz Buras
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sanitize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: feedjira
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.4'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '3.1'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '3.1'
125
+ - !ruby/object:Gem::Dependency
126
+ name: bundler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: '1.6'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: '1.6'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rake
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: guard-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: Simple gem for extracting api information from enklawa.net
168
+ email:
169
+ - macbury@gmail.com
170
+ executables:
171
+ - enklawa
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - .gitignore
176
+ - .rspec
177
+ - Gemfile
178
+ - Guardfile
179
+ - LICENSE.txt
180
+ - README.md
181
+ - Rakefile
182
+ - bin/enklawa
183
+ - enklawa-api.gemspec
184
+ - lib/enklawa/api.rb
185
+ - lib/enklawa/api/episode.rb
186
+ - lib/enklawa/api/program.rb
187
+ - lib/enklawa/api/request.rb
188
+ - lib/enklawa/api/response.rb
189
+ - lib/enklawa/api/version.rb
190
+ - lib/enklawa/cli.rb
191
+ - spec/lib/api_spec.rb
192
+ - spec/spec_helper.rb
193
+ homepage: http://macbury.ninja
194
+ licenses:
195
+ - MIT
196
+ metadata: {}
197
+ post_install_message:
198
+ rdoc_options: []
199
+ require_paths:
200
+ - lib
201
+ required_ruby_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ required_rubygems_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - ! '>='
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ requirements: []
212
+ rubyforge_project:
213
+ rubygems_version: 2.2.2
214
+ signing_key:
215
+ specification_version: 4
216
+ summary: Simple gem for extracting api information from enklawa.net
217
+ test_files:
218
+ - spec/lib/api_spec.rb
219
+ - spec/spec_helper.rb