csdn-tire 0.5.1 → 0.6.0
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.
- data/examples/tire.rb +2 -0
- data/lib/tire/click_log.rb +29 -0
- data/lib/tire/version.rb +1 -1
- data/lib/tire.rb +1 -1
- metadata +5 -5
- data/lib/tire/results/pagination.rb +0 -55
data/examples/tire.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Tire
|
2
|
+
class ClickLog
|
3
|
+
include Utils
|
4
|
+
|
5
|
+
def initialize(indices, types, keyword, ids)
|
6
|
+
@indices = Array(indices)
|
7
|
+
@types = Array(types).map { |type| Utils.escape(type) }
|
8
|
+
|
9
|
+
@path = ['/', @indices.join(','), @types.join(','), '_log'].compact.join('/').squeeze('/')
|
10
|
+
@payload = MultiJson.encode({:keyword => keyword, :id => ids.split(',')})
|
11
|
+
end
|
12
|
+
|
13
|
+
def url
|
14
|
+
"#{Configuration.url}#@path"
|
15
|
+
end
|
16
|
+
|
17
|
+
def log
|
18
|
+
@response = Configuration.client.post(url, @payload)
|
19
|
+
if @response.success?
|
20
|
+
MultiJson.decode(@response.body)
|
21
|
+
else
|
22
|
+
[]
|
23
|
+
end
|
24
|
+
ensure
|
25
|
+
curl = %Q(curl -X POST #{url} -d '#{@payload}')
|
26
|
+
logged('CLICK_LOG', curl)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/tire/version.rb
CHANGED
data/lib/tire.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csdn-tire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 6
|
9
|
+
- 0
|
10
|
+
version: 0.6.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Hooopo
|
@@ -211,6 +211,7 @@ files:
|
|
211
211
|
- Rakefile
|
212
212
|
- examples/tire.rb
|
213
213
|
- lib/tire.rb
|
214
|
+
- lib/tire/click_log.rb
|
214
215
|
- lib/tire/configuration.rb
|
215
216
|
- lib/tire/count.rb
|
216
217
|
- lib/tire/dsl.rb
|
@@ -219,7 +220,6 @@ files:
|
|
219
220
|
- lib/tire/http/response.rb
|
220
221
|
- lib/tire/index.rb
|
221
222
|
- lib/tire/logger.rb
|
222
|
-
- lib/tire/results/pagination.rb
|
223
223
|
- lib/tire/rubyext/ruby_1_8.rb
|
224
224
|
- lib/tire/rubyext/to_json.rb
|
225
225
|
- lib/tire/search.rb
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
module Tire
|
3
|
-
module Results
|
4
|
-
|
5
|
-
# Adds support for WillPaginate and Kaminari
|
6
|
-
#
|
7
|
-
module Pagination
|
8
|
-
|
9
|
-
def total_entries
|
10
|
-
@total
|
11
|
-
end
|
12
|
-
|
13
|
-
def per_page
|
14
|
-
(@options[:per_page] || @options[:size] || 10 ).to_i
|
15
|
-
end
|
16
|
-
|
17
|
-
def total_pages
|
18
|
-
( @total.to_f / per_page ).ceil
|
19
|
-
end
|
20
|
-
|
21
|
-
def current_page
|
22
|
-
if @options[:page]
|
23
|
-
@options[:page].to_i
|
24
|
-
else
|
25
|
-
(per_page + @options[:from].to_i) / per_page
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def previous_page
|
30
|
-
current_page > 1 ? (current_page - 1) : nil
|
31
|
-
end
|
32
|
-
|
33
|
-
def next_page
|
34
|
-
current_page < total_pages ? (current_page + 1) : nil
|
35
|
-
end
|
36
|
-
|
37
|
-
def offset
|
38
|
-
per_page * (current_page - 1)
|
39
|
-
end
|
40
|
-
|
41
|
-
def out_of_bounds?
|
42
|
-
current_page > total_pages
|
43
|
-
end
|
44
|
-
|
45
|
-
# Kaminari support
|
46
|
-
#
|
47
|
-
alias :limit_value :per_page
|
48
|
-
alias :total_count :total_entries
|
49
|
-
alias :num_pages :total_pages
|
50
|
-
alias :offset_value :offset
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
end
|