eltanin 0.0.2

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzMxZTFiNjRhZjE4ZDZlZjk0NjE1ZmYxOWZjMTMyZGYzMDI2ZmIzNQ==
5
+ data.tar.gz: !binary |-
6
+ ZWFiYjJiZGZmMGY2N2QzOTVkMTM4NzczYmNmMWEzNWE5NmEwZjBkMg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YTA0MGFlNTUyNWQ1OGExNWM4YjkyM2QwM2FlYTdkNWMxNDI2MmIzNzI1OTY4
10
+ MWQ0OTMyYzUyZjg3NTUzOGJjNTg0MjE2YWI0YzJkYTEwMzRkMjJiYzdkOTQ3
11
+ MjA3OTU3NTYwZmZhYTI3NDVkZGZlZmU3MzZkN2UxMTI0NGNjNmU=
12
+ data.tar.gz: !binary |-
13
+ NGUxMjk0ZjMzNjhiZTExMDY2MDgwZGVmZGI5NjFjZDhlY2I5MmI0NWFlM2Ez
14
+ ZmY2MjNlNjMxOTQ0YmUzODM0OWRmNjVhZGViNzViYmNlZGNjZTFiNWUwZWUw
15
+ NDg2OWJjZTY0MjIzYWFlYzVkMTgzYzk4NjMzMmIyOTAxNjM4YWU=
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in eltanin.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 David Rodenas
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Eltanin
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'eltanin'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install eltanin
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'eltanin/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "eltanin"
8
+ gem.version = Eltanin::VERSION
9
+ gem.authors = ["David Rodenas"]
10
+ gem.email = ["david.rodenas@gmail.com"]
11
+ gem.summary = "Driver to access Eltanin"
12
+ gem.description = "A simple driver to access to Eltanin"
13
+ gem.homepage = "http://rubygems.org/gems/eltanin"
14
+
15
+ gem.add_dependency "nestful"
16
+
17
+ gem.files = `git ls-files`.split($/)
18
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.require_paths = ["lib"]
21
+
22
+ end
@@ -0,0 +1,116 @@
1
+ require "eltanin/version"
2
+ require "nestful"
3
+
4
+ module Eltanin
5
+ extend self
6
+
7
+ def eye(root)
8
+ Eye.new root
9
+ end
10
+
11
+ class Eye
12
+
13
+ # Creates a new instance of the resource to Eltanin.
14
+ #
15
+ # It only requires an String that points to the root URI.
16
+ # The object itself is copied with modification each time that
17
+ # a change is required, so every instance will always spot to
18
+ # the same resource.
19
+ #
20
+ # Parameters:
21
+ # - +root+:: the URL to the Eltanin REST address, for example http://us@pas:eltanin-eye.com
22
+ def initialize(root, path = "", options = {}, queue = nil)
23
+ @root = root;
24
+ @path = path;
25
+ @options = options;
26
+ @queue = queue;
27
+ end
28
+
29
+ # Returns a new instance to a suburi of the current.
30
+ #
31
+ # For example: Eltanin.eye("http://ey.co")[:buyers] creates
32
+ # a resource that points to http;//ey.co/buyers
33
+ def [](suburl)
34
+ self.class.new @root, @path+"/"+suburl.to_s, @options, @queue
35
+ end
36
+
37
+ # Returns a new instance of a object that is a queue for batch calls.
38
+ #
39
+ # Eltanin EYE is designed to be able to group multiple calls into a
40
+ # single call. This method creates a new object that groups all
41
+ # requests. Methods get/put/post/delete/request will have no
42
+ # inmediate effect. These operations are queued waiting for a call
43
+ # to the method batch.
44
+ #
45
+ # An example:
46
+ # q = Eltanin.eye("http://ey.co").queue()
47
+ # buyers_idx = q['buyers'].get
48
+ # products_idx = q['products'].get
49
+ # all = q.batch
50
+ # buyers = all[buyers_idx]
51
+ # products = all[products_idx]
52
+ #
53
+ # See:
54
+ # batch()
55
+ def queue()
56
+ self.class.new @root, @path, @options, []
57
+ end
58
+
59
+ # Executes all enqueued requests.
60
+ #
61
+ # It must be called in to an object result of queue().
62
+ # Makes a single REST query with all pending requests.
63
+ # Each time that get/put/post/delete/request is invoked in a
64
+ # queue an index is returned, batch returns an array
65
+ # with all results indexed by its corresponding index.
66
+ #
67
+ # For more information and an example see queue()
68
+ def batch()
69
+ raise "Is not a queue" if @queue.nil?
70
+ r = (self.class.new @root, "/batch").post @queue unless @queue.empty?
71
+ @queue = []
72
+ r
73
+ end
74
+
75
+ # Makes a get request on top of the current resource.
76
+ def get(options = {})
77
+ request ({:method=>:get,:params=>{:limit=>50}}.merge(options))
78
+ end
79
+
80
+ # Makes a post request on top of the current resource.
81
+ def post(value=nil, options = {})
82
+ request ({:method=>:post,:params=>value}.merge(options))
83
+ end
84
+
85
+ # Makes a put request on top of the current resource.
86
+ def put(value=nil, options = {})
87
+ request ({:method=>:put,:params=>value}.merge(options))
88
+ end
89
+
90
+ # Makes a delete request on top of the current resource.
91
+ def delete(options = {})
92
+ request ({:method=>:delete}.merge(options))
93
+ end
94
+
95
+ def request(options)
96
+ if @queue.nil?
97
+ resource = Nestful::Resource.new(@root+@path,{:format=>:json}.merge(@options))
98
+ begin
99
+ resource.request options
100
+ rescue Nestful::ClientError => e
101
+ e
102
+ end
103
+ else
104
+ r = { "method" => options[:method], "path" => @path }
105
+ if options[:method] == :get
106
+ r["path"] += "?"+ (URI.encode_www_form options[:params])
107
+ else
108
+ r["body"] = options[:params] unless options[:params].nil?
109
+ end
110
+ @queue << r
111
+ @queue.size - 1
112
+ end
113
+ end
114
+
115
+ end
116
+ end
@@ -0,0 +1,3 @@
1
+ module Eltanin
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eltanin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - David Rodenas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nestful
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A simple driver to access to Eltanin
28
+ email:
29
+ - david.rodenas@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - Gemfile
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - eltanin.gemspec
40
+ - lib/eltanin.rb
41
+ - lib/eltanin/version.rb
42
+ homepage: http://rubygems.org/gems/eltanin
43
+ licenses: []
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.0.0
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Driver to access Eltanin
65
+ test_files: []