zooniverse_social 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc43968cb6199ebf3112c1f6f91b329a081b4b0a
4
- data.tar.gz: 0033248f277444b3556c88c99f84222ec1d2d439
3
+ metadata.gz: e2170887303b63833125fc8442597b5b40310bf0
4
+ data.tar.gz: b9b132c059cc39f2e5801e9e1158ba1e3596237d
5
5
  SHA512:
6
- metadata.gz: 092f2528e5a8a89c5d7435f066b493249a43a1d5589812e37cc423fcd7d7743d910e40bdc19918f7785f53eb294754b4ea14d5491f20761f86db883be1efc04c
7
- data.tar.gz: e485d2f4b1f52f3d8096466b5f836e7e51515d71b86aa9f4e3f684389bf9c3eb07c9681caf89860482a7a3630df383fece6c1f43fa3d7f91a3f138e8923a1a03
6
+ metadata.gz: 550e4e0a5ae8e3dd2fc3a48509065ec0ec9578206134601c76eb6ac962c81e439ea8f9b2ec72831d3faba79ceff2b74d1a8c6be0feac7408b7280afa05f2bb35
7
+ data.tar.gz: 686211f3d27eb7215a817bbc112ba56a3e1fbc4b741a89eaf4ec845ca10c781f1c51f677e2a3e6608ac5616dd19d02677176191274ca91adab44765c2c94b1ec
@@ -3,6 +3,7 @@ require 'concurrent'
3
3
  require 'zooniverse_social/posts'
4
4
  require 'zooniverse_social/statuses'
5
5
  require 'zooniverse_social/tweets'
6
+ require 'zooniverse_social/task_observer'
6
7
 
7
8
  module ZooniverseSocial
8
9
  class Data
@@ -35,7 +36,8 @@ module ZooniverseSocial
35
36
  end
36
37
 
37
38
  def self.start
38
- Concurrent::TimerTask.new(execution_interval: 600, run_now: true){ update }.execute
39
+ task = Concurrent::TimerTask.new(execution_interval: 600, timeout_interval: 20, run_now: true){ update }.execute
40
+ TaskObserver.new task, method(:start)
39
41
  end
40
42
  end
41
43
  end
@@ -5,13 +5,20 @@ module ZooniverseSocial
5
5
  attr_reader :data
6
6
 
7
7
  def initialize
8
- @updater = Updater.new 'https://public-api.wordpress.com', '/rest/v1.1/sites/36711287/posts'
8
+ @blog_updater = Updater.new 'https://public-api.wordpress.com', '/rest/v1.1/sites/36711287/posts'
9
+ @daily_updater = Updater.new 'https://public-api.wordpress.com', '/rest/v1.1/sites/57182749/posts'
9
10
  update
10
11
  end
11
12
 
12
13
  def update
13
- response = @updater.update number: 3, fields: 'ID,URL,title,date'
14
- @data = response.fetch('posts', []).collect do |post|
14
+ blog_data = _update @blog_updater
15
+ daily_data = _update @daily_updater
16
+ @data = (blog_data + daily_data).sort{ |a, b| b[:created_at] <=> a[:created_at] }.take 3
17
+ end
18
+
19
+ def _update(updater)
20
+ response = updater.update number: 3, fields: 'ID,URL,title,date'
21
+ response.fetch('posts', []).collect do |post|
15
22
  {
16
23
  id: post['ID'],
17
24
  title: post['title'],
@@ -0,0 +1,16 @@
1
+ module ZooniverseSocial
2
+ class TaskObserver
3
+ def initialize(task, restart)
4
+ @task = task
5
+ @restart = restart
6
+ @task.add_observer self
7
+ end
8
+
9
+ def update(time, result, error)
10
+ if error.is_a?(Concurrent::TimeoutError)
11
+ @task.shutdown
12
+ @restart.call
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module ZooniverseSocial
2
- VERSION = '0.1.0'
2
+ VERSION = '1.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zooniverse_social
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Parrish
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-21 00:00:00.000000000 Z
11
+ date: 2016-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puma
@@ -214,6 +214,7 @@ files:
214
214
  - lib/zooniverse_social/posts.rb
215
215
  - lib/zooniverse_social/server.rb
216
216
  - lib/zooniverse_social/statuses.rb
217
+ - lib/zooniverse_social/task_observer.rb
217
218
  - lib/zooniverse_social/tweets.rb
218
219
  - lib/zooniverse_social/updater.rb
219
220
  - lib/zooniverse_social/version.rb