funky 0.2.17 → 0.2.18

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: da54bfb41c5753645c1a7c563b097bea1e95485a
4
- data.tar.gz: 92fcb13e252a300a1d06b65bc776ae1b6edbd70e
3
+ metadata.gz: f79e490243da7655f0de7e622a6888db059af5a3
4
+ data.tar.gz: ac848b830fe8ddc6e1acb4dfe195157f366f25c4
5
5
  SHA512:
6
- metadata.gz: f966f16d954f34554c4adbe39edae84683d259e9d59ea66e8c891d0747c00b4b77f4837716cefc7e04f4e7eded27d9bb7a2051b87180a43d4407e54ddaed14a3
7
- data.tar.gz: 10e4b65adc153b6c884611ca281fe30e4a82bba35d3f9d8ceba9649549df8d813242e134b9db1f59203a2d8b190b175ecf8eab158eddfe2ad09c799b296c0081
6
+ metadata.gz: eb7519f9f86c6b71a9feb16824fb89030a5c06be77167c5b8c9ddb1ab7e6ad25ba2364c54d883f034728c76c9a8e3d8ba385cb7e0a234000826c75379ceb9751
7
+ data.tar.gz: 3f5d7a338a2b22631d088fff7b50d86bdcca35a4b7b810b6e8ed76c8f292daa76a813a634d6243211e03c79a784fdfe24c522692a7477f263defb3a4f55165da
@@ -6,6 +6,10 @@ For more information about changelogs, check
6
6
  [Keep a Changelog](http://keepachangelog.com) and
7
7
  [Vandamme](http://tech-angels.github.io/vandamme).
8
8
 
9
+ ## 0.2.18 - 2017/04/19
10
+
11
+ * [ENHANCEMENT] `Funky::Page#videos` now fetches more videos by time-based pagination.
12
+
9
13
  ## 0.2.17 - 2017/04/17
10
14
 
11
15
  * [FEATURE] Add `Funky::Page.find` class method to find a page by its page ID.
@@ -7,16 +7,34 @@ module Funky
7
7
  class API < Base
8
8
  def self.fetch(path_query, is_array: false)
9
9
  uri = URI "https://#{host}/v2.8/#{path_query}&limit=100&access_token=#{app_id}%7C#{app_secret}"
10
- is_array ? fetch_multiple_pages(uri) : json_for(uri)
10
+ is_array ? fetch_multiple_pages(uri).uniq : json_for(uri)
11
11
  end
12
12
 
13
13
  def self.fetch_multiple_pages(uri)
14
14
  json = json_for(uri)
15
- if json[:paging][:next]
16
- next_paging_uri = URI json[:paging][:next]
17
- json[:data] + fetch_multiple_pages(next_paging_uri)
15
+ if json[:data].empty?
16
+ @try_count ||= 0
17
+ if @previous_timestamp && @try_count < 1 && (Date.parse @previous_timestamp rescue nil)
18
+ timestamp = (Date.parse(@previous_timestamp) - 1).strftime('%F')
19
+ @try_count += 1
20
+ @previous_timestamp = timestamp
21
+ new_query = URI.decode_www_form(uri.query).to_h.merge('until' => timestamp)
22
+ uri.query = URI.encode_www_form(new_query)
23
+ json[:data] + fetch_multiple_pages(uri)
24
+ else
25
+ []
26
+ end
18
27
  else
19
- json[:data]
28
+ timestamp = if json[:data].count == 1
29
+ Date.parse(json[:data][-1][:created_time]).strftime('%F')
30
+ else
31
+ Time.parse(json[:data][-1][:created_time]).to_i
32
+ end
33
+ @try_count = 0
34
+ @previous_timestamp = timestamp
35
+ new_query = URI.decode_www_form(uri.query).to_h.merge('until' => timestamp)
36
+ uri.query = URI.encode_www_form(new_query)
37
+ json[:data] + fetch_multiple_pages(uri)
20
38
  end
21
39
  end
22
40
 
@@ -1,3 +1,3 @@
1
1
  module Funky
2
- VERSION = "0.2.17"
2
+ VERSION = "0.2.18"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: funky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.17
4
+ version: 0.2.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-17 00:00:00.000000000 Z
11
+ date: 2017-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler