cloud_search 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,8 +11,9 @@ module CloudSearch
11
11
  private
12
12
 
13
13
  def check_configuration_parameters
14
- raise MissingConfigurationError.new("domain_id") if CloudSearch.config.domain_id.nil?
15
- raise MissingConfigurationError.new("domain_name") if CloudSearch.config.domain_name.nil?
14
+ %w(domain_id domain_name).each do |config|
15
+ raise MissingConfigurationError.new(config) if CloudSearch.config[config].nil?
16
+ end
16
17
  end
17
18
  end
18
19
 
@@ -27,6 +28,10 @@ module CloudSearch
27
28
  attr_accessor :region
28
29
  attr_accessor :search_url
29
30
 
31
+ def [](config)
32
+ self.__send__(config)
33
+ end
34
+
30
35
  def api_version
31
36
  @api_version ||= "2011-02-01"
32
37
  end
@@ -36,7 +41,7 @@ module CloudSearch
36
41
  end
37
42
 
38
43
  def document_url
39
- @document_url ||= "http://doc-#{self.domain_name}-#{self.domain_id}.#{self.region}.cloudsearch.amazonaws.com/#{self.api_version}"
44
+ @document_url ||= "http://doc-#{base_path}"
40
45
  end
41
46
 
42
47
  def region
@@ -44,7 +49,13 @@ module CloudSearch
44
49
  end
45
50
 
46
51
  def search_url
47
- @search_url ||= "http://search-#{self.domain_name}-#{self.domain_id}.#{self.region}.cloudsearch.amazonaws.com/#{self.api_version}"
52
+ @search_url ||= "http://search-#{base_path}"
53
+ end
54
+
55
+ private
56
+
57
+ def base_path
58
+ "#{self.domain_name}-#{self.domain_id}.#{self.region}.cloudsearch.amazonaws.com/#{self.api_version}"
48
59
  end
49
60
  end
50
61
  end
@@ -7,7 +7,6 @@ module CloudSearch
7
7
 
8
8
  def initialize(attributes = {})
9
9
  attributes.each_pair { |key, value| self.__send__("#{key}=", value) }
10
- @errors = {}
11
10
  end
12
11
 
13
12
  def id=(_id)
@@ -1,6 +1,7 @@
1
1
  module CloudSearch
2
2
  class SearchResponse
3
- attr_reader :body
3
+ attr_writer :items_per_page
4
+ attr_reader :current_page, :total_pages, :body
4
5
  attr_accessor :http_code
5
6
 
6
7
  def results
@@ -25,20 +26,20 @@ module CloudSearch
25
26
  @items_per_page || 10
26
27
  end
27
28
 
28
- alias :page_size :items_per_page
29
- alias :limit_value :items_per_page
30
- alias :total_entries :hits
31
- alias :any? :found?
32
-
33
- attr_writer :items_per_page
34
- attr_reader :current_page
35
- attr_reader :total_pages
29
+ def has_pagination?
30
+ hits > items_per_page
31
+ end
36
32
 
37
33
  def offset
38
34
  return 0 unless found?
39
35
  (@current_page - 1) * items_per_page
40
36
  end
41
37
 
38
+ alias :page_size :items_per_page
39
+ alias :limit_value :items_per_page
40
+ alias :total_entries :hits
41
+ alias :any? :found?
42
+
42
43
  private
43
44
 
44
45
  def calculate_pages
@@ -11,8 +11,8 @@ module CloudSearch
11
11
 
12
12
  def search
13
13
  cloud_search_response = RestClient.get url
14
- @response.http_code = cloud_search_response.code
15
- @response.body = cloud_search_response.body
14
+ @response.http_code = cloud_search_response.code
15
+ @response.body = cloud_search_response.body
16
16
 
17
17
  @response
18
18
  end
@@ -1,3 +1,3 @@
1
1
  module CloudSearch
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -33,6 +33,23 @@ describe CloudSearch::SearchResponse do
33
33
  end
34
34
  end
35
35
 
36
+ describe "#has_pagination?" do
37
+ it "when hits is greater than items_per_page returns true" do
38
+ subject.items_per_page = 8
39
+ subject.has_pagination?.should == false
40
+ end
41
+
42
+ it "when hits is less than items_per_page returns false" do
43
+ subject.items_per_page = 6
44
+ subject.has_pagination?.should == true
45
+ end
46
+
47
+ it "when hits is equal to items_per_page returns false" do
48
+ subject.items_per_page = 7
49
+ subject.has_pagination?.should == false
50
+ end
51
+ end
52
+
36
53
  describe "#found?" do
37
54
  it "returns true when found documents" do
38
55
  subject.should be_found
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-22 00:00:00.000000000 Z
12
+ date: 2012-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry
@@ -175,15 +175,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
175
175
  - - ! '>='
176
176
  - !ruby/object:Gem::Version
177
177
  version: '0'
178
+ segments:
179
+ - 0
180
+ hash: -2319996128587745862
178
181
  required_rubygems_version: !ruby/object:Gem::Requirement
179
182
  none: false
180
183
  requirements:
181
184
  - - ! '>='
182
185
  - !ruby/object:Gem::Version
183
186
  version: '0'
187
+ segments:
188
+ - 0
189
+ hash: -2319996128587745862
184
190
  requirements: []
185
191
  rubyforge_project:
186
- rubygems_version: 1.8.23
192
+ rubygems_version: 1.8.24
187
193
  signing_key:
188
194
  specification_version: 3
189
195
  summary: A wraper to Amazon CloudSearch's API
@@ -204,4 +210,3 @@ test_files:
204
210
  - spec/fixtures/vcr_cassettes/search/request/paginated_second_page.yml
205
211
  - spec/spec_helper.rb
206
212
  - spec/support/vcr.rb
207
- has_rdoc: