esnek 0.1.2 → 0.2.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.
data/CHANGES CHANGED
@@ -1,9 +1,17 @@
1
1
  = Esnek Change Log
2
2
 
3
3
  == Expected
4
+
5
+ == 0.2.x
6
+ * tests with elasticsearch API
4
7
  * Authentication mechanisms
8
+ * proxy
9
+
10
+ == 0.1.x
11
+ * first working version
12
+ * documentation
5
13
 
6
- == 0.0.1
14
+ == 0.0.x
7
15
  * the very initial release
8
16
 
9
17
 
data/README.rdoc CHANGED
@@ -10,26 +10,67 @@ highly-available, real time search RESTful search engine communicating by JSON o
10
10
 
11
11
  For the installation of elasticsearch please follow the guides at http://www.elasticsearch.org
12
12
 
13
- == Usage:
13
+ == Usage
14
14
 
15
+ === ElasticSearch
16
+
17
+ To use esnek just instantiate Esnek with the base API URL.
15
18
  require 'esnek'
16
- es = Esnek.new('http://localhost:9200',true)
17
-
19
+ es = Esnek.new('http://localhost:9200')
20
+
21
+ Make a chained method call where each method is a directory in the URL for the JSON API.Your method chain must end with get, post, put or delete.
22
+ For example assuming elastic search is running at port 9200 on your localhost, the following code gets the state of the cluster.
23
+
18
24
  #curl -XGET 'http://localhost:9200/_cluster/state'
19
25
  es._cluster.state.get
20
26
 
27
+
28
+ You may pass options as a hash parameter for each directory in your URL.
21
29
  #curl -XGET http://localhost:9200/twitter/tweet/_search?q=user:kimchy
22
30
  es.twitter.tweet._search(:q => 'good').get
23
-
31
+
32
+ For literals such as 1, use __1; esnek simply omits __ (2 underscores)
24
33
  #curl -XGET 'http://localhost:9200/twitter/tweet/1'
25
34
  es.twitter.tweet.__1.get
26
35
 
27
- #curl -XPUT http://localhost:9200/twitter/tweet/2 -d '{ "user": "kimchy", "post_date": "2009-11-15T14:12:12", "message": "You know, for Search"}'
36
+ In order to post a JSON data simply pass a block (do...end)
37
+ #curl -XPUT http://localhost:9200/twitter/tweet/2 -d '{
38
+ # "user": "kimchy", "post_date": "2009-11-15T14:12:12", "message": "You know, for Search"
39
+ # }'
28
40
  es.twitter.tweet.__2.put do
29
41
  {"user" => "alper", "post_date" => "2011-11-15T14:12:12", "message" => "For esnek"}
30
42
  end
31
-
43
+
44
+ === Google Translate API
45
+ require 'esnek'
46
+ gapi = Esnek.new('https://www.googleapis.com')
47
+ gapi.language.translate.v2.get :q => "hello world", :source => :en, :target => :tr, :key => INSERT_YOUR_KEY
48
+
49
+ === Google URL Shortener
50
+ require 'esnek'
51
+ gapi = Esnek.new('https://www.googleapis.com')
52
+ res = gapi.urlshortener.v1.url.post {{:longUrl => "http://www.sayarus.com/"}}
53
+ puts res.longUrl # Use res.table[:id] instead of res.id, because id method already exist for Object
54
+
55
+ == Proxy
56
+
57
+ Esnek will use the proxy specified by RestClient.proxy:
58
+
59
+ RestClient.proxy = "http://proxy.example.com/"
60
+ or the proxy url is set in an environment variable
61
+ RestClient.proxy = ENV['http_proxy']
62
+
63
+ == Logging
64
+
65
+ To enable logging you can
66
+
67
+ * set RestClient.log with a ruby Logger
68
+ * or set an environment variable to avoid modifying the code (in this case you can use a file name, "stdout" or "stderr"):
69
+
70
+ $ RESTCLIENT_LOG=stdout path/to/my/program
71
+ $ RESTCLIENT_LOG=stdout irb
72
+
73
+
32
74
  == Notes
33
75
 
34
76
  Esnek was initially developed using Redcar under Ubuntu Linux 10.10.
35
-
data/lib/esnek/base.rb CHANGED
@@ -6,9 +6,8 @@ require 'ostruct'
6
6
  # highly-available, real time search RESTful search engine communicating by JSON over HTTP, based on _Lucene_ (http://lucene.apache.org).
7
7
  class Esnek
8
8
  attr_accessor :chain, :url_root
9
- def initialize(url_root, debug=false)
9
+ def initialize(url_root)
10
10
  @url_root = url_root
11
- @debug = debug
12
11
  @chain = []
13
12
  end
14
13
 
@@ -20,18 +19,19 @@ class Esnek
20
19
  if block_given?
21
20
  data = block.call.to_json rescue nil
22
21
  end
23
- if @debug
24
- puts url
25
- puts data.inspect
26
- puts @chain.inspect
27
- end
28
22
  @chain = []
29
23
 
30
- resp = block_given? ? RestClient.send(method_sym, url, data, :params => params) :
24
+ resp = block_given? ? RestClient.send(method_sym, url, data,:params => params,:content_type => :json, :accept => :json) :
31
25
  RestClient.send(method_sym, url,:params => params)
32
26
 
33
27
  if resp.headers[:content_type].include?('application/json')
34
- OpenStruct.new JSON.parse resp
28
+ r = OpenStruct.new JSON.parse resp
29
+ class << r
30
+ def table
31
+ @table
32
+ end
33
+ end
34
+ r
35
35
  else
36
36
  resp
37
37
  end
data/lib/esnek/version.rb CHANGED
@@ -1 +1 @@
1
- ESNEK_VERSION='0.1.2'
1
+ ESNEK_VERSION='0.2.0'
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: 31
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
8
  - 2
10
- version: 0.1.2
9
+ - 0
10
+ version: 0.2.0
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-04-18 00:00:00 Z
18
+ date: 2011-04-19 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: json