esnek 0.2.5 → 0.2.6
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/README.rdoc +26 -40
- data/lib/esnek/version.rb +1 -1
- metadata +6 -6
data/README.rdoc
CHANGED
@@ -1,42 +1,35 @@
|
|
1
1
|
= Esnek
|
2
2
|
|
3
3
|
_Esnek_ provides a minimalistic Ruby interface for JSON APIs, such as ElasticSearch, Google APIs, Facebook Graph API..
|
4
|
-
|
5
|
-
Esnek is mainly developed for _ElasticSearch_ in mind. ElasticSearch (http://www.elasticsearch.org)
|
6
|
-
is a scalable, fast, distributed, highly-available, real time search RESTful search engine communicating
|
7
|
-
by JSON over HTTP, based on _Lucene_ (http://lucene.apache.org).
|
4
|
+
Esnek is initially developed for _ElasticSearch_ http://www.elasticsearch.org which is based on _Lucene_ http://lucene.apache.org .
|
8
5
|
|
9
6
|
== Installation:
|
10
7
|
|
11
|
-
gem install esnek
|
12
|
-
|
13
|
-
Esnek is under heavy development in april 2011, so use "gem update" frequently.
|
8
|
+
gem install esnek # In april-june 2011, under development so use "gem update" frequently.
|
14
9
|
|
15
|
-
For the installation of elasticsearch please follow the guides at http://www.elasticsearch.org
|
16
|
-
|
17
10
|
== Quick Start
|
18
11
|
|
19
12
|
=== ElasticSearch
|
20
13
|
|
21
|
-
To
|
14
|
+
To install ElasticSearch please follow the guides at http://www.elasticsearch.org.
|
15
|
+
To use esnek just instantiate Esnek with the base API URL.
|
22
16
|
require 'esnek'
|
23
17
|
es = Esnek.new('http://localhost:9200')
|
24
18
|
|
25
|
-
|
19
|
+
Assuming Elastic Search is running at port 9200 on your localhost, the following code gets the state of the cluster:
|
26
20
|
|
27
21
|
#curl -XGET 'http://localhost:9200/_cluster/state'
|
28
22
|
es._cluster.state.get
|
29
23
|
|
30
|
-
|
31
|
-
You may pass options as a hash parameter for each directory in your URL.
|
24
|
+
You may pass options as a hash parameter for each directory in your URL:
|
32
25
|
#curl -XGET http://localhost:9200/twitter/tweet/_search?q=user:kimchy
|
33
26
|
es.twitter.tweet._search(:q => 'good').get
|
34
27
|
|
35
|
-
For literals such as 1, use __1; esnek simply omits __ (2 underscores)
|
28
|
+
For literals such as 1, use __1; esnek simply omits __ (2 underscores):
|
36
29
|
#curl -XGET 'http://localhost:9200/twitter/tweet/1'
|
37
30
|
es.twitter.tweet.__1.get
|
38
31
|
|
39
|
-
In order to post a JSON data simply pass a block (do...end)
|
32
|
+
In order to post a JSON data simply pass a block (do...end) which returns a hash:
|
40
33
|
#curl -XPUT http://localhost:9200/twitter/tweet/2 -d '{
|
41
34
|
# "user": "kimchy", "post_date": "2009-11-15T14:12:12", "message": "You know, for Search"
|
42
35
|
# }'
|
@@ -63,25 +56,24 @@ Notice that since "http://www.wsirussia.ru" is an invalid ruby method name, we u
|
|
63
56
|
puts res.shares
|
64
57
|
|
65
58
|
== Advanced
|
66
|
-
With
|
67
|
-
for your
|
59
|
+
With Esnek you make a chained method call where each method is a directory in the URL
|
60
|
+
for your target JSON API. You finish by appending a method for the HTTP verb; get, post, put or delete.
|
68
61
|
|
69
62
|
=== General Usage
|
70
|
-
require 'esnek'
|
71
|
-
Choose any JSON over HTTP API and identify the base url
|
63
|
+
require 'esnek'
|
64
|
+
Choose any JSON over HTTP API and identify the base url:
|
72
65
|
|
73
66
|
gapi = Esnek.new('https://www.googleapis.com')
|
74
67
|
|
75
|
-
Form a chained method call
|
76
|
-
your method chain must end with get, post, put or delete.
|
68
|
+
Form a chained method call and make sure you end with get, post, put or delete.
|
77
69
|
|
78
70
|
gapi.language.translate.v2.get :q => "hello world", :source => :en, :target => :tr, :key => INSERT_YOUR_KEY
|
79
71
|
|
80
|
-
Any query string should be given as a hash to any method in the method
|
72
|
+
Any query string should be given as a hash parameter to any method in the method chain.
|
81
73
|
|
82
74
|
gapi.language.translate.v2(:key => INSERT_YOUR_KEY).get(:q => "hello world", :source => :en, :target => :tr)
|
83
75
|
|
84
|
-
If you face any portion of the URL which cannot be a valid Ruby method name use send(:'!1invalid_method')
|
76
|
+
If you face any portion of the URL which cannot be a valid Ruby method name, use send(:'!1invalid_method')
|
85
77
|
|
86
78
|
res = fb.send(:"http://www.wsirussia.ru").get
|
87
79
|
|
@@ -89,37 +81,31 @@ Alternatively you may prefix digits with double underscore __
|
|
89
81
|
|
90
82
|
es.twitter.tweet.__1.get
|
91
83
|
|
92
|
-
If you append a block and
|
84
|
+
If you append a block and the block returns a hash, the hash is converted into a JSON and posted as data.
|
93
85
|
|
94
86
|
es.twitter.tweet.__2.put do
|
95
87
|
{"user" => "alper", "post_date" => "2011-11-15T14:12:12", "message" => "For esnek"}
|
96
88
|
end
|
97
89
|
|
98
90
|
=== Return Values
|
99
|
-
Esnek
|
91
|
+
Esnek converts the returned JSON into an Ostruct object.
|
100
92
|
|
101
|
-
res.my_field
|
102
|
-
res.table[:my_field] #
|
103
|
-
|
104
|
-
Notice that Ostruct converts only the first level hash keys into object attributes.
|
105
|
-
The deeper hashes are intact and should be accessed as Hash.
|
93
|
+
res.my_field # access as if it is an object's attrribute
|
94
|
+
res.table[:my_field] # For field names such as "id", you may use the "table" attribute.
|
106
95
|
|
107
|
-
|
96
|
+
Notice that Ostruct converts only the first level hash keys into Ostruct object attributes.
|
97
|
+
Consult your specific API documentation on how the return value is structured.
|
108
98
|
|
109
99
|
=== Proxy
|
110
|
-
Esnek is based on
|
111
|
-
Esnek will use the proxy specified by RestClient.proxy:
|
100
|
+
Esnek is based on Restclient, so some of the settings of Restclient apply to Esnek too.
|
101
|
+
For example Esnek will use the proxy specified by RestClient.proxy:
|
112
102
|
|
113
|
-
RestClient.proxy = "http://proxy.example.com/"
|
114
|
-
or the proxy url is set in an environment variable
|
115
|
-
RestClient.proxy = ENV['http_proxy']
|
103
|
+
RestClient.proxy = "http://proxy.example.com/" # or =ENV['http_proxy']
|
116
104
|
|
117
105
|
=== Logging
|
118
106
|
|
119
|
-
To enable logging the calls made to the API, you may
|
120
|
-
|
121
|
-
* set RestClient.log with a ruby Logger
|
122
|
-
* or set an environment variable to avoid modifying the code (in this case you can use a file name, "stdout" or "stderr"):
|
107
|
+
To enable logging the calls made to the API, you may set RestClient.log with a ruby Logger or set an environment
|
108
|
+
variable to avoid modifying the code (in this case you can use a file name, "stdout" or "stderr"):
|
123
109
|
|
124
110
|
$ RESTCLIENT_LOG=stdout path/to/my/program
|
125
111
|
$ RESTCLIENT_LOG=stdout irb
|
data/lib/esnek/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ESNEK_VERSION='0.2.
|
1
|
+
ESNEK_VERSION='0.2.6'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: esnek
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 6
|
10
|
+
version: 0.2.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alper Akgun
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-11-06 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: json
|
@@ -23,7 +23,7 @@ dependencies:
|
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
hash: 1
|
29
29
|
segments:
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
|
-
- -
|
42
|
+
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
hash: 13
|
45
45
|
segments:
|