indextank 0.0.6 → 1.0.7

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/lib/indextank.rb CHANGED
@@ -5,7 +5,7 @@ directory = File.expand_path(File.dirname(__FILE__))
5
5
  require File.join(directory, 'indextank', 'client')
6
6
 
7
7
  module IndexTank
8
- VERSION = "0.0.6"
8
+ VERSION = "1.0.7"
9
9
 
10
10
  def self.setup_connection(url, &block)
11
11
  @conn = Faraday::Connection.new(:url => url) do |builder|
@@ -17,6 +17,7 @@ module IndexTank
17
17
  end
18
18
  @uri = URI.parse(url)
19
19
  @conn.basic_auth @uri.user,@uri.password
20
+ @conn.headers['User-Agent'] = "IndexTank-Ruby/#{VERSION}"
20
21
  @conn
21
22
  end
22
23
  end
@@ -7,7 +7,8 @@ module IndexTank
7
7
 
8
8
  def initialize(api_url)
9
9
  @uri = api_url
10
- @conn = IndexTank.setup_connection(api_url)
10
+ builder = Proc.new { |builder| builder.use ClientResponseMiddleware }
11
+ @conn = IndexTank.setup_connection(api_url, &builder)
11
12
  end
12
13
 
13
14
  def indexes(name = nil)
@@ -33,4 +34,26 @@ module IndexTank
33
34
  Index.new("#{@uri}/v1/indexes/#{name}")
34
35
  end
35
36
  end
37
+
38
+ class ClientResponseMiddleware < Faraday::Response::Middleware
39
+ def self.register_on_complete(env)
40
+ env[:response].on_complete do |finished_env|
41
+ case finished_env[:status]
42
+ when 200
43
+ nil # this is the expected return code
44
+ when 204
45
+ nil # this is the expected return code for empty responses
46
+ when 401
47
+ raise InvalidApiKey
48
+ else
49
+ raise UnexpectedHTTPException, finished_env[:body]
50
+ end
51
+ end
52
+ end
53
+
54
+ def initialize(app)
55
+ super
56
+ @parser = nil
57
+ end
58
+ end
36
59
  end
@@ -5,7 +5,9 @@ module IndexTank
5
5
  class Document
6
6
  attr_reader :docid
7
7
 
8
+ # :docid => a String or Symbol, that is no longer than 1024 bytes when UTF-8 encoded
8
9
  def initialize(document_url, docid)
10
+ raise InvalidArgument , "docid too long. max is 1024 bytes and got #{String(docid).bytesize}" unless String(docid).bytesize <= 1024
9
11
  @docid = docid
10
12
  builder = Proc.new { |builder| builder.use DocumentResponseMiddleware }
11
13
  @conn = IndexTank.setup_connection(document_url, &builder)
@@ -65,6 +67,10 @@ module IndexTank
65
67
  def self.register_on_complete(env)
66
68
  env[:response].on_complete do |finished_env|
67
69
  case finished_env[:status]
70
+ when 200
71
+ nil # this is the expected code
72
+ when 204
73
+ nil # this is another expected code, for empty responses
68
74
  when 401
69
75
  raise InvalidApiKey
70
76
  when 409
@@ -73,6 +79,8 @@ module IndexTank
73
79
  raise NonExistentIndex
74
80
  when 400
75
81
  raise InvalidArgument, finished_env[:body]
82
+ else
83
+ raise UnexpectedHTTPException, finished_env[:body]
76
84
  end
77
85
  end
78
86
  end
@@ -7,4 +7,5 @@ module IndexTank
7
7
  class InvalidQuery < StandardError; end
8
8
  class IndexInitializing < StandardError; end
9
9
  class InvalidArgument < StandardError; end
10
+ class UnexpectedHTTPException < StandardError; end
10
11
  end
@@ -155,6 +155,8 @@ module IndexTank
155
155
  end
156
156
  end
157
157
 
158
+ # creates a new document, identified by :docid
159
+ # :docid => a String or Symbol, with bytesize no longer than 1024 bytes
158
160
  def document(docid)
159
161
  Document.new("#{@uri}/docs", docid)
160
162
  end
metadata CHANGED
@@ -1,21 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indextank
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 25
5
+ prerelease:
5
6
  segments:
7
+ - 1
6
8
  - 0
7
- - 0
8
- - 6
9
- version: 0.0.6
9
+ - 7
10
+ version: 1.0.7
10
11
  platform: ruby
11
12
  authors:
12
13
  - Santiago Perez
13
14
  - Terence Lee
15
+ - Diego Buthay
14
16
  autorequire:
15
17
  bindir: bin
16
18
  cert_chain: []
17
19
 
18
- date: 2011-01-04 00:00:00 -03:00
20
+ date: 2011-01-07 00:00:00 -08:00
19
21
  default_executable:
20
22
  dependencies:
21
23
  - !ruby/object:Gem::Dependency
@@ -24,8 +26,9 @@ dependencies:
24
26
  requirement: &id001 !ruby/object:Gem::Requirement
25
27
  none: false
26
28
  requirements:
27
- - - "="
29
+ - - ">="
28
30
  - !ruby/object:Gem::Version
31
+ hash: 7
29
32
  segments:
30
33
  - 1
31
34
  - 4
@@ -41,6 +44,7 @@ dependencies:
41
44
  requirements:
42
45
  - - ">="
43
46
  - !ruby/object:Gem::Version
47
+ hash: 62196421
44
48
  segments:
45
49
  - 2
46
50
  - 0
@@ -58,6 +62,7 @@ dependencies:
58
62
  requirements:
59
63
  - - ">="
60
64
  - !ruby/object:Gem::Version
65
+ hash: 62196421
61
66
  segments:
62
67
  - 2
63
68
  - 0
@@ -73,8 +78,9 @@ dependencies:
73
78
  requirement: &id004 !ruby/object:Gem::Requirement
74
79
  none: false
75
80
  requirements:
76
- - - "="
81
+ - - ">="
77
82
  - !ruby/object:Gem::Version
83
+ hash: 33
78
84
  segments:
79
85
  - 0
80
86
  - 10
@@ -88,8 +94,9 @@ dependencies:
88
94
  requirement: &id005 !ruby/object:Gem::Requirement
89
95
  none: false
90
96
  requirements:
91
- - - "="
97
+ - - ">="
92
98
  - !ruby/object:Gem::Version
99
+ hash: 49
93
100
  segments:
94
101
  - 0
95
102
  - 8
@@ -105,6 +112,7 @@ dependencies:
105
112
  requirements:
106
113
  - - ">="
107
114
  - !ruby/object:Gem::Version
115
+ hash: 3
108
116
  segments:
109
117
  - 0
110
118
  version: "0"
@@ -116,8 +124,9 @@ dependencies:
116
124
  requirement: &id007 !ruby/object:Gem::Requirement
117
125
  none: false
118
126
  requirements:
119
- - - "="
127
+ - - ">="
120
128
  - !ruby/object:Gem::Version
129
+ hash: 17
121
130
  segments:
122
131
  - 0
123
132
  - 3
@@ -133,6 +142,7 @@ dependencies:
133
142
  requirements:
134
143
  - - ">="
135
144
  - !ruby/object:Gem::Version
145
+ hash: 3
136
146
  segments:
137
147
  - 0
138
148
  version: "0"
@@ -144,8 +154,9 @@ dependencies:
144
154
  requirement: &id009 !ruby/object:Gem::Requirement
145
155
  none: false
146
156
  requirements:
147
- - - "="
157
+ - - ">="
148
158
  - !ruby/object:Gem::Version
159
+ hash: 13
149
160
  segments:
150
161
  - 0
151
162
  - 7
@@ -159,8 +170,9 @@ dependencies:
159
170
  requirement: &id010 !ruby/object:Gem::Requirement
160
171
  none: false
161
172
  requirements:
162
- - - "="
173
+ - - ">="
163
174
  - !ruby/object:Gem::Version
175
+ hash: 11
164
176
  segments:
165
177
  - 1
166
178
  - 4
@@ -172,6 +184,7 @@ description: Ruby Client for the IndexTank API
172
184
  email:
173
185
  - santip@santip.com.ar
174
186
  - hone02@gmail.com
187
+ - dbuthay@gmail.com
175
188
  executables: []
176
189
 
177
190
  extensions: []
@@ -204,6 +217,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
204
217
  requirements:
205
218
  - - ">="
206
219
  - !ruby/object:Gem::Version
220
+ hash: 3
207
221
  segments:
208
222
  - 0
209
223
  version: "0"
@@ -212,13 +226,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
226
  requirements:
213
227
  - - ">="
214
228
  - !ruby/object:Gem::Version
229
+ hash: 3
215
230
  segments:
216
231
  - 0
217
232
  version: "0"
218
233
  requirements: []
219
234
 
220
235
  rubyforge_project: nowarning
221
- rubygems_version: 1.3.7
236
+ rubygems_version: 1.4.1
222
237
  signing_key:
223
238
  specification_version: 3
224
239
  summary: Ruby Client for the IndexTank API