csdn-tire 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/examples/tire.rb CHANGED
@@ -79,3 +79,5 @@ p state
79
79
 
80
80
  more_state = Tire.state.info(true)
81
81
  p more_state
82
+
83
+ Tire::ClickLog.new('blog', 'csdn', 'java', '1').log
@@ -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
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Tire
3
- VERSION = "0.5.1"
3
+ VERSION = "0.6.0"
4
4
  end
data/lib/tire.rb CHANGED
@@ -17,7 +17,7 @@ require 'tire/http/client'
17
17
  require 'tire/search'
18
18
  require 'tire/count'
19
19
  require 'tire/state'
20
- require 'tire/results/pagination'
20
+ require 'tire/click_log'
21
21
  require 'tire/index'
22
22
  require 'tire/dsl'
23
23
 
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: 9
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 5
9
- - 1
10
- version: 0.5.1
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