algoliasearch 1.0.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.
@@ -0,0 +1,92 @@
1
+ require 'cgi'
2
+
3
+ module Algolia
4
+ # A module which encapsulates the specifics of Algolia's REST API.
5
+ module Protocol
6
+
7
+ # Basics
8
+
9
+ # The version of the REST API implemented by this module.
10
+ VERSION = 1
11
+
12
+ # HTTP Headers
13
+ # ----------------------------------------
14
+
15
+ # The HTTP header used for passing your application ID to the
16
+ # Algolia API.
17
+ HEADER_APP_ID = "X-Algolia-Application-Id"
18
+
19
+ # The HTTP header used for passing your API key to the
20
+ # Algolia API.
21
+ HEADER_API_KEY = "X-Algolia-API-Key"
22
+
23
+ # HTTP ERROR CODES
24
+ # ----------------------------------------
25
+
26
+ ERROR_TIMEOUT = 124
27
+ ERROR_UNAVAILABLE = 503
28
+
29
+ # URI Helpers
30
+ # ----------------------------------------
31
+
32
+ # Construct a uri to list available indexes
33
+ def Protocol.indexes_uri
34
+ "/#{VERSION}/indexes"
35
+ end
36
+
37
+ # Construct a uri referencing a given Algolia index
38
+ def Protocol.index_uri(index)
39
+ "/#{VERSION}/indexes/#{index}"
40
+ end
41
+
42
+ def Protocol.batch_uri(index)
43
+ "/#{VERSION}/indexes/#{index}/batch"
44
+ end
45
+
46
+ def Protocol.task_uri(index, task_id)
47
+ "#{index_uri(index)}/task/#{task_id}"
48
+ end
49
+
50
+ def Protocol.object_uri(index, object_id, params = {})
51
+ params = params.nil? || params.size == 0 ? "" : "?#{to_query(params)}"
52
+ "#{index_uri(index)}/#{object_id}#{params}"
53
+ end
54
+
55
+ def Protocol.search_uri(index, query, params = {})
56
+ params = params.nil? || params.size == 0 ? "" : "&#{to_query(params)}"
57
+ "#{index_uri(index)}?query=#{CGI.escape(query)}&#{params}"
58
+ end
59
+
60
+ def Protocol.partial_object_uri(index, object_id)
61
+ "#{index_uri(index)}/#{object_id}/partial"
62
+ end
63
+
64
+ def Protocol.settings_uri(index)
65
+ "#{index_uri(index)}/settings"
66
+ end
67
+
68
+ def Protocol.keys_uri
69
+ "/#{VERSION}/keys"
70
+ end
71
+
72
+ def Protocol.key_uri(key)
73
+ "/#{VERSION}/keys/#{key}"
74
+ end
75
+
76
+ def Protocol.index_key_uri(index, key)
77
+ "#{index_uri(index)}/keys/#{key}"
78
+ end
79
+
80
+ def Protocol.index_keys_uri(index)
81
+ "#{index_uri(index)}/keys"
82
+ end
83
+
84
+ private
85
+ def Protocol.to_query(params)
86
+ params.map do |k, v|
87
+ "#{CGI.escape(k)}=#{CGI.escape(v.to_s)}"
88
+ end.join('&')
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,18 @@
1
+ ## ----------------------------------------------------------------------
2
+ ##
3
+ ## Ruby client for algolia.com
4
+ ## A quick library for playing with algolia.com's REST API for object storage.
5
+ ## Thanks to Sylvain Utard for the initial version of the library (sylvain.utard@gmail.com)
6
+ ## ----------------------------------------------------------------------
7
+ require "rubygems"
8
+ require "bundler/setup"
9
+
10
+ require 'json'
11
+ require 'curb'
12
+ require 'date'
13
+ require 'cgi'
14
+
15
+ cwd = Pathname(__FILE__).dirname
16
+ $:.unshift(cwd.to_s) unless $:.include?(cwd.to_s) || $:.include?(cwd.expand_path.to_s)
17
+
18
+ require 'algolia/index'
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: algoliasearch
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Algolia
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2013-08-05 00:00:00 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: curb
16
+ prerelease: false
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - &id002
20
+ - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ type: :runtime
24
+ version_requirements: *id001
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ prerelease: false
28
+ requirement: &id003 !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - *id002
31
+ type: :development
32
+ version_requirements: *id003
33
+ - !ruby/object:Gem::Dependency
34
+ name: jeweler
35
+ prerelease: false
36
+ requirement: &id004 !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - *id002
39
+ type: :development
40
+ version_requirements: *id004
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ prerelease: false
44
+ requirement: &id005 !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - *id002
47
+ type: :development
48
+ version_requirements: *id005
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ prerelease: false
52
+ requirement: &id006 !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - *id002
55
+ type: :development
56
+ version_requirements: *id006
57
+ - !ruby/object:Gem::Dependency
58
+ name: shoulda-context
59
+ prerelease: false
60
+ requirement: &id007 !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - *id002
63
+ type: :development
64
+ version_requirements: *id007
65
+ - !ruby/object:Gem::Dependency
66
+ name: webmock
67
+ prerelease: false
68
+ requirement: &id008 !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - *id002
71
+ type: :development
72
+ version_requirements: *id008
73
+ - !ruby/object:Gem::Dependency
74
+ name: redgreen
75
+ prerelease: false
76
+ requirement: &id009 !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - *id002
79
+ type: :development
80
+ version_requirements: *id009
81
+ description: A simple Ruby client for the algolia.com REST API
82
+ email: contact@algolia.com
83
+ executables: []
84
+
85
+ extensions: []
86
+
87
+ extra_rdoc_files:
88
+ - LICENSE.txt
89
+ - README.md
90
+ files:
91
+ - contacts.json
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - VERSION
98
+ - algoliasearch.gemspec
99
+ - lib/algolia/client.rb
100
+ - lib/algolia/error.rb
101
+ - lib/algolia/index.rb
102
+ - lib/algolia/protocol.rb
103
+ - lib/algoliasearch.rb
104
+ homepage: http://github.com/algolia/algoliasearch-client-ruby
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+
109
+ post_install_message:
110
+ rdoc_options: []
111
+
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - *id002
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - *id002
120
+ requirements: []
121
+
122
+ rubyforge_project:
123
+ rubygems_version: 2.0.3
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: A simple Ruby client for the algolia.com REST API
127
+ test_files: []
128
+