eventify 1.5.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +0 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +0 -0
  5. data/Gemfile +14 -14
  6. data/Guardfile +0 -0
  7. data/LICENSE +0 -0
  8. data/README.md +2 -2
  9. data/Rakefile +0 -0
  10. data/eventify.gemspec +1 -2
  11. data/lib/eventify.rb +4 -4
  12. data/lib/eventify/configuration.rb +0 -0
  13. data/lib/eventify/database.rb +0 -0
  14. data/lib/eventify/mail.rb +0 -0
  15. data/lib/eventify/provider/apollo_kino.rb +21 -0
  16. data/lib/eventify/provider/base.rb +55 -55
  17. data/lib/eventify/provider/livenation.rb +21 -0
  18. data/lib/eventify/provider/piletilevi.rb +18 -5
  19. data/lib/eventify/version.rb +1 -1
  20. data/spec/eventify/configuration_spec.rb +51 -51
  21. data/spec/eventify/database_spec.rb +9 -9
  22. data/spec/eventify/mail_spec.rb +33 -33
  23. data/spec/eventify/provider/apollo_kino_spec.rb +25 -0
  24. data/spec/eventify/provider/base_spec.rb +145 -145
  25. data/spec/eventify/provider/livenation_spec.rb +25 -0
  26. data/spec/eventify/provider/piletilevi_spec.rb +16 -30
  27. data/spec/eventify_spec.rb +155 -155
  28. data/spec/spec_helper.rb +7 -0
  29. data/spec/support/apollo_kino.html +1021 -0
  30. data/spec/support/livenation.html +1444 -0
  31. data/spec/support/piletilevi-page1.json +1 -0
  32. data/spec/support/piletilevi-page2.json +1 -0
  33. metadata +19 -32
  34. data/lib/eventify/provider/fbi.rb +0 -17
  35. data/lib/eventify/provider/solaris_kino.rb +0 -30
  36. data/spec/eventify/provider/fbi_spec.rb +0 -25
  37. data/spec/eventify/provider/solaris_kino_spec.rb +0 -31
  38. data/spec/support/fbi.html +0 -802
  39. data/spec/support/piletilevi.json +0 -174
  40. data/spec/support/solaris_kino.html +0 -542
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0b04a77c626eb161c209936ab6d00d6094a06318
4
- data.tar.gz: f933a1e78f4216df4e5d1de6537d73e7bc383d62
2
+ SHA256:
3
+ metadata.gz: 87fc46638793a6f58c659b1f1d4410cc4fc15f323e829a7e62f97b169f22761b
4
+ data.tar.gz: 9076ebd85ff66f6b6a01efd54a30399c39e9c721325eaa2ec6187b7c4e11a73d
5
5
  SHA512:
6
- metadata.gz: 54eb1cd19a4ed5266d8aa4c43fec637f6a35f494d1875ee8723121088e3b9986369df675aa0f452053342ccc55659f110369e57d1e73a4a56b615dba6d6ba802
7
- data.tar.gz: e4c46c6419f92fc59999573f90d536403c9e79db7b7fd8797b3a1422533248f02ab4192800590d9dee4841c7b1e2ae9d5036d1d9f4f99c7d23268ceaabca656e
6
+ metadata.gz: fc41f7752a36c1c98466faaa31629e2736ea05825a9f7b8fa15a9aa54243a303d1d7d51aa92a4d1dad4ae67a778effe49bffd6d6a4b58a8420f823c48cd255b0
7
+ data.tar.gz: 0a08fc417a2950789bf9830667d9617453610ddd5257344d01659535a647e8f37d3b0eb1baf3c2f1df3d7062f86077da2ddb4f8bfea7f6acccdd9b6af183d752
data/.gitignore CHANGED
File without changes
@@ -1 +1 @@
1
- 2.3.1
1
+ 2.5.5
File without changes
data/Gemfile CHANGED
@@ -1,14 +1,14 @@
1
- source "https://rubygems.org"
2
-
3
- group :development do
4
- gem "guard"
5
- gem "guard-rspec"
6
- gem "guard-bundler"
7
- gem "wdm", platform: :mingw
8
- gem "win32console", platform: :mingw
9
- gem "ruby_gntp"
10
- end
11
-
12
- gemspec
13
-
14
- gem "coveralls", require: false
1
+ source "https://rubygems.org"
2
+
3
+ group :development do
4
+ gem "guard"
5
+ gem "guard-rspec"
6
+ gem "guard-bundler"
7
+ gem "wdm", platform: :mingw
8
+ gem "win32console", platform: :mingw
9
+ gem "ruby_gntp"
10
+ end
11
+
12
+ gemspec
13
+
14
+ gem "coveralls", require: false
data/Guardfile CHANGED
File without changes
data/LICENSE CHANGED
File without changes
data/README.md CHANGED
@@ -38,9 +38,9 @@ providers/organizers in an aggregate way.
38
38
 
39
39
  The following providers are currently supported:
40
40
 
41
- * [FBI](http://fbi.ee)
41
+ * [Livenation](https://livenation.ee)
42
42
  * [Piletilevi](http://www.piletilevi.ee/)
43
- * [Solaris Kino](http://solariskino.ee/)
43
+ * [Apollo Kino](https://www.apollokino.ee/)
44
44
 
45
45
  ## Adding New Providers
46
46
 
data/Rakefile CHANGED
File without changes
@@ -19,10 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "simple-rss"
22
- spec.add_dependency "nokogiri", "~> 1.7.1"
22
+ spec.add_dependency "nokogiri", "~> 1.11.0"
23
23
  spec.add_dependency "sqlite3"
24
24
  spec.add_dependency "mail", "~> 2.7.0.rc1"
25
- spec.add_dependency "faraday"
26
25
 
27
26
  spec.add_development_dependency "bundler", "~> 1.3"
28
27
  spec.add_development_dependency "rake"
@@ -1,9 +1,9 @@
1
1
  require File.expand_path("eventify/version", __dir__)
2
2
  require File.expand_path("eventify/configuration", __dir__)
3
3
  require File.expand_path("eventify/provider/base", __dir__)
4
- require File.expand_path("eventify/provider/fbi", __dir__)
4
+ require File.expand_path("eventify/provider/livenation", __dir__)
5
5
  require File.expand_path("eventify/provider/piletilevi", __dir__)
6
- require File.expand_path("eventify/provider/solaris_kino", __dir__)
6
+ require File.expand_path("eventify/provider/apollo_kino", __dir__)
7
7
  require File.expand_path("eventify/database", __dir__)
8
8
  require File.expand_path("eventify/mail", __dir__)
9
9
 
@@ -35,8 +35,8 @@ class Eventify
35
35
  def providers
36
36
  @providers ||= [
37
37
  Eventify::Provider::Piletilevi,
38
- Eventify::Provider::FBI,
39
- Eventify::Provider::SolarisKino
38
+ Eventify::Provider::Livenation,
39
+ Eventify::Provider::ApolloKino
40
40
  ]
41
41
  end
42
42
  end
File without changes
File without changes
File without changes
@@ -0,0 +1,21 @@
1
+ require "open-uri"
2
+ require "nokogiri"
3
+ require "time"
4
+
5
+ module Eventify::Provider
6
+ class ApolloKino < Base
7
+ URL = "https://www.apollokino.ee/"
8
+
9
+ class << self
10
+ def fetch
11
+ doc = Nokogiri::HTML(open(URI.join(URL, "eng/soon"), {"Accept-Encoding" => "gzip,deflate"}))
12
+ doc.search(".EventList-container > div").map do |item|
13
+ title_node = item.at("h2 a")
14
+ url = URI.join(URL, title_node["href"]).to_s
15
+ date = Time.strptime(item.at(".event-releaseDate b").content, "%d.%m.%Y")
16
+ new id: url, title: title_node.content, link: url, date: date
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,55 +1,55 @@
1
- class Eventify
2
- module Provider
3
- class Base
4
- include Comparable
5
-
6
- class << self
7
- def fetch
8
- raise NotImplementedError
9
- end
10
- end
11
-
12
- attr_reader :id, :title, :link, :date
13
-
14
- def initialize(event)
15
- @id = event[:id] or raise MissingAttributeError.new("id is missing")
16
- @title = event[:title] or raise MissingAttributeError.new("title is missing")
17
- @link = event[:link] or raise MissingAttributeError.new("link is missing")
18
- @date = event[:date]
19
- end
20
-
21
- def provider
22
- @provider ||= self.class.name
23
- end
24
-
25
- def save
26
- Database.save self
27
- self
28
- end
29
-
30
- def exists?
31
- Database.exists? self
32
- end
33
-
34
- def ==(other)
35
- id == other.id &&
36
- provider == other.provider &&
37
- title == other.title &&
38
- link == other.link &&
39
- date.to_i == other.date.to_i
40
- end
41
-
42
- alias_method :eql?, :==
43
-
44
- def hash
45
- "#{id}-#{provider}-#{title}-#{link}-#{date.to_i}".hash
46
- end
47
-
48
- def <=>(other)
49
- title <=> other.title
50
- end
51
-
52
- MissingAttributeError = Class.new(RuntimeError)
53
- end
54
- end
55
- end
1
+ class Eventify
2
+ module Provider
3
+ class Base
4
+ include Comparable
5
+
6
+ class << self
7
+ def fetch
8
+ raise NotImplementedError
9
+ end
10
+ end
11
+
12
+ attr_reader :id, :title, :link, :date
13
+
14
+ def initialize(event)
15
+ @id = event[:id] or raise MissingAttributeError.new("id is missing")
16
+ @title = event[:title] or raise MissingAttributeError.new("title is missing")
17
+ @link = event[:link] or raise MissingAttributeError.new("link is missing")
18
+ @date = event[:date]
19
+ end
20
+
21
+ def provider
22
+ @provider ||= self.class.name
23
+ end
24
+
25
+ def save
26
+ Database.save self
27
+ self
28
+ end
29
+
30
+ def exists?
31
+ Database.exists? self
32
+ end
33
+
34
+ def ==(other)
35
+ id == other.id &&
36
+ provider == other.provider &&
37
+ title == other.title &&
38
+ link == other.link &&
39
+ date.to_i == other.date.to_i
40
+ end
41
+
42
+ alias_method :eql?, :==
43
+
44
+ def hash
45
+ "#{id}-#{provider}-#{title}-#{link}-#{date.to_i}".hash
46
+ end
47
+
48
+ def <=>(other)
49
+ title <=> other.title
50
+ end
51
+
52
+ MissingAttributeError = Class.new(RuntimeError)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,21 @@
1
+ require "open-uri"
2
+ require "nokogiri"
3
+ require "json"
4
+ require "time"
5
+
6
+ module Eventify::Provider
7
+ class Livenation < Base
8
+ URL = "https://www.livenation.ee/event/allevents"
9
+
10
+ class << self
11
+ def fetch
12
+ doc = Nokogiri::HTML(open(URL))
13
+ doc.search("script[type='application/ld+json']").map do |raw_item|
14
+ item = JSON.parse(raw_item.content)
15
+ next unless item["name"]
16
+ new id: item["url"], title: item["name"], link: item["url"], date: Time.parse(item["startDate"])
17
+ end.compact
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,16 +1,29 @@
1
- require "faraday"
1
+ require "open-uri"
2
2
  require "json"
3
3
 
4
4
  module Eventify::Provider
5
5
  class Piletilevi < Base
6
- URL = URI.parse("http://www.piletilevi.ee/ajaxCaller/method:getConcertsList/start:0/limit:500/id:58103/type:any/")
6
+ URL = URI.parse("https://www.piletilevi.ee/ajaxCaller/method:getConcertsListInfo/id:1089/type:catalog_category/order:date,asc")
7
7
 
8
8
  class << self
9
9
  def fetch
10
- json = JSON.parse(Faraday.new(url: "#{URL.scheme}://#{URL.host}").get(URL.path).body, symbolize_names: true) rescue {}
11
- entries = json[:responseData] && json[:responseData][:event] || []
10
+ first_page_json = fetch_page(1)
11
+ list_info = first_page_json["responseData"]["listInfo"]
12
+ total_pages = list_info["total"] / list_info["pageSize"] + 1
13
+ result = events(first_page_json) + (2..total_pages).flat_map { |page_number| events(fetch_page(page_number)) }
14
+ result
15
+ end
16
+
17
+ private
18
+
19
+ def fetch_page(number)
20
+ JSON.parse(open("#{URL}/page:#{number}").read)
21
+ end
22
+
23
+ def events(json)
24
+ entries = json["responseData"]["event"]
12
25
  entries.map do |entry|
13
- new id: entry[:id], title: entry[:title], link: entry[:link], date: Time.at(entry[:startTime][:stamp])
26
+ new id: entry["id"], title: entry["title"], link: entry["link"], date: Time.at(entry["startTime"]["stamp"])
14
27
  end
15
28
  end
16
29
  end
@@ -1,3 +1,3 @@
1
1
  class Eventify
2
- VERSION = "1.5.1"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -1,51 +1,51 @@
1
- require "spec_helper"
2
-
3
- describe Eventify::Configuration do
4
- before do
5
- stub_const "Eventify::Configuration::PATH", File.join(Dir.tmpdir, "eventify-config.yml")
6
- File.delete Eventify::Configuration::PATH if File.exists? Eventify::Configuration::PATH
7
- end
8
-
9
- context "#initialize" do
10
- it "has default settings by default" do
11
- configuration = Eventify::Configuration.new
12
- configuration[:subscribers].should == ["user@example.org"]
13
- configuration[:mail].should == Mail.delivery_method.settings.merge(openssl_verify_mode: "none")
14
- end
15
-
16
- it "allows to override settings" do
17
- File.open(Eventify::Configuration::PATH, "w") { |f| f.write YAML.dump(foo: "baz") }
18
-
19
- configuration = Eventify::Configuration.new(foo: "bar")
20
- configuration[:foo].should == "bar"
21
- configuration[:subscribers].should == ["user@example.org"]
22
- end
23
-
24
- it "loads settings from file too" do
25
- File.open(Eventify::Configuration::PATH, "w") { |f| f.write YAML.dump(bar: "foo") }
26
-
27
- configuration = Eventify::Configuration.new(foo: "bar")
28
- configuration[:foo].should == "bar"
29
- configuration[:bar].should == "foo"
30
- configuration[:subscribers].should == ["user@example.org"]
31
- end
32
- end
33
-
34
- context "#save" do
35
- it "saves config as yaml" do
36
- Eventify::Configuration.new(foo: "bar").save
37
- YAML.load(File.read(Eventify::Configuration::PATH))[:foo].should == "bar"
38
- end
39
-
40
- it "saves subscribers as an array even if it is specified as a string" do
41
- Eventify::Configuration.new(subscribers: "foo@bar.com").save
42
- YAML.load(File.read(Eventify::Configuration::PATH))[:subscribers].should == ["foo@bar.com"]
43
- end
44
- end
45
-
46
- context "#[]" do
47
- it "retrieves configuration setting" do
48
- Eventify::Configuration.new(baz: "bar")[:baz].should == "bar"
49
- end
50
- end
51
- end
1
+ require "spec_helper"
2
+
3
+ describe Eventify::Configuration do
4
+ before do
5
+ stub_const "Eventify::Configuration::PATH", File.join(Dir.tmpdir, "eventify-config.yml")
6
+ File.delete Eventify::Configuration::PATH if File.exists? Eventify::Configuration::PATH
7
+ end
8
+
9
+ context "#initialize" do
10
+ it "has default settings by default" do
11
+ configuration = Eventify::Configuration.new
12
+ expect(configuration[:subscribers]).to eq(["user@example.org"])
13
+ expect(configuration[:mail]).to eq(Mail.delivery_method.settings.merge(openssl_verify_mode: "none"))
14
+ end
15
+
16
+ it "allows to override settings" do
17
+ File.open(Eventify::Configuration::PATH, "w") { |f| f.write YAML.dump(foo: "baz") }
18
+
19
+ configuration = Eventify::Configuration.new(foo: "bar")
20
+ expect(configuration[:foo]).to eq("bar")
21
+ expect(configuration[:subscribers]).to eq(["user@example.org"])
22
+ end
23
+
24
+ it "loads settings from file too" do
25
+ File.open(Eventify::Configuration::PATH, "w") { |f| f.write YAML.dump(bar: "foo") }
26
+
27
+ configuration = Eventify::Configuration.new(foo: "bar")
28
+ expect(configuration[:foo]).to eq("bar")
29
+ expect(configuration[:bar]).to eq("foo")
30
+ expect(configuration[:subscribers]).to eq(["user@example.org"])
31
+ end
32
+ end
33
+
34
+ context "#save" do
35
+ it "saves config as yaml" do
36
+ Eventify::Configuration.new(foo: "bar").save
37
+ expect(YAML.load(File.read(Eventify::Configuration::PATH))[:foo]).to eq("bar")
38
+ end
39
+
40
+ it "saves subscribers as an array even if it is specified as a string" do
41
+ Eventify::Configuration.new(subscribers: "foo@bar.com").save
42
+ expect(YAML.load(File.read(Eventify::Configuration::PATH))[:subscribers]).to eq(["foo@bar.com"])
43
+ end
44
+ end
45
+
46
+ context "#[]" do
47
+ it "retrieves configuration setting" do
48
+ expect(Eventify::Configuration.new(baz: "bar")[:baz]).to eq("bar")
49
+ end
50
+ end
51
+ end
@@ -19,8 +19,8 @@ describe Eventify::Database do
19
19
  )
20
20
  Eventify::Database.save event2
21
21
 
22
- Eventify::Database.events.size.should == 2
23
- Eventify::Database.events.should == [event1, event2]
22
+ expect(Eventify::Database.events.size).to eq(2)
23
+ expect(Eventify::Database.events).to eq([event1, event2])
24
24
  end
25
25
 
26
26
  it "raises an error when event already exists" do
@@ -34,7 +34,7 @@ describe Eventify::Database do
34
34
 
35
35
  expect {
36
36
  Eventify::Database.save event
37
- }.to raise_error
37
+ }.to raise_error(SQLite3::ConstraintException)
38
38
  end
39
39
  end
40
40
 
@@ -48,7 +48,7 @@ describe Eventify::Database do
48
48
  )
49
49
  Eventify::Database.save(event)
50
50
 
51
- Eventify::Database.should exist(event)
51
+ expect(Eventify::Database).to exist(event)
52
52
  end
53
53
 
54
54
  it "false when event does not exist" do
@@ -59,7 +59,7 @@ describe Eventify::Database do
59
59
  date: Time.parse("2013-12-27 12:30:11"),
60
60
  )
61
61
 
62
- Eventify::Database.should_not exist(event)
62
+ expect(Eventify::Database).not_to exist(event)
63
63
  end
64
64
 
65
65
  it "false when event id is different" do
@@ -78,7 +78,7 @@ describe Eventify::Database do
78
78
  date: Time.parse("2013-12-27 12:30:11"),
79
79
  )
80
80
 
81
- Eventify::Database.should_not exist(event2)
81
+ expect(Eventify::Database).not_to exist(event2)
82
82
  end
83
83
 
84
84
  it "false when event link is different" do
@@ -97,7 +97,7 @@ describe Eventify::Database do
97
97
  date: Time.parse("2013-12-27 12:30:11"),
98
98
  )
99
99
 
100
- Eventify::Database.should_not exist(event2)
100
+ expect(Eventify::Database).not_to exist(event2)
101
101
  end
102
102
 
103
103
  it "false when event provider is different" do
@@ -116,7 +116,7 @@ describe Eventify::Database do
116
116
  date: Time.parse("2013-12-27 12:30:11"),
117
117
  )
118
118
 
119
- Eventify::Database.should_not exist(event2)
119
+ expect(Eventify::Database).not_to exist(event2)
120
120
  end
121
121
  end
122
122
 
@@ -137,6 +137,6 @@ describe Eventify::Database do
137
137
  )
138
138
  Eventify::Database.save(event2)
139
139
 
140
- Eventify::Database.events.should == [event1, event2]
140
+ expect(Eventify::Database.events).to eq([event1, event2])
141
141
  end
142
142
  end