enklawa 0.1.4 → 0.2
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 +8 -8
- data/.gitignore +2 -0
- data/lib/enklawa/api.rb +2 -2
- data/lib/enklawa/api/program.rb +7 -3
- data/lib/enklawa/api/request.rb +11 -40
- data/lib/enklawa/api/version.rb +1 -1
- data/lib/enklawa/cli.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDA1MDcyOTVhNmEzMWQ0Nzg2YTFhN2MyMDBkNTVkZTIyODhhMDU1Yw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Yjc2MmEwMGEzNDEyZTdmNjMxMjY1YzMwMDdiNDE3OGYxNzYyZTM5Ng==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTI1YzZlNWYzYTg0NDk4MTJiODQ1MDVjZDljNzJkYmE0YmRmMDgxOWVhOTA0
|
10
|
+
YzQ0MmVjNjcxNjM5NTdmMzRiYzkxY2JhMjJkNjU0ZmJhZDI5MDhkMTIzYWQx
|
11
|
+
N2RkOTJiMTZjNDNiMzY0MzA0YTRhYWE2OGJlM2JjZDlhMDZiZTM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTZjZGM4YjhkMjlhOGE4ZWI2NDYwY2M4MTAxZTU0ZGQ3MTM4MDZmMWVmY2Rh
|
14
|
+
YzViODAzMmM3MWRmMjNmMDQ4ODMwMzZjMDI4MzkzNzAzNGM0MTY2OTkwOTMx
|
15
|
+
ZDM5NjQxMTdlNzg5MzhmNzQzMzNjNGI1N2U2ODE5ZjRiMWI4YWY=
|
data/.gitignore
CHANGED
data/lib/enklawa/api.rb
CHANGED
data/lib/enklawa/api/program.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
module Enklawa
|
2
2
|
module Api
|
3
3
|
class Program < Struct.new(:id, :name, :description, :author, :live, :category_id)
|
4
|
-
attr_accessor :episodes
|
4
|
+
attr_accessor :episodes, :base_url
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
self.episodes = []
|
8
8
|
end
|
9
9
|
|
10
10
|
def image
|
11
|
-
"
|
11
|
+
if base_url.match("enklawa")
|
12
|
+
File.join([base_url, "/images/programs/#{id}.jpg"])
|
13
|
+
else
|
14
|
+
File.join([base_url, "/images/programs/240/#{id}.jpg"])
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
18
|
def <<(episode)
|
@@ -16,7 +20,7 @@ module Enklawa
|
|
16
20
|
end
|
17
21
|
|
18
22
|
def feed_url
|
19
|
-
"
|
23
|
+
File.join([base_url, "/program#{self.id}.xml"])
|
20
24
|
end
|
21
25
|
|
22
26
|
def to_h
|
data/lib/enklawa/api/request.rb
CHANGED
@@ -4,12 +4,11 @@ require "yaml"
|
|
4
4
|
module Enklawa
|
5
5
|
module Api
|
6
6
|
class Request
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@cache = YAML::load_file(ENKLAWA_CACHE_FILE) if File.exists?(ENKLAWA_CACHE_FILE)
|
7
|
+
def initialize(url)
|
8
|
+
@info_xml_url = File.join([url, "info.xml"])
|
9
|
+
@main_page_url = url
|
10
|
+
@cache_key = url.gsub(/[^a-z]/i,"") + ".yml"
|
11
|
+
@cache = YAML::load_file(@cache_key) if File.exists?(@cache_key)
|
13
12
|
@cache ||= {
|
14
13
|
'images' => {},
|
15
14
|
'durations' => {}
|
@@ -18,44 +17,32 @@ module Enklawa
|
|
18
17
|
|
19
18
|
def get!
|
20
19
|
@response = Response.new
|
21
|
-
get_forum_feeds!
|
22
|
-
get_categories!
|
23
20
|
get_info!
|
24
21
|
get_programs!
|
25
22
|
get_episodes!
|
26
23
|
|
27
|
-
File.open(
|
24
|
+
File.open(@cache_key, 'w') {|f| f.write @cache.to_yaml }
|
28
25
|
|
29
26
|
@response
|
30
27
|
end
|
31
28
|
|
32
29
|
private
|
33
30
|
|
34
|
-
def get_categories!
|
35
|
-
doc = Nokogiri::HTML(open(MAIN_PAGE_URL))
|
36
|
-
|
37
|
-
doc.search("select#ProgramsSelector option").each do |option|
|
38
|
-
category = Category.new
|
39
|
-
category.name = option.text
|
40
|
-
category.id = option[:value].to_i
|
41
|
-
|
42
|
-
@response.add_category(category)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
31
|
def get_info!
|
47
|
-
@info_xml_doc = Nokogiri::XML(open(
|
32
|
+
@info_xml_doc = Nokogiri::XML(open(@info_xml_url).read)
|
48
33
|
|
49
34
|
@response.skype = @info_xml_doc.search("settings call skype").text
|
50
35
|
@response.phone = @info_xml_doc.search("settings call phone").text
|
51
36
|
|
52
|
-
shoutcast_pls_url =
|
37
|
+
shoutcast_pls_url = CGI.unescape(@info_xml_doc.search("settings listen shoutcast").text)
|
38
|
+
shoutcast_pls_url = "http:"+ shoutcast_pls_url unless shoutcast_pls_url.match("http")
|
53
39
|
@response.radio = open(shoutcast_pls_url).read.strip.split("\n")[-1].gsub("File1=","")
|
54
40
|
end
|
55
41
|
|
56
42
|
def get_programs!
|
57
43
|
@info_xml_doc.search("programs p").each do |program_node|
|
58
44
|
program = Program.new
|
45
|
+
program.base_url = @main_page_url
|
59
46
|
program.id = program_node[:id].to_i
|
60
47
|
program.name = program_node.search("name").text
|
61
48
|
program.description = program_node.search("description").text
|
@@ -78,25 +65,9 @@ module Enklawa
|
|
78
65
|
@response.programs.reject! { |program| program.episodes.empty? }
|
79
66
|
end
|
80
67
|
|
81
|
-
def get_forum_feeds!
|
82
|
-
feed = Feedjira::Feed.fetch_and_parse(FORUM_FEED_URL)
|
83
|
-
return if feed == 404
|
84
|
-
|
85
|
-
feed.entries.each do |entry|
|
86
|
-
thread = ForumThread.new
|
87
|
-
thread.id = entry.id
|
88
|
-
thread.title = entry.title
|
89
|
-
thread.link = entry.url
|
90
|
-
thread.content = entry.content
|
91
|
-
thread.pub_date = entry.published
|
92
|
-
thread.author = entry.author
|
93
|
-
@response.add_thread(thread)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
68
|
def check_if_image_exists_or_use_from_program(program, episode)
|
98
69
|
return @cache['images'][episode.id] if @cache['images'].key?(episode.id)
|
99
|
-
image = "
|
70
|
+
image = File.join([@main_page_url, "/images/episodes/#{episode.id}.jpg"])
|
100
71
|
|
101
72
|
uri = URI(image)
|
102
73
|
|
data/lib/enklawa/api/version.rb
CHANGED
data/lib/enklawa/cli.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enklawa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkadiusz Buras
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|