enklawa 0.0.2 → 0.0.3

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzVmOWRkYjE3MmJjZjgyY2IwOTU0NTk4MGZhMGJmMDE5ODlhOGU5Yw==
4
+ YWI0YzdjNGNhNmJkY2M0ZTA3ZjdhNDRhNGU0M2E4OWViNzYxOGZiZQ==
5
5
  data.tar.gz: !binary |-
6
- ZDEwMmI5NGNmMTkwOWM5NjJlZTFjOTE1MjI5MDA3NmI0NjhiODllZQ==
6
+ MmZkMjgyYTYyMzA4OGNjNWU3M2I4YjAyOGFkZjA4MGJmNjVmZDcwMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MGU5MDMxZTgyMDBlYmExYTQ4ZTcyMTQwYmY0NDJjMTM4YWYyM2NhMzY5N2Jj
10
- OGY4NGE1MTdhMDdkMzQ3YTY2YjkwYWZjNWI0NjBjMmY4YmQzMWJhZTM5OTk2
11
- NmI4YmEzYzY4YjVhNTJhNTY3YjNkZjhjNWQwOTQ3ZDY2MzY2Yjk=
9
+ NTNlODU4NDM2YzNkMTAzZDM2NjEzNzhkNWM0NWFiYzgzNGEyMDBiYWRjNTUz
10
+ OGZlMmExNzY4NDJlOWE5MzA3ZGZiNDQ5NDkxZGZjYzIxYmNjYWVmY2I0NWJi
11
+ N2UzNDAyNjFiZDBiZWJmYzgzZjhlMTE2NWIxNzk0NTVmMmZlMGI=
12
12
  data.tar.gz: !binary |-
13
- ODI0M2RjMDcyNzllNzIxNDVhMDFmYmE5NTZmM2ExNDJjZDAzOWU3ZmNhMzg1
14
- NzA3YmE0MjUwY2UyOGVjZjg3MzcyNzkzOWY3MGY5MzBmNGM2ODkyODEyZGI0
15
- OTMzZWZiYzViZWEyYzAyMTQ2OWRmYzQ4OTAyODRlZWUzOTg2ZWU=
13
+ ZjQwY2Y5MDUwYjI3ZDllM2Q5NTM4YTk1ZTI0NTFiZmIxNTg5YThkZmRhYjI1
14
+ N2YzMGZhMjk1NzIzYjBlYjBkN2IxYWI1ZjAwNmI3YjUzZDlmNmU5MWI0OWZj
15
+ MWI5MDE4YjAzMGIxMTRlM2I4ZTk5OTYyZTkzZGI2MWY2YTA3Yjc=
data/README.md CHANGED
@@ -18,6 +18,9 @@ Next you can use it to download all programs:
18
18
 
19
19
  <http://enklawa.macbury.ninja/>
20
20
 
21
+ ## More info
22
+ <http://macbury.ninja/2014/9/enklawa-api-gem>
23
+
21
24
  ## Contributing
22
25
 
23
26
  1. Fork it ( https://github.com/macbury/enklawa-api/fork )
data/lib/enklawa/api.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "enklawa/api/version"
2
2
  require "enklawa/api/response"
3
3
  require "enklawa/api/program"
4
+ require "enklawa/api/category"
4
5
  require "enklawa/api/episode"
5
6
  require "enklawa/api/request"
6
7
  require "open-uri"
@@ -0,0 +1,13 @@
1
+ module Enklawa
2
+ module Api
3
+ class Category < Struct.new(:id, :name)
4
+
5
+ def to_h
6
+ {
7
+ id: id,
8
+ name: name
9
+ }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,6 +1,6 @@
1
1
  module Enklawa
2
2
  module Api
3
- class Program < Struct.new(:id, :name, :description, :author, :live)
3
+ class Program < Struct.new(:id, :name, :description, :author, :live, :category_id)
4
4
  attr_accessor :episodes
5
5
 
6
6
  def initialize
@@ -28,6 +28,7 @@ module Enklawa
28
28
  live: live,
29
29
  image: image,
30
30
  feed_url: feed_url,
31
+ category_id: category_id,
31
32
  episodes: episodes.map(&:to_h)
32
33
  }
33
34
  end
@@ -4,14 +4,15 @@ require "sanitize"
4
4
  module Enklawa
5
5
  module Api
6
6
  class Request
7
- INFO_XML_URL = "http://www.enklawa.net/info.xml"
8
-
7
+ INFO_XML_URL = "http://www.enklawa.net/info.xml"
8
+ MAIN_PAGE_URL = "http://enklawa.net"
9
9
  def initialize
10
10
 
11
11
  end
12
12
 
13
13
  def get!
14
14
  @response = Response.new
15
+ get_categories!
15
16
  get_info!
16
17
  get_programs!
17
18
  get_episodes!
@@ -21,6 +22,18 @@ module Enklawa
21
22
 
22
23
  private
23
24
 
25
+ def get_categories!
26
+ doc = Nokogiri::HTML(open(MAIN_PAGE_URL))
27
+
28
+ doc.search("select#ProgramsSelector option").each do |option|
29
+ category = Category.new
30
+ category.name = option.text
31
+ category.id = option[:value].to_i
32
+
33
+ @response.add_category(category)
34
+ end
35
+ end
36
+
24
37
  def get_info!
25
38
  @info_xml_doc = Nokogiri::XML(open(INFO_XML_URL).read)
26
39
 
@@ -38,6 +51,7 @@ module Enklawa
38
51
  program.name = program_node.search("name").text
39
52
  program.description = program_node.search("description").text
40
53
  program.author = program_node.search("author").text
54
+ program.category_id = program_node.search("cat").text.to_i
41
55
  program.live = program_node.search("live").size > 0
42
56
  @response.programs << program
43
57
  end
@@ -4,7 +4,8 @@ module Enklawa
4
4
  attr_accessor :skype, :phone, :radio
5
5
 
6
6
  def initialize
7
- @programs = []
7
+ @programs = []
8
+ @categories = []
8
9
  end
9
10
 
10
11
  def programs
@@ -15,11 +16,17 @@ module Enklawa
15
16
  @programs << program
16
17
  end
17
18
 
19
+ def add_category(category)
20
+ @categories << category
21
+ end
22
+
18
23
  def to_h
19
24
  {
25
+ version: VERSION,
20
26
  skype: skype,
21
27
  phone: phone,
22
28
  radio: radio,
29
+ categories: @categories.map(&:to_h),
23
30
  programs: @programs.map(&:to_h)
24
31
  }
25
32
  end
@@ -1,5 +1,5 @@
1
1
  module Enklawa
2
2
  module Api
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
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.0.2
4
+ version: 0.0.3
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-09-08 00:00:00.000000000 Z
11
+ date: 2014-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -182,6 +182,7 @@ files:
182
182
  - bin/enklawa
183
183
  - enklawa-api.gemspec
184
184
  - lib/enklawa/api.rb
185
+ - lib/enklawa/api/category.rb
185
186
  - lib/enklawa/api/episode.rb
186
187
  - lib/enklawa/api/program.rb
187
188
  - lib/enklawa/api/request.rb