searchbox-tire 0.0.1
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/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.markdown +43 -0
- data/Rakefile +1 -0
- data/lib/generators/searchbox_generator.rb +13 -0
- data/lib/generators/templates/searchbox.yml +12 -0
- data/lib/searchbox-tire.rb +26 -0
- data/lib/searchbox-tire/client.rb +63 -0
- data/lib/searchbox-tire/configuration.rb +10 -0
- data/lib/searchbox-tire/curb.rb +20 -0
- data/lib/searchbox-tire/environment.rb +14 -0
- data/lib/searchbox-tire/version.rb +5 -0
- data/searchbox-tire.gemspec +25 -0
- metadata +83 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
Searchbox-Tire
|
2
|
+
=========
|
3
|
+
|
4
|
+
Searchbox-Tire is Ruby client for searchbox based on <https://github.com/karmi/tire/> which is a Ruby client for [ElasticSearch](http://www.elasticsearch.org/).
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
Install gem via ruby gems
|
10
|
+
|
11
|
+
$ gem install searchbox-tire
|
12
|
+
|
13
|
+
or you can use bundler
|
14
|
+
|
15
|
+
gem 'searchbox-tire'
|
16
|
+
|
17
|
+
|
18
|
+
Generate config file
|
19
|
+
|
20
|
+
$ rails generate searchbox
|
21
|
+
|
22
|
+
This will generate file named searchbox.yml under config folder looks like this.
|
23
|
+
|
24
|
+
# Configuration file for searchbox.io
|
25
|
+
development:
|
26
|
+
account_name: dev_account
|
27
|
+
api_key: dev_key
|
28
|
+
|
29
|
+
test:
|
30
|
+
account_name: test_account
|
31
|
+
api_key: test_key
|
32
|
+
|
33
|
+
production:
|
34
|
+
account_name: <%= ENV['SEARCHBOX_ACCOUNT_NAME'] %>
|
35
|
+
api_key: <%= ENV['SEARCHBOX_API_KEY'] %>
|
36
|
+
|
37
|
+
|
38
|
+
Enter your account name and api key which can be generated from <http://searchbox.io/>.
|
39
|
+
|
40
|
+
Usage
|
41
|
+
-----
|
42
|
+
|
43
|
+
Tire project documentation details can be found at <http://karmi.github.com/tire/>
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class SearchboxGenerator < Rails::Generators::Base
|
2
|
+
|
3
|
+
desc "Creates a configuration file at config/searchbox.yml"
|
4
|
+
|
5
|
+
def self.source_root
|
6
|
+
File.expand_path("../templates", __FILE__)
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_config_file
|
10
|
+
template 'searchbox.yml', File.join('config', "searchbox.yml")
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Configuration file for searchbox.io
|
2
|
+
development:
|
3
|
+
account_name: dev_account
|
4
|
+
api_key: dev_key
|
5
|
+
|
6
|
+
test:
|
7
|
+
account_name: test_account
|
8
|
+
api_key: test_key
|
9
|
+
|
10
|
+
production:
|
11
|
+
account_name: <%%= ENV['SEARCHBOX_ACCOUNT_NAME'] %>
|
12
|
+
api_key: <%%= ENV['SEARCHBOX_API_KEY'] %>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "tire"
|
2
|
+
require "searchbox-tire/version"
|
3
|
+
require "searchbox-tire/environment"
|
4
|
+
|
5
|
+
module Searchbox
|
6
|
+
|
7
|
+
# header name of api key
|
8
|
+
SEARCHBOX_API_HEADER_NAME = "x-searchboxio-key"
|
9
|
+
|
10
|
+
begin
|
11
|
+
|
12
|
+
APP_CONFIG = Environment.load_yaml("config/searchbox.yml")
|
13
|
+
SEARCHBOX_URL = "http://api.searchbox.io/#{APP_CONFIG['account_name']}"
|
14
|
+
API_KEY = APP_CONFIG['api_key']
|
15
|
+
|
16
|
+
rescue Exception => e
|
17
|
+
SEARCHBOX_URL = ""
|
18
|
+
API_KEY = ""
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
#tire monkey patches
|
24
|
+
require "searchbox-tire/configuration"
|
25
|
+
require "searchbox-tire/client"
|
26
|
+
require "searchbox-tire/curb"
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Tire
|
2
|
+
|
3
|
+
module HTTP
|
4
|
+
|
5
|
+
module Client
|
6
|
+
|
7
|
+
class RestClient
|
8
|
+
ConnectionExceptions = [::RestClient::ServerBrokeConnection, ::RestClient::RequestTimeout]
|
9
|
+
|
10
|
+
def self.get(url, data=nil)
|
11
|
+
|
12
|
+
perform ::RestClient::Request.new(:method => :get, :url => url, :payload => data, :headers => {Searchbox::SEARCHBOX_API_HEADER_NAME => Searchbox::API_KEY}).execute
|
13
|
+
rescue *ConnectionExceptions
|
14
|
+
raise
|
15
|
+
rescue ::RestClient::Exception => e
|
16
|
+
Response.new e.http_body, e.http_code
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.post(url, data)
|
20
|
+
perform ::RestClient.post(url, data, Searchbox::SEARCHBOX_API_HEADER_NAME => Searchbox::API_KEY)
|
21
|
+
rescue *ConnectionExceptions
|
22
|
+
raise
|
23
|
+
rescue ::RestClient::Exception => e
|
24
|
+
Response.new e.http_body, e.http_code
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.put(url, data)
|
28
|
+
perform ::RestClient.put(url, data, Searchbox::SEARCHBOX_API_HEADER_NAME => Searchbox::API_KEY)
|
29
|
+
rescue *ConnectionExceptions
|
30
|
+
raise
|
31
|
+
rescue ::RestClient::Exception => e
|
32
|
+
Response.new e.http_body, e.http_code
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.delete(url)
|
36
|
+
perform ::RestClient.delete(url, Searchbox::SEARCHBOX_API_HEADER_NAME => Searchbox::API_KEY)
|
37
|
+
rescue *ConnectionExceptions
|
38
|
+
raise
|
39
|
+
rescue ::RestClient::Exception => e
|
40
|
+
Response.new e.http_body, e.http_code
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.head(url)
|
44
|
+
perform ::RestClient.head(url, Searchbox::SEARCHBOX_API_HEADER_NAME => Searchbox::API_KEY)
|
45
|
+
rescue *ConnectionExceptions
|
46
|
+
raise
|
47
|
+
rescue ::RestClient::Exception => e
|
48
|
+
Response.new e.http_body, e.http_code
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def self.perform(response)
|
54
|
+
Response.new response.body, response.code, response.headers
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'curb'
|
2
|
+
|
3
|
+
module Tire
|
4
|
+
|
5
|
+
module HTTP
|
6
|
+
|
7
|
+
module Client
|
8
|
+
|
9
|
+
class Curb
|
10
|
+
@client = ::Curl::Easy.new
|
11
|
+
@client.resolve_mode = :ipv4
|
12
|
+
@client.headers[Searchbox::SEARCHBOX_API_HEADER_NAME] = Searchbox::API_KEY
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Encapsulates logic for getting environment information.
|
2
|
+
module Environment
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def env_name
|
6
|
+
return Rails.env if defined?(Rails)
|
7
|
+
return Sinatra::Base.environment.to_s if defined?(Sinatra)
|
8
|
+
ENV["RACK_ENV"] || ENV["SEARCHBOX_ENV"] || raise(Errors::NoEnvironment.new)
|
9
|
+
end
|
10
|
+
|
11
|
+
def load_yaml(path)
|
12
|
+
YAML.load(ERB.new(File.new(path).read).result)[env_name]
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "searchbox-tire/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "searchbox-tire"
|
7
|
+
s.version = Searchbox::Tire::VERSION
|
8
|
+
s.authors = ["searchbox"]
|
9
|
+
s.email = ["admin@searchbox.io"]
|
10
|
+
s.homepage = "http://www.searchbox.io"
|
11
|
+
s.summary = %q{Configuration additions to ruby-tire gem}
|
12
|
+
s.description = %q{An elasticsearch ruby client based on ruby/tire gem with some additions for authorization flow of searchbox.io}
|
13
|
+
|
14
|
+
s.rubyforge_project = "searchbox-tire"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
s.add_dependency "tire"
|
24
|
+
s.add_dependency "curb"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: searchbox-tire
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- searchbox
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-02 00:00:00.000000000 +03:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: tire
|
17
|
+
requirement: &17610980 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *17610980
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: curb
|
28
|
+
requirement: &17610440 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *17610440
|
37
|
+
description: An elasticsearch ruby client based on ruby/tire gem with some additions
|
38
|
+
for authorization flow of searchbox.io
|
39
|
+
email:
|
40
|
+
- admin@searchbox.io
|
41
|
+
executables: []
|
42
|
+
extensions: []
|
43
|
+
extra_rdoc_files: []
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- Gemfile
|
47
|
+
- README.markdown
|
48
|
+
- Rakefile
|
49
|
+
- lib/generators/searchbox_generator.rb
|
50
|
+
- lib/generators/templates/searchbox.yml
|
51
|
+
- lib/searchbox-tire.rb
|
52
|
+
- lib/searchbox-tire/client.rb
|
53
|
+
- lib/searchbox-tire/configuration.rb
|
54
|
+
- lib/searchbox-tire/curb.rb
|
55
|
+
- lib/searchbox-tire/environment.rb
|
56
|
+
- lib/searchbox-tire/version.rb
|
57
|
+
- searchbox-tire.gemspec
|
58
|
+
has_rdoc: true
|
59
|
+
homepage: http://www.searchbox.io
|
60
|
+
licenses: []
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project: searchbox-tire
|
79
|
+
rubygems_version: 1.6.2
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Configuration additions to ruby-tire gem
|
83
|
+
test_files: []
|