quintype 0.0.9 → 0.0.10

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2fe7f1432e9a9b878d4499bf11c023b96a5885fc
4
- data.tar.gz: be8a71b10d9bdb532e229c764dd1838bb58c0616
3
+ metadata.gz: '0287b1b423facb37184a57dba69a5d6d55ab51cf'
4
+ data.tar.gz: ecab515fafee3dd23ba15b0b24cc36acc8efbabd
5
5
  SHA512:
6
- metadata.gz: d0c7fdb57f4228b705661d27744c87baf994cc3baedff575a7dd7ac5edac288e566f5f5dd4487075f8ec7d6951e58f5ebb512281deb1e33a9d36870f31e921f8
7
- data.tar.gz: 580c17014147e45662b687e3b78afb121ff574445e7f334d3c03f833e2eeb3029094ba862f4741659bdb8044f5369e9c851f1462fc31f7da49108e9db615f7fe
6
+ metadata.gz: 17e34a6cd0641bef5cbb90ba1c8922400dcc1c0ecfed3d375daec1c050384e7c036bedd0e56610f9fcfdbb8943ad2018724c41ce42b21bde11b480e5ee53106e
7
+ data.tar.gz: be0da5cc89a320bc48cf11b2d72804a797c3370552ca289125da5bb5408f395f3dafa1dc23efb7b6da13907daf04eae04f12e175a97aabee02bf92d448f09be7
data/Gemfile.lock CHANGED
@@ -1,32 +1,32 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- quintype (0.0.8)
4
+ quintype (0.0.10)
5
5
  activesupport (~> 4.2)
6
6
  faraday (~> 0.9)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (4.2.7.1)
11
+ activesupport (4.2.10)
12
12
  i18n (~> 0.7)
13
- json (~> 1.7, >= 1.7.7)
14
13
  minitest (~> 5.1)
15
14
  thread_safe (~> 0.3, >= 0.3.4)
16
15
  tzinfo (~> 1.1)
17
16
  addressable (2.4.0)
18
17
  byebug (8.2.2)
19
18
  coderay (1.1.1)
19
+ concurrent-ruby (1.0.5)
20
20
  crack (0.4.3)
21
21
  safe_yaml (~> 1.0.0)
22
22
  diff-lcs (1.2.5)
23
- faraday (0.9.2)
23
+ faraday (0.13.1)
24
24
  multipart-post (>= 1.2, < 3)
25
25
  hashdiff (0.3.0)
26
- i18n (0.7.0)
27
- json (1.8.3)
26
+ i18n (0.9.0)
27
+ concurrent-ruby (~> 1.0)
28
28
  method_source (0.8.2)
29
- minitest (5.9.0)
29
+ minitest (5.10.3)
30
30
  multipart-post (2.0.0)
31
31
  pry (0.10.3)
32
32
  coderay (~> 1.1.0)
@@ -47,8 +47,8 @@ GEM
47
47
  rspec-support (3.4.1)
48
48
  safe_yaml (1.0.4)
49
49
  slop (3.6.0)
50
- thread_safe (0.3.5)
51
- tzinfo (1.2.2)
50
+ thread_safe (0.3.6)
51
+ tzinfo (1.2.4)
52
52
  thread_safe (~> 0.1)
53
53
  vcr (3.0.1)
54
54
  webmock (1.24.2)
@@ -68,4 +68,4 @@ DEPENDENCIES
68
68
  webmock
69
69
 
70
70
  BUNDLED WITH
71
- 1.11.2
71
+ 1.15.4
data/lib/quintype/api.rb CHANGED
@@ -12,6 +12,7 @@ class API
12
12
  def establish_connection(host, conn = Faraday.new(url: host))
13
13
  @@host = host
14
14
  @@api_base = host + '/api/'
15
+ @@bulk_cache = ActiveSupport::Cache::MemoryStore.new
15
16
  @@conn = conn
16
17
  end
17
18
 
@@ -23,6 +24,21 @@ class API
23
24
  _post("bulk", params)
24
25
  end
25
26
 
27
+ def bulk_cached(params)
28
+ location = @@bulk_cache.fetch(params) do |params|
29
+ response = @@conn.post(@@api_base + "bulk-request", params) do |request|
30
+ request.headers['Content-Type'] = 'application/json'
31
+ request.body = params.to_json
32
+ end
33
+ if response.status == 303 && response.headers["Location"]
34
+ response.headers["Location"]
35
+ else
36
+ raise "Did not recieve a location header, status #{response.status}"
37
+ end
38
+ end
39
+ _get(location.sub(/^\/api\//, ""))
40
+ end
41
+
26
42
  def config
27
43
  _get("config")
28
44
  end
@@ -41,13 +41,25 @@ class API
41
41
  end
42
42
  end
43
43
 
44
+ def prepare_bulk(params)
45
+ params.inject({}) do |hash, param|
46
+ hash[param.first] = param.last.merge(_type: param.last[:_type] || 'stories')
47
+ hash
48
+ end
49
+ end
50
+
44
51
  def find_in_bulk(params)
45
52
  if params.present?
46
- params = params.inject({}) do |hash, param|
47
- hash[param.first] = param.last.merge(_type: param.last[:_type] || 'stories')
48
- hash
49
- end
50
- response = API.bulk_post(requests: params)
53
+ response = API.bulk_post(requests: prepare_bulk(params))
54
+ response['results']
55
+ else
56
+ []
57
+ end
58
+ end
59
+
60
+ def find_in_bulk_cached(params)
61
+ if params.present?
62
+ response = API.bulk_cached(requests: prepare_bulk(params))
51
63
  response['results']
52
64
  else
53
65
  []
data/quintype.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'quintype'
3
- s.version = '0.0.9'
3
+ s.version = '0.0.10'
4
4
  s.date = '2016-02-19'
5
5
  s.summary = "quintype!"
6
6
  s.platform = Gem::Platform::RUBY
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quintype
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.2.2
98
+ rubygems_version: 2.6.11
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: quintype!