esnek 0.5.0 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 51bd712e9e708a69ead2eb6f40485677a391f8c2
4
- data.tar.gz: 4963c8831cd8c6d079ddceadcf2c5143acded2b0
2
+ SHA256:
3
+ metadata.gz: 7d749360bb64f84c76b7ac31b748185c32213ac8a14ae82cdf8b2292c7301e75
4
+ data.tar.gz: 731a01d8ad37a56901fa6ec13f87035c5ba204955baddd08fed3cfea6dfb0692
5
5
  SHA512:
6
- metadata.gz: cc709556d2794cf54de28aaebf388c06bf4ef69ff71c3105a45cb60418e7cef38bdd209c99c35e2d6e76d26a861dab0979ec56ccdc689982a9bc0424d2bf93d8
7
- data.tar.gz: 641901f95ab9cc5400e1075fbe84e47f6e8bb9aaf163fcd23bb6c5ab1875911a66443a804133084faa328690f28251a370931225be2e2ee3c0d45139fa90ecba
6
+ metadata.gz: 5ce7fb6809f7e62f903269779d73887fec4d9160bc6b57a59491f8cf7f62f27799cc815c1cc16261a05fc9cbed1e312db62de3fdf91dd06d9b12f566f1266d58
7
+ data.tar.gz: c5023354cd4bc9c75bf84a0c9f956ee5833f0ed866070ae30a9ee748a564adeb58dfdf7bff7a0f0c6f3d9ff2f96471bfe8458c3e62877adef1b65b37ea37ed0c
data/.gitignore CHANGED
@@ -13,3 +13,4 @@
13
13
  *.a
14
14
  *.gem
15
15
  mkmf.log
16
+ .redcar
data/AUTHORS CHANGED
@@ -1,5 +1,3 @@
1
1
  Esnek was initialled developed and hosted by Sayarus.
2
2
 
3
3
  Alper Akgun: initial developer
4
-
5
-
data/CHANGES CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  == Expected
4
4
 
5
+ == 0.5.1
6
+ * Verify SSL 1 support
7
+
5
8
  == 0.4.x
6
9
  * MIT License adopted
7
10
 
data/Gemfile CHANGED
@@ -4,10 +4,7 @@ source 'https://rubygems.org' unless ENV['QUICK']
4
4
  gemspec
5
5
 
6
6
  gem 'rake'
7
- if RUBY_ENGINE == "ruby" and RUBY_VERSION > '1.9.2'
8
7
  gem 'rest-client'
9
8
  gem 'json'
10
9
  gem "minitest", "~> 4.0"
11
10
  gem 'rdoc'
12
- end
13
-
data/README.rdoc CHANGED
@@ -12,20 +12,15 @@ Twitter OAuth login integrations.
12
12
 
13
13
  == Quick Start
14
14
 
15
- === Google URL Shortener
15
+ ===
16
16
  require 'esnek'
17
- gapi = Esnek.new('https://www.googleapis.com')
18
- res = gapi.urlshortener.v1.url.post {{:longUrl => "http://www.resimit.com/"}}
19
- # Use res.table[:id] instead of res.id, because id method already exist for Object
20
- puts res.longUrl
21
- puts res.inspect
17
+ esnek = Esnek.new('https://jsonplaceholder.typicode.com/')
18
+ todo = esnek.todos.__1.get
19
+ puts todo.id
20
+ puts todo.inspect
22
21
 
23
22
  === Facebook Graph API
24
23
  require 'esnek'
25
- fb = Esnek.new('http://graph.facebook.com')
26
- res = fb.send(:"http://www.resimit.com").get
27
- # Notice that since "http://www.resimit.com" is a complex ruby method name, we use "send" to call it
28
- puts res.shares
29
24
 
30
25
  === ElasticSearch
31
26
 
data/esnek.gemspec CHANGED
@@ -6,7 +6,6 @@ require 'esnek/version'
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'esnek'
8
8
  s.version = ESNEK_VERSION
9
- #s.has_rdoc = true
10
9
  s.extra_rdoc_files = ['README.rdoc', 'LICENSE','CHANGES','AUTHORS']
11
10
  s.summary = 'Esnek provides a minimalistic Ruby interface for JSON APIs, such as ElasticSearch'
12
11
  s.description = s.summary
@@ -24,9 +23,3 @@ Gem::Specification.new do |s|
24
23
  s.add_development_dependency "bundler", "~> 1.6"
25
24
  s.add_development_dependency "rake", "~> 10.0"
26
25
  end
27
-
28
-
29
-
30
-
31
-
32
-
data/lib/esnek/base.rb CHANGED
@@ -1,20 +1,23 @@
1
1
  require 'rest_client'
2
2
  require 'json'
3
3
 
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).
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).
6
6
  class Esnek
7
7
  #attr_accessor :esnek_chain, :esnek_url_root, :esnek_params, :esnek_url
8
- def initialize(esnek_url_root,options={:json_api=>true,:json_return=>true, :header=>{}})
8
+ def initialize(esnek_url_root, options={:verify_ssl=>true, :json_api=>true,:json_return=>true, :header=>{}})
9
9
  @esnek_url_root = esnek_url_root
10
10
  @esnek_chain = []
11
11
  @json_api = options[:json_api].nil? ? true : options[:json_api]
12
12
  @json_return = options[:json_return].nil? ? @json_api : options[:json_return]
13
+ @verify_ssl = options[:verify_ssl]
13
14
  @header= options[:header] || {}
14
15
  if options[:oauth] # Esnek assumes that oauth ruby gem is installed
15
16
  options[:oauth][:scheme] ||= :header
16
17
  consumer = OAuth::Consumer.new(options[:oauth][:consumer_key],options[:oauth][:consumer_secret], {:site => options[:oauth][:site], :scheme => options[:oauth][:scheme]})
17
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
18
21
  end
19
22
  end
20
23
 
@@ -31,7 +34,7 @@ class Esnek
31
34
  class<<r;def table;@table;end;end;
32
35
  else
33
36
  e
34
- end
37
+ end
35
38
  r}
36
39
  else
37
40
  j
@@ -58,18 +61,18 @@ class Esnek
58
61
  RestClient.add_before_execution_proc do |req, par|
59
62
  @access_token.sign! req
60
63
  end if @access_token
61
- resp = if [:put, :post,:patch].include?(method_sym)
62
- RestClient.send(method_sym, @esnek_url, data, heades)
64
+ resp = if [:put, :post,:patch].include?(method_sym)
65
+ RestClient::Request.execute(:method=>method_sym, :url=>@esnek_url, :payload=>data, :headers=>heades, :verify_ssl=>@verify_ssl)
63
66
  else
64
- RestClient.send(method_sym, @esnek_url, heades)
67
+ RestClient::Request.execute(:method=>method_sym, :url=>@esnek_url, :headers=>heades, :verify_ssl=>@verify_ssl)
65
68
  end
66
-
69
+
67
70
  if @json_return
68
71
  parse_json(resp)
69
72
  else
70
73
  resp
71
74
  end
72
- else
75
+ else
73
76
  @esnek_chain << {:method => method_sym.to_s.gsub(/^__/,''), :arg => (args.empty? ? {} : args[0]) }
74
77
  self
75
78
  end
@@ -77,7 +80,7 @@ class Esnek
77
80
  @esnek_chain = []
78
81
  raise $!
79
82
  end
80
-
83
+
81
84
  def respond_to?(method_sym)
82
85
  if [:head,:get, :put, :post,:patch, :delete].include?(method_sym)
83
86
  true
@@ -85,5 +88,5 @@ class Esnek
85
88
  super
86
89
  end
87
90
  end
88
-
91
+
89
92
  end
data/lib/esnek/version.rb CHANGED
@@ -1 +1 @@
1
- ESNEK_VERSION='0.5.0'
1
+ ESNEK_VERSION='0.5.1'
data/test/base.rb CHANGED
@@ -4,24 +4,32 @@ require './lib/esnek'
4
4
  require 'minitest/autorun'
5
5
 
6
6
  describe Esnek do
7
- before do
7
+ before do
8
8
  end
9
9
 
10
- describe "When I query Google URL Shortener API" do
11
- it "should return a shortened URL" do
12
- gapi = Esnek.new('https://www.googleapis.com')
13
- res = gapi.urlshortener.v1.url.post {{:longUrl => "http://www.resimit.com/"}}
14
- puts res.inspect
15
- end
16
- end
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
17
16
 
18
- describe "When I query Facebook graph API to count the # of shares of url" do
19
- it "should return an object which responds to :shares" do
20
- fb = Esnek.new('http://graph.facebook.com')
21
- res = fb.send(:"http://www.resimit.com").get
22
- assert res.respond_to?(:shares)
23
- puts res.inspect
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
24
27
  end
25
- end
26
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
27
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: esnek
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alper Akgun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-09 00:00:00.000000000 Z
11
+ date: 2021-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -108,8 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubyforge_project:
112
- rubygems_version: 2.2.2
111
+ rubygems_version: 3.1.2
113
112
  signing_key:
114
113
  specification_version: 4
115
114
  summary: Esnek provides a minimalistic Ruby interface for JSON APIs, such as ElasticSearch