elastirad 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +28 -3
- data/lib/elastirad/client.rb +28 -28
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9bd90ba9cbdee2c0331b5e08ff23ccdd98e6d50
|
4
|
+
data.tar.gz: a4c2ed447639e22bf299fe80f33b10276448b3ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10de492cfab17e226675a470a1c9517b5b16ee7e9dc94e375609b59ef4ad14519d33677a39a428e7c992b4c890e55955a97d03d35af55b67ef4368d339bd41e2
|
7
|
+
data.tar.gz: ba547d13f45ffff8603de449002ddd7fcb9ea0052a9b5b3567216536112252ebd21cfb6bd15e63280ea108372faed6f44e7efdcf876dc838ce63631990ad5770
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
---------
|
3
|
+
- **2014-03-15**: 0.0.2
|
4
|
+
- Fix bug in #rad_index
|
5
|
+
- Fix bug for YARD README.md formatting
|
6
|
+
- Add documentation of Elasticsearch::API mixin functionality
|
7
|
+
- Add CHANGELOG.md excerpt to README.md
|
8
|
+
|
3
9
|
- **2014-03-14**: 0.0.1
|
4
10
|
- Initial release
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Elastirad: A RAD Client for Elasticsearch
|
|
4
4
|
Synopsis
|
5
5
|
--------
|
6
6
|
|
7
|
-
Elastirad is a custom
|
7
|
+
Elastirad is a custom Rapid Application Development (RAD) client for
|
8
8
|
Elasticsearch's Elasticsearch::API that provides a simple interface for
|
9
9
|
making Elasticsearch requests based on Elasticsearch's online documentation.
|
10
10
|
|
@@ -12,12 +12,15 @@ The primary goal for Elastirad is to enable use of the Elasticsearch online
|
|
12
12
|
curl-based documentation alone without needing to understand the syntax for
|
13
13
|
the Ruby SDK.
|
14
14
|
|
15
|
+
Elastirad::Client embeds the Elasticsearch::API and thus supports
|
16
|
+
Elasticsearch::API methods.
|
17
|
+
|
15
18
|
Installing
|
16
19
|
----------
|
17
20
|
|
18
21
|
Download and install elastirad with the following:
|
19
22
|
|
20
|
-
|
23
|
+
gem install elastirad
|
21
24
|
|
22
25
|
#Examples
|
23
26
|
---------
|
@@ -77,6 +80,12 @@ Download and install elastirad with the following:
|
|
77
80
|
:body => article
|
78
81
|
})
|
79
82
|
|
83
|
+
# Supports Elasticsearch::API methods
|
84
|
+
|
85
|
+
p rad.cluster.health
|
86
|
+
# --> GET _cluster/health {}
|
87
|
+
# => "{"cluster_name":"elasticsearch" ... }"
|
88
|
+
|
80
89
|
#Documentation
|
81
90
|
--------------
|
82
91
|
|
@@ -85,10 +94,26 @@ This gem is 100% documented with YARD, an exceptional documentation library. To
|
|
85
94
|
$ gem install yard
|
86
95
|
$ yard server -g
|
87
96
|
|
97
|
+
#Change Log
|
98
|
+
-----------
|
99
|
+
|
100
|
+
- **2014-03-15**: 0.0.2
|
101
|
+
- Fix bug in #rad_index
|
102
|
+
- Fix bug for YARD README.md formatting
|
103
|
+
- Add documentation of Elasticsearch::API mixin functionality
|
104
|
+
- Add CHANGELOG.md excerpt to README.md
|
105
|
+
- **2014-03-14**: 0.0.1
|
106
|
+
- Initial release
|
107
|
+
- Custom Elasticsearch::API mixin client
|
108
|
+
|
88
109
|
#Links
|
89
110
|
------
|
90
111
|
|
91
|
-
|
112
|
+
Elasticseach Reference Guide
|
113
|
+
|
114
|
+
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index.html
|
115
|
+
|
116
|
+
Elasticsearch::API for Ruby
|
92
117
|
|
93
118
|
https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch-api
|
94
119
|
|
data/lib/elastirad/client.rb
CHANGED
@@ -16,38 +16,14 @@ module Elastirad
|
|
16
16
|
? dOptions[:port].to_i : 9200
|
17
17
|
@sIndex = dOptions.has_key?(:index) && dOptions[:index] \
|
18
18
|
? dOptions[:index].strip : nil
|
19
|
-
@sUrl =
|
19
|
+
@sUrl = makeUrl(@sProtocol,@sHostname,@iPort)
|
20
20
|
@oFaraday = Faraday::Connection.new url: @sUrl || 'http://localhost:9200'
|
21
21
|
@dVerbs = {:put=>1,:get=>1,:post=>1,:delete=>1}
|
22
22
|
end
|
23
23
|
|
24
|
-
def makeUrl(sProtocol='http',sHostname='localhost',iPort=9200)
|
25
|
-
if sHostname.nil?
|
26
|
-
sHostname = 'localhost'
|
27
|
-
elsif sHostname.is_a?(String)
|
28
|
-
sHostname.strip!
|
29
|
-
if sHostname.length < 1
|
30
|
-
sHostname = 'localhost'
|
31
|
-
end
|
32
|
-
else
|
33
|
-
raise ArgumentError, 'E_HOSTNAME_IS_NOT_A_STRING'
|
34
|
-
end
|
35
|
-
if iPort.nil?
|
36
|
-
iPort = 9200
|
37
|
-
elsif iPort.is_a?(String) && iPort =~ /^[0-9]+$/
|
38
|
-
iPort = iPort.to_i
|
39
|
-
elsif ! iPort.kind_of?(Integer)
|
40
|
-
raise ArgumentError, 'E_PORT_IS_NOT_AN_INTEGER'
|
41
|
-
end
|
42
|
-
sBaseUrl = "#{sProtocol}://#{sHostname}"
|
43
|
-
sBaseUrl.sub!(/\/+\s*$/,'')
|
44
|
-
sBaseUrl += ':' + iPort.to_s if iPort != 80
|
45
|
-
return sBaseUrl
|
46
|
-
end
|
47
|
-
|
48
24
|
def rad_index(dEsRes={})
|
49
25
|
dEsRes[:verb] = :put
|
50
|
-
return self.
|
26
|
+
return self.rad_request(dEsRes)
|
51
27
|
end
|
52
28
|
|
53
29
|
def rad_request(dEsReq={})
|
@@ -58,7 +34,7 @@ module Elastirad
|
|
58
34
|
getBodyFromEsReq(dEsReq)
|
59
35
|
|
60
36
|
dEsResBody = oEsRes.body \
|
61
|
-
? MultiJson.
|
37
|
+
? MultiJson.decode( oEsRes.body, :symbolize_keys => true ) : nil
|
62
38
|
end
|
63
39
|
|
64
40
|
def perform_request(method,path,params,body)
|
@@ -71,6 +47,30 @@ module Elastirad
|
|
71
47
|
|
72
48
|
private
|
73
49
|
|
50
|
+
def makeUrl(sProtocol='http',sHostname='localhost',iPort=9200)
|
51
|
+
if sHostname.nil?
|
52
|
+
sHostname = 'localhost'
|
53
|
+
elsif sHostname.is_a?(String)
|
54
|
+
sHostname.strip!
|
55
|
+
if sHostname.length < 1
|
56
|
+
sHostname = 'localhost'
|
57
|
+
end
|
58
|
+
else
|
59
|
+
raise ArgumentError, 'E_HOSTNAME_IS_NOT_A_STRING'
|
60
|
+
end
|
61
|
+
if iPort.nil?
|
62
|
+
iPort = 9200
|
63
|
+
elsif iPort.is_a?(String) && iPort =~ /^[0-9]+$/
|
64
|
+
iPort = iPort.to_i
|
65
|
+
elsif ! iPort.kind_of?(Integer)
|
66
|
+
raise ArgumentError, 'E_PORT_IS_NOT_AN_INTEGER'
|
67
|
+
end
|
68
|
+
sBaseUrl = "#{sProtocol}://#{sHostname}"
|
69
|
+
sBaseUrl.sub!(/\/+\s*$/,'')
|
70
|
+
sBaseUrl += ':' + iPort.to_s if iPort != 80
|
71
|
+
return sBaseUrl
|
72
|
+
end
|
73
|
+
|
74
74
|
def getVerbFromEsReq(dEsReq={})
|
75
75
|
sVerb = dEsReq.has_key?(:verb) ? dEsReq[:verb] : :get
|
76
76
|
yVerb = sVerb.downcase.to_sym
|
@@ -115,7 +115,7 @@ module Elastirad
|
|
115
115
|
jBody = nil
|
116
116
|
if dEsReq.has_key?(:body)
|
117
117
|
if dEsReq[:body].is_a?(Hash)
|
118
|
-
jBody = MultiJson.
|
118
|
+
jBody = MultiJson.encode(dEsReq[:body])
|
119
119
|
elsif dEsReq[:body].is_a?(String) && dEsReq[:body].length > 0
|
120
120
|
jBody = dEsReq[:body]
|
121
121
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastirad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Wang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elasticsearch
|
@@ -70,7 +70,7 @@ dependencies:
|
|
70
70
|
- - ">="
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: '0'
|
73
|
-
description: A
|
73
|
+
description: A RAD (Rapid Application Development) Elasticsearch client
|
74
74
|
email: john@johnwang.com
|
75
75
|
executables: []
|
76
76
|
extensions: []
|