esnek 0.2.5 → 0.5.3
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.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/AUTHORS +0 -2
- data/CHANGES +16 -2
- data/Gemfile +10 -0
- data/LICENSE +16 -10
- data/README.rdoc +41 -58
- data/Rakefile +4 -24
- data/esnek.gemspec +25 -0
- data/lib/esnek/base.rb +66 -28
- data/lib/esnek/version.rb +1 -1
- data/test/base.rb +35 -0
- metadata +84 -74
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 163d151965f161030894b911af494b237e4f8138ee4fc4e9fc0e09ed817b43a5
|
4
|
+
data.tar.gz: 76739af567ca730c5f8ce4a197adc125450167d0e03fa0140f12ed560e02ecf5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 16c006ebba3b69be5eddcc0aa63897313dc9d25e84578a413bd1ed17a292e8e2f9fc87ad2e058367cc2cd7249dda39c08be1a6c5c93d3e68e8f93e89b6192950
|
7
|
+
data.tar.gz: 83a24bd2f7a2b26687f1614bc37aa7cf609ca431a7bcf595c358cefec5f76ab7ed11892c9dfa506e1275b6162c6a648dba5aab8b75e0bcd2d8aa3f313e028ebb
|
data/.gitignore
ADDED
data/AUTHORS
CHANGED
data/CHANGES
CHANGED
@@ -2,6 +2,22 @@
|
|
2
2
|
|
3
3
|
== Expected
|
4
4
|
|
5
|
+
== 0.5.1
|
6
|
+
* Verify SSL 1 support
|
7
|
+
|
8
|
+
== 0.4.x
|
9
|
+
* MIT License adopted
|
10
|
+
|
11
|
+
== 0.4.x
|
12
|
+
* hash post data in the block are now converted into a form post data
|
13
|
+
* oauth support with an access token through restclient
|
14
|
+
* json_return option controls jsonifaction of return values
|
15
|
+
|
16
|
+
== 0.3.x
|
17
|
+
* bug fixed for content type inclusions
|
18
|
+
* custom headers are supported
|
19
|
+
* Non Json data payloads are now supported
|
20
|
+
|
5
21
|
== 0.2.x
|
6
22
|
* tests with elasticsearch API
|
7
23
|
* Authentication mechanisms
|
@@ -15,5 +31,3 @@
|
|
15
31
|
== 0.0.x
|
16
32
|
* the very initial release
|
17
33
|
|
18
|
-
|
19
|
-
|
data/Gemfile
ADDED
data/LICENSE
CHANGED
@@ -1,13 +1,19 @@
|
|
1
|
-
|
2
|
-
it under the terms of the GNU General Public License as published by
|
3
|
-
the Free Software Foundation, either version 3 of the License, or
|
4
|
-
(at your option) any later version.
|
1
|
+
Copyright (c) Alper Akgun
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
13
12
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -1,42 +1,47 @@
|
|
1
1
|
= Esnek
|
2
2
|
|
3
|
-
_Esnek_
|
3
|
+
_Esnek_ is a minimalistic client for any Web API in general and no API
|
4
|
+
in particular. Esnek has been used in production for a few years already.
|
5
|
+
ElasticSearch, Google APIs, Facebook Graph API, LinkedIn, Facebook,
|
6
|
+
Twitter OAuth login integrations.
|
4
7
|
|
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).
|
8
8
|
|
9
9
|
== Installation:
|
10
10
|
|
11
|
-
gem install esnek
|
11
|
+
gem install esnek
|
12
12
|
|
13
|
-
Esnek is under heavy development in april 2011, so use "gem update" frequently.
|
14
|
-
|
15
|
-
For the installation of elasticsearch please follow the guides at http://www.elasticsearch.org
|
16
|
-
|
17
13
|
== Quick Start
|
18
14
|
|
15
|
+
===
|
16
|
+
require 'esnek'
|
17
|
+
esnek = Esnek.new('https://jsonplaceholder.typicode.com/')
|
18
|
+
todo = esnek.todos.__1.get
|
19
|
+
puts todo.id
|
20
|
+
puts todo.inspect
|
21
|
+
|
22
|
+
=== Facebook Graph API
|
23
|
+
require 'esnek'
|
24
|
+
|
19
25
|
=== ElasticSearch
|
20
26
|
|
21
|
-
To use esnek just instantiate Esnek with the base API URL.
|
27
|
+
To use esnek just instantiate Esnek with the base API URL.
|
22
28
|
require 'esnek'
|
23
29
|
es = Esnek.new('http://localhost:9200')
|
24
30
|
|
25
|
-
|
31
|
+
Assuming Elastic Search is running at port 9200 on your localhost, the following code gets the state of the cluster:
|
26
32
|
|
27
33
|
#curl -XGET 'http://localhost:9200/_cluster/state'
|
28
34
|
es._cluster.state.get
|
29
35
|
|
30
|
-
|
31
|
-
You may pass options as a hash parameter for each directory in your URL.
|
36
|
+
You may pass options as a hash parameter for each directory in your URL:
|
32
37
|
#curl -XGET http://localhost:9200/twitter/tweet/_search?q=user:kimchy
|
33
38
|
es.twitter.tweet._search(:q => 'good').get
|
34
39
|
|
35
|
-
For literals such as 1, use __1; esnek simply omits __ (2 underscores)
|
40
|
+
For literals such as 1, use __1; esnek simply omits __ (2 underscores):
|
36
41
|
#curl -XGET 'http://localhost:9200/twitter/tweet/1'
|
37
42
|
es.twitter.tweet.__1.get
|
38
43
|
|
39
|
-
In order to post a JSON data simply pass a block (do...end)
|
44
|
+
In order to post a JSON data simply pass a block (do...end) which returns a hash:
|
40
45
|
#curl -XPUT http://localhost:9200/twitter/tweet/2 -d '{
|
41
46
|
# "user": "kimchy", "post_date": "2009-11-15T14:12:12", "message": "You know, for Search"
|
42
47
|
# }'
|
@@ -44,44 +49,26 @@ In order to post a JSON data simply pass a block (do...end)
|
|
44
49
|
{"user" => "alper", "post_date" => "2011-11-15T14:12:12", "message" => "For esnek"}
|
45
50
|
end
|
46
51
|
|
47
|
-
=== Google Translate API
|
48
|
-
require 'esnek'
|
49
|
-
gapi = Esnek.new('https://www.googleapis.com')
|
50
|
-
gapi.language.translate.v2.get :q => "hello world", :source => :en, :target => :tr, :key => INSERT_YOUR_KEY
|
51
|
-
|
52
|
-
=== Google URL Shortener
|
53
|
-
require 'esnek'
|
54
|
-
gapi = Esnek.new('https://www.googleapis.com')
|
55
|
-
res = gapi.urlshortener.v1.url.post {{:longUrl => "http://www.sayarus.com/"}}
|
56
|
-
puts res.longUrl # Use res.table[:id] instead of res.id, because id method already exist for Object
|
57
|
-
|
58
|
-
=== Facebook Graph API
|
59
|
-
require 'esnek'
|
60
|
-
fb = Esnek.new('http://graph.facebook.com')
|
61
|
-
res = fb.send(:"http://www.wsirussia.ru").get
|
62
|
-
Notice that since "http://www.wsirussia.ru" is an invalid ruby method name, we use "send" to call it
|
63
|
-
puts res.shares
|
64
52
|
|
65
53
|
== Advanced
|
66
|
-
With
|
67
|
-
for your
|
54
|
+
With Esnek you make a chained method call where each method is a directory in the URL
|
55
|
+
for your target JSON API. You finish by appending a method for the HTTP verb; get, post, put or delete.
|
68
56
|
|
69
57
|
=== General Usage
|
70
|
-
require 'esnek'
|
71
|
-
Choose any JSON over HTTP API and identify the base url
|
58
|
+
require 'esnek'
|
59
|
+
Choose any JSON over HTTP API and identify the base url:
|
72
60
|
|
73
61
|
gapi = Esnek.new('https://www.googleapis.com')
|
74
62
|
|
75
|
-
Form a chained method call
|
76
|
-
your method chain must end with get, post, put or delete.
|
63
|
+
Form a chained method call and make sure you end with get, post, put or delete.
|
77
64
|
|
78
65
|
gapi.language.translate.v2.get :q => "hello world", :source => :en, :target => :tr, :key => INSERT_YOUR_KEY
|
79
66
|
|
80
|
-
Any query string should be given as a hash to any method in the method
|
67
|
+
Any query string should be given as a hash parameter to any method in the method chain.
|
81
68
|
|
82
69
|
gapi.language.translate.v2(:key => INSERT_YOUR_KEY).get(:q => "hello world", :source => :en, :target => :tr)
|
83
70
|
|
84
|
-
If you face any portion of the URL which cannot be a valid Ruby method name use send(:'!1invalid_method')
|
71
|
+
If you face any portion of the URL which cannot be a valid Ruby method name, use send(:'!1invalid_method')
|
85
72
|
|
86
73
|
res = fb.send(:"http://www.wsirussia.ru").get
|
87
74
|
|
@@ -89,37 +76,32 @@ Alternatively you may prefix digits with double underscore __
|
|
89
76
|
|
90
77
|
es.twitter.tweet.__1.get
|
91
78
|
|
92
|
-
If you append a block and
|
79
|
+
If you append a block and the block returns a hash, the hash is converted into a JSON and posted as data.
|
93
80
|
|
94
81
|
es.twitter.tweet.__2.put do
|
95
82
|
{"user" => "alper", "post_date" => "2011-11-15T14:12:12", "message" => "For esnek"}
|
96
83
|
end
|
97
84
|
|
98
85
|
=== Return Values
|
99
|
-
Esnek
|
86
|
+
Esnek converts the returned JSON into an Ostruct object. You may use
|
87
|
+
the returned object's inspect method to see how it works for a given API.
|
100
88
|
|
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.
|
89
|
+
res.my_field # access as if it is an object's attrribute
|
90
|
+
res.table[:my_field] # For field names such as "id", you may use the "table" attribute.
|
106
91
|
|
107
|
-
|
92
|
+
Notice that Ostruct converts only the first level hash keys into Ostruct object attributes.
|
93
|
+
Consult your specific API documentation on how the return value is structured.
|
108
94
|
|
109
95
|
=== Proxy
|
110
|
-
Esnek is based on
|
111
|
-
Esnek will use the proxy specified by RestClient.proxy:
|
96
|
+
Esnek is based on Restclient, so some of the settings of Restclient apply to Esnek too.
|
97
|
+
For example Esnek will use the proxy specified by RestClient.proxy:
|
112
98
|
|
113
|
-
RestClient.proxy = "http://proxy.example.com/"
|
114
|
-
or the proxy url is set in an environment variable
|
115
|
-
RestClient.proxy = ENV['http_proxy']
|
99
|
+
RestClient.proxy = "http://proxy.example.com/" # or =ENV['http_proxy']
|
116
100
|
|
117
101
|
=== Logging
|
118
102
|
|
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"):
|
103
|
+
To enable logging the calls made to the API, you may set RestClient.log with a ruby Logger or set an environment
|
104
|
+
variable to avoid modifying the code (in this case you can use a file name, "stdout" or "stderr"):
|
123
105
|
|
124
106
|
$ RESTCLIENT_LOG=stdout path/to/my/program
|
125
107
|
$ RESTCLIENT_LOG=stdout irb
|
@@ -127,4 +109,5 @@ To enable logging the calls made to the API, you may
|
|
127
109
|
|
128
110
|
== Notes
|
129
111
|
|
130
|
-
Esnek was initially developed using
|
112
|
+
Esnek was initially developed using Emacs under Ubuntu Linux.
|
113
|
+
|
data/Rakefile
CHANGED
@@ -1,28 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require '
|
4
|
-
require 'rake/gempackagetask'
|
5
|
-
require 'rake/rdoctask'
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'esnek/version'
|
6
4
|
require 'rake/testtask'
|
7
|
-
require
|
8
|
-
|
9
|
-
|
10
|
-
spec = eval(File.read('esnek.gemspec'))
|
11
|
-
|
12
|
-
Rake::GemPackageTask.new(spec) do |p|
|
13
|
-
p.gem_spec = spec
|
14
|
-
p.need_tar = false
|
15
|
-
p.need_zip = false
|
16
|
-
end
|
17
|
-
|
18
|
-
Rake::RDocTask.new do |rdoc|
|
19
|
-
files =['README.rdoc', 'LICENSE','CHANGES', 'AUTHORS', 'lib/**/*.rb', 'test/**/*.rb']
|
20
|
-
rdoc.rdoc_files.add(files)
|
21
|
-
rdoc.main = "README"
|
22
|
-
rdoc.title = "Esnek Documentation"
|
23
|
-
rdoc.rdoc_dir = 'doc/rdoc'
|
24
|
-
rdoc.options
|
25
|
-
end
|
5
|
+
require "bundler/gem_tasks"
|
26
6
|
|
27
7
|
Rake::TestTask.new do |t|
|
28
8
|
t.test_files = FileList['test/**/*.rb']
|
data/esnek.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'esnek/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'esnek'
|
8
|
+
s.version = ESNEK_VERSION
|
9
|
+
s.extra_rdoc_files = ['README.rdoc', 'LICENSE','CHANGES','AUTHORS']
|
10
|
+
s.summary = 'Esnek provides a minimalistic Ruby interface for JSON APIs, such as ElasticSearch'
|
11
|
+
s.description = s.summary
|
12
|
+
s.authors = ['Alper Akgun']
|
13
|
+
s.email = 'esnek@sayarus.com'
|
14
|
+
s.homepage = "https://github.com/sayarus/esnek"
|
15
|
+
s.license = "MIT"
|
16
|
+
s.files = `git ls-files -z`.split("\x0")
|
17
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.bindir = "bin"
|
21
|
+
s.add_dependency("json", ">= 1.4")
|
22
|
+
s.add_dependency("rest-client", ">= 1.6.1")
|
23
|
+
s.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
s.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
data/lib/esnek/base.rb
CHANGED
@@ -1,57 +1,95 @@
|
|
1
1
|
require 'rest_client'
|
2
2
|
require 'json'
|
3
|
-
require 'ostruct'
|
4
3
|
|
5
|
-
# _Esnek_ provides a quick Ruby interface for JSON APIs, such as _ElasticSearch_ (http://www.elasticsearch.org); a scalable, fast, distributed,
|
6
|
-
# highly-available, real time search RESTful search engine communicating by JSON over HTTP, based on _Lucene_ (http://lucene.apache.org).
|
4
|
+
# _Esnek_ provides a quick Ruby interface for JSON APIs, such as _ElasticSearch_ (http://www.elasticsearch.org); a scalable, fast, distributed,
|
5
|
+
# highly-available, real time search RESTful search engine communicating by JSON over HTTP, based on _Lucene_ (http://lucene.apache.org).
|
7
6
|
class Esnek
|
8
|
-
attr_accessor :
|
9
|
-
def initialize(
|
10
|
-
@
|
11
|
-
@
|
7
|
+
#attr_accessor :esnek_chain, :esnek_url_root, :esnek_params, :esnek_url
|
8
|
+
def initialize(esnek_url_root, options={:verify_ssl=>true, :json_api=>true,:json_return=>true, :header=>{}})
|
9
|
+
@esnek_url_root = esnek_url_root
|
10
|
+
@esnek_chain = []
|
11
|
+
@json_api = options[:json_api].nil? ? true : options[:json_api]
|
12
|
+
@json_return = options[:json_return].nil? ? @json_api : options[:json_return]
|
13
|
+
@verify_ssl = options[:verify_ssl]
|
14
|
+
@header= options[:header] || {}
|
15
|
+
if options[:oauth] # Esnek assumes that oauth ruby gem is installed
|
16
|
+
options[:oauth][:scheme] ||= :header
|
17
|
+
consumer = OAuth::Consumer.new(options[:oauth][:consumer_key],options[:oauth][:consumer_secret], {:site => options[:oauth][:site], :scheme => options[:oauth][:scheme]})
|
18
|
+
@access_token = OAuth::AccessToken.from_hash(consumer, {:oauth_token => options[:oauth][:oauth_token], :oauth_token_secret => options[:oauth][:oauth_token_secret]} )
|
19
|
+
else
|
20
|
+
@access_token = nil
|
21
|
+
end
|
12
22
|
end
|
13
23
|
|
14
24
|
def parse_json(resp)
|
15
25
|
j = JSON.parse resp
|
16
26
|
case
|
17
27
|
when j.is_a?(Hash)
|
18
|
-
r=OpenStruct.new(j)
|
19
|
-
class
|
28
|
+
r = OpenStruct.new(j)
|
29
|
+
class<<r;def table;@table;end;end;
|
20
30
|
r
|
21
31
|
when j.is_a?(Array)
|
22
|
-
j.map
|
32
|
+
j.map do |e|
|
33
|
+
r = if e.is_a?(Hash)
|
34
|
+
rr = OpenStruct.new(e)
|
35
|
+
class<<rr;def table;@table;end;end;
|
36
|
+
rr
|
37
|
+
else
|
38
|
+
e
|
39
|
+
end
|
40
|
+
r
|
41
|
+
end
|
23
42
|
else
|
24
43
|
j
|
25
44
|
end
|
26
45
|
end
|
27
46
|
def method_missing(method_sym, *args, &block)
|
28
|
-
if [:get, :put, :post, :delete].include?(method_sym)
|
29
|
-
@
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
47
|
+
if [:get, :put, :post, :delete, :patch, :head].include?(method_sym)
|
48
|
+
@esnek_chain << {:method => nil, :arg => (args.empty? ? {} : args[0]) }
|
49
|
+
@esnek_url = @esnek_url_root.gsub(/\/$/,'') + '/' + @esnek_chain.map{|e| e[:method]}.compact.join('/')
|
50
|
+
@esnek_params = @esnek_chain.inject({}){|s,e| s.merge!(e[:arg] || {}) if e[:arg].is_a?(Hash)}
|
51
|
+
@esnek_chain = []
|
52
|
+
heades = {:params => @esnek_params}.merge(@header)
|
53
|
+
data = block_given? ? block.call : nil #rescue nil
|
54
|
+
|
55
|
+
# if a JSON api is set in initializer both the payload data and the result will be un/jsonized
|
56
|
+
if @json_api
|
57
|
+
heades.merge!({:content_type => :json, :accept => :json})
|
58
|
+
data = data.to_json if data #rescue nil
|
59
|
+
elsif data.is_a? Hash
|
60
|
+
data = data.map{|k,v| "#{CGI::escape(k)}=#{CGI::escape(v)}"}.join('&')
|
34
61
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
62
|
+
# if a oauth token exist, use it; unfortunately restclient does not allow a proper
|
63
|
+
RestClient.reset_before_execution_procs
|
64
|
+
RestClient.add_before_execution_proc do |req, par|
|
65
|
+
@access_token.sign! req
|
66
|
+
end if @access_token
|
67
|
+
resp = if [:put, :post,:patch].include?(method_sym)
|
68
|
+
RestClient::Request.execute(:method=>method_sym, :url=>@esnek_url, :payload=>data, :headers=>heades, :verify_ssl=>@verify_ssl)
|
69
|
+
else
|
70
|
+
RestClient::Request.execute(:method=>method_sym, :url=>@esnek_url, :headers=>heades, :verify_ssl=>@verify_ssl)
|
71
|
+
end
|
72
|
+
|
73
|
+
if @json_return
|
74
|
+
parse_json(resp)
|
75
|
+
else
|
76
|
+
resp
|
77
|
+
end
|
78
|
+
else
|
79
|
+
@esnek_chain << {:method => method_sym.to_s.gsub(/^__/,''), :arg => (args.empty? ? {} : args[0]) }
|
42
80
|
self
|
43
81
|
end
|
44
82
|
rescue
|
45
|
-
@
|
83
|
+
@esnek_chain = []
|
46
84
|
raise $!
|
47
85
|
end
|
48
|
-
|
86
|
+
|
49
87
|
def respond_to?(method_sym)
|
50
|
-
if [:get, :put, :post, :delete].include?(method_sym)
|
88
|
+
if [:head,:get, :put, :post,:patch, :delete].include?(method_sym)
|
51
89
|
true
|
52
90
|
else
|
53
91
|
super
|
54
92
|
end
|
55
93
|
end
|
56
|
-
|
57
|
-
end
|
94
|
+
|
95
|
+
end
|
data/lib/esnek/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ESNEK_VERSION='0.
|
1
|
+
ESNEK_VERSION='0.5.3'
|
data/test/base.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require './lib/esnek'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
|
6
|
+
describe Esnek do
|
7
|
+
before do
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "When I query json placeholder API" do
|
11
|
+
it "should return an object" do
|
12
|
+
esnek = Esnek.new('https://jsonplaceholder.typicode.com/')
|
13
|
+
res = esnek.todos.__1.get
|
14
|
+
assert_equal 1, res.id
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should put" do
|
18
|
+
esnek = Esnek.new('https://jsonplaceholder.typicode.com/')
|
19
|
+
res = esnek.todos.__1.put { { title: 'A' }}
|
20
|
+
assert_equal 1, res.id
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should post" do
|
24
|
+
esnek = Esnek.new('https://jsonplaceholder.typicode.com/')
|
25
|
+
res = esnek.todos.post { { title: 'A' }}
|
26
|
+
assert res.id > 0
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should delete" do
|
30
|
+
esnek = Esnek.new('https://jsonplaceholder.typicode.com/')
|
31
|
+
res = esnek.todos.__1.delete
|
32
|
+
assert res.id.nil?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,106 +1,116 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: esnek
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 5
|
10
|
-
version: 0.2.5
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.3
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Alper Akgun
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2021-04-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: json
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 1
|
29
|
-
segments:
|
30
|
-
- 1
|
31
|
-
- 5
|
32
|
-
- 1
|
33
|
-
version: 1.5.1
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.4'
|
34
20
|
type: :runtime
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: rest-client
|
38
21
|
prerelease: false
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
49
33
|
version: 1.6.1
|
50
34
|
type: :runtime
|
51
|
-
|
52
|
-
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.6.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: Esnek provides a minimalistic Ruby interface for JSON APIs, such as
|
70
|
+
ElasticSearch
|
53
71
|
email: esnek@sayarus.com
|
54
72
|
executables: []
|
55
|
-
|
56
73
|
extensions: []
|
57
|
-
|
58
|
-
extra_rdoc_files:
|
74
|
+
extra_rdoc_files:
|
59
75
|
- README.rdoc
|
60
76
|
- LICENSE
|
61
77
|
- CHANGES
|
62
78
|
- AUTHORS
|
63
|
-
files:
|
79
|
+
files:
|
80
|
+
- ".gitignore"
|
81
|
+
- AUTHORS
|
82
|
+
- CHANGES
|
83
|
+
- Gemfile
|
64
84
|
- LICENSE
|
65
85
|
- README.rdoc
|
66
86
|
- Rakefile
|
67
|
-
-
|
68
|
-
-
|
87
|
+
- esnek.gemspec
|
88
|
+
- lib/esnek.rb
|
69
89
|
- lib/esnek/base.rb
|
70
90
|
- lib/esnek/version.rb
|
71
|
-
-
|
91
|
+
- test/base.rb
|
72
92
|
homepage: https://github.com/sayarus/esnek
|
73
|
-
licenses:
|
74
|
-
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
75
96
|
post_install_message:
|
76
97
|
rdoc_options: []
|
77
|
-
|
78
|
-
require_paths:
|
98
|
+
require_paths:
|
79
99
|
- lib
|
80
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
-
|
82
|
-
requirements:
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
83
102
|
- - ">="
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
version: "0"
|
89
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
|
-
requirements:
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
92
107
|
- - ">="
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
|
95
|
-
segments:
|
96
|
-
- 0
|
97
|
-
version: "0"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
98
110
|
requirements: []
|
99
|
-
|
100
|
-
rubyforge_project:
|
101
|
-
rubygems_version: 1.7.2
|
111
|
+
rubygems_version: 3.1.2
|
102
112
|
signing_key:
|
103
|
-
specification_version:
|
113
|
+
specification_version: 4
|
104
114
|
summary: Esnek provides a minimalistic Ruby interface for JSON APIs, such as ElasticSearch
|
105
|
-
test_files:
|
106
|
-
|
115
|
+
test_files:
|
116
|
+
- test/base.rb
|