fluidinfo 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem "rest-client"
6
+ gem "json"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "shoulda", ">= 0"
12
+ gem "bundler", "~> 1.0.0"
13
+ gem "jeweler", "~> 1.5.2"
14
+ gem "rcov", ">= 0"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ json (1.5.1)
10
+ mime-types (1.16)
11
+ rake (0.8.7)
12
+ rcov (0.9.9)
13
+ rest-client (1.6.1)
14
+ mime-types (>= 1.16)
15
+ shoulda (2.11.3)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ bundler (~> 1.0.0)
22
+ jeweler (~> 1.5.2)
23
+ json
24
+ rcov
25
+ rest-client
26
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Eric Seidel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,30 @@
1
+ = fluidinfo
2
+
3
+ Fluidinfo.rb provides a simple interface to fluidinfo.
4
+
5
+ == Simple Example
6
+
7
+ >> require 'fluidinfo'
8
+ >> fluid = Fluidinfo::Client.new
9
+ >> fluid.get '/objects', :query => 'has gridaphobe/met'
10
+ => {"ids"=>["fa0bb30b-d1c2-4438-b65c-d86bbb1a44cd"]}
11
+
12
+ For now, check out Fluidinfo's extensive
13
+ {documentation}[http://api.fluidinfo.com/] for explanations of each API call.
14
+
15
+
16
+ == Contributing to fluidinfo
17
+
18
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
19
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
20
+ * Fork the project
21
+ * Start a feature/bugfix branch
22
+ * Commit and push until you are happy with your contribution
23
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
24
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
25
+
26
+ == Copyright
27
+
28
+ Copyright (c) 2011 Eric Seidel. See LICENSE.txt for
29
+ further details.
30
+
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "fluidinfo"
16
+ gem.homepage = "http://github.com/gridaphobe/fluidinfo"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Provides a simple interface to fluidinfo}
19
+ gem.description = %Q{This gem provides a simple interface to fluidinfo, built on top of the rest-client gem.}
20
+ gem.email = "gridaphobe@gmail.com"
21
+ gem.authors = ["Eric Seidel"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ gem.add_runtime_dependency "rest-client"
27
+ gem.add_runtime_dependency "json"
28
+ end
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+
31
+ require 'rake/testtask'
32
+ Rake::TestTask.new(:test) do |test|
33
+ test.libs << 'lib' << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
+
38
+ require 'rcov/rcovtask'
39
+ Rcov::RcovTask.new do |test|
40
+ test.libs << 'test'
41
+ test.pattern = 'test/**/test_*.rb'
42
+ test.verbose = true
43
+ end
44
+
45
+ task :default => :test
46
+
47
+ require 'rake/rdoctask'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "fluidinfo #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
data/fluidinfo.gemspec ADDED
@@ -0,0 +1,75 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{fluidinfo}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Eric Seidel"]
12
+ s.date = %q{2011-03-22}
13
+ s.description = %q{This gem provides a simple interface to fluidinfo, built on top of the rest-client gem.}
14
+ s.email = %q{gridaphobe@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "fluidinfo.gemspec",
28
+ "lib/fluidinfo.rb",
29
+ "test/helper.rb",
30
+ "test/test_fluidinfo.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/gridaphobe/fluidinfo}
33
+ s.licenses = ["MIT"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.6.2}
36
+ s.summary = %q{Provides a simple interface to fluidinfo}
37
+ s.test_files = [
38
+ "test/helper.rb",
39
+ "test/test_fluidinfo.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<rest-client>, [">= 0"])
47
+ s.add_runtime_dependency(%q<json>, [">= 0"])
48
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
49
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
51
+ s.add_development_dependency(%q<rcov>, [">= 0"])
52
+ s.add_runtime_dependency(%q<rest-client>, [">= 0"])
53
+ s.add_runtime_dependency(%q<json>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<rest-client>, [">= 0"])
56
+ s.add_dependency(%q<json>, [">= 0"])
57
+ s.add_dependency(%q<shoulda>, [">= 0"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
60
+ s.add_dependency(%q<rcov>, [">= 0"])
61
+ s.add_dependency(%q<rest-client>, [">= 0"])
62
+ s.add_dependency(%q<json>, [">= 0"])
63
+ end
64
+ else
65
+ s.add_dependency(%q<rest-client>, [">= 0"])
66
+ s.add_dependency(%q<json>, [">= 0"])
67
+ s.add_dependency(%q<shoulda>, [">= 0"])
68
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
69
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
70
+ s.add_dependency(%q<rcov>, [">= 0"])
71
+ s.add_dependency(%q<rest-client>, [">= 0"])
72
+ s.add_dependency(%q<json>, [">= 0"])
73
+ end
74
+ end
75
+
data/lib/fluidinfo.rb ADDED
@@ -0,0 +1,121 @@
1
+ require "rest-client"
2
+ require "uri"
3
+ require "json"
4
+ require "base64"
5
+
6
+ module Fluidinfo
7
+ class Client
8
+ # The main fluidinfo instance.
9
+ @@MAIN = 'https://fluiddb.fluidinfo.com'
10
+ # The sandbox instance, test your code here.
11
+ @@SANDBOX = 'https://sandbox.fluidinfo.com'
12
+
13
+ def initialize(options={})
14
+ if options[:sandbox]
15
+ @instance = @@SANDBOX
16
+ else
17
+ @instance = @@MAIN
18
+ end
19
+ @headers = {
20
+ "Accept" => "*/*"
21
+ }
22
+ end
23
+
24
+ def login(user, pass)
25
+ auth = "Basic " + (Base64.encode64 "#{user}:#{pass}").strip
26
+ @headers["Authorization"] = auth
27
+ end
28
+
29
+ def logout
30
+ @headers.delete "Authorization"
31
+ end
32
+
33
+ # Call GET
34
+ def get(path, options={})
35
+ path = @instance + path
36
+ args = ''
37
+ options.each do |key, val|
38
+ if key == :tags
39
+ val.each do |tag|
40
+ args += "&tag=#{URI.escape tag.to_s}"
41
+ end
42
+ else
43
+ args += "&#{URI.escape key.to_s}=#{URI.escape val.to_s}"
44
+ end
45
+ args[0] = '?'
46
+ end
47
+ path += args
48
+ response = RestClient.get path, @headers
49
+ begin
50
+ JSON.load response.to_str
51
+ rescue JSON::ParserError
52
+ # this should mean that fluidinfo returned a non-hash/array primitive
53
+ eval response.to_str
54
+ end
55
+ end
56
+
57
+ def head(path)
58
+ path = @instance + path
59
+ RestClient.head path
60
+ end
61
+
62
+ def post(path, options={})
63
+ path = @instance + path
64
+ if options[:body]
65
+ if options[:mime]
66
+ mime = options[:mime]
67
+ body = options[:body]
68
+ else
69
+ mime = "application/json"
70
+ begin
71
+ body = JSON.dump options[:body]
72
+ rescue JSON::GeneratorError
73
+ body = options[:body]
74
+ end
75
+ end
76
+ headers = @headers.merge :content_type => mime
77
+ JSON.parse(RestClient.post path, body, headers)
78
+ else
79
+ JSON.parse(RestClient.post path, nil)
80
+ end
81
+ end
82
+
83
+ def put(path, options={})
84
+ path = @instance + path
85
+ if options[:query]
86
+ query = URI.escape options[:query]
87
+ path += "?query=#{query}"
88
+ end
89
+ body = options[:body]
90
+ if options[:mime]
91
+ mime = options[:mime]
92
+ else
93
+ mime = "application/json"
94
+ begin
95
+ body = JSON.dump options[:body]
96
+ rescue JSON::GeneratorError
97
+ body = options[:body]
98
+ end
99
+ end
100
+ # nothing returned in response body for PUT
101
+ headers = @headers.merge :content_type => mime
102
+ RestClient.put path, body, headers
103
+ end
104
+
105
+ def delete(path, options={})
106
+ path = @instance + path
107
+ if options[:query]
108
+ query = URI.escape options[:query]
109
+ path += "?query=#{query}"
110
+ end
111
+ if options[:tags]
112
+ options[:tags].each do |tag|
113
+ tag = URI.escape tag
114
+ path += "&tag=#{tag}"
115
+ end
116
+ end
117
+ # nothing returned in response body for DELETE
118
+ RestClient.delete path
119
+ end
120
+ end
121
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'fluidinfo'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,76 @@
1
+ require 'helper'
2
+
3
+ class FluidinfoTest < Test::Unit::TestCase
4
+ context "GET" do
5
+ setup do
6
+ @fluid = Fluidinfo::Client.new
7
+ end
8
+
9
+ context "/objects" do
10
+ should "retrieve tags correctly" do
11
+ uid = "e034d8c0-a2e4-4094-895b-3a8065f9696e"
12
+ tag = "gridaphobe/given-name"
13
+ assert_equal "Eric", @fluid.get("/objects/#{uid}/#{tag}")
14
+ end
15
+
16
+ should "process queries correctly" do
17
+ query = 'fluiddb/users/username = "gridaphobe"'
18
+ expected = {
19
+ "ids" => ["e034d8c0-a2e4-4094-895b-3a8065f9696e"]
20
+ }
21
+ assert_equal expected, @fluid.get("/objects", :query => query)
22
+ end
23
+
24
+ should "retrieve objects with about tag" do
25
+ uid = "206b5ca5-cd69-469a-9aba-44b28cfb455e"
26
+ expected = {
27
+ "about"=>nil,
28
+ "tagPaths"=>["gridaphobe/test/test_tag"]
29
+ }
30
+ assert_equal expected, @fluid.get("/objects/#{uid}", :showAbout => true)
31
+ end
32
+
33
+ should "retrieve objects without about tag" do
34
+ uid = "206b5ca5-cd69-469a-9aba-44b28cfb455e"
35
+ expected = {
36
+ "tagPaths"=>["gridaphobe/test/test_tag"]
37
+ }
38
+ assert_equal expected, @fluid.get("/objects/#{uid}")
39
+ end
40
+
41
+ should "raise 404 errors on bad request" do
42
+ uid = "1"
43
+ tag = "gridaphobe/given-name"
44
+ assert_raise RestClient::ResourceNotFound do
45
+ @fluid.get "/objects/#{uid}/#{tag}"
46
+ end
47
+ end
48
+ end
49
+
50
+ context "/namespaces" do
51
+ should "show basic information about namespaces" do
52
+ user = "gridaphobe"
53
+ ns = "test"
54
+ expected = {
55
+ "id" =>"9c16dcbe-87fd-4fe9-ae0e-699be84f1105"
56
+ }
57
+ assert_equal expected, @fluid.get("/namespaces/#{user}/#{ns}")
58
+ end
59
+
60
+ should "show detailed information about namespaces" do
61
+ user = "gridaphobe"
62
+ ns = "test"
63
+ expected = {
64
+ "tagNames" => ["test_tag"],
65
+ "namespaceNames" => ["sub_ns"],
66
+ "id" =>"9c16dcbe-87fd-4fe9-ae0e-699be84f1105",
67
+ "description" =>"test"
68
+ }
69
+ assert_equal expected, @fluid.get("/namespaces/#{user}/#{ns}",
70
+ :returnDescription => true,
71
+ :returnTags => true,
72
+ :returnNamespaces => true)
73
+ end
74
+ end
75
+ end
76
+ end
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluidinfo
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
+ platform: ruby
12
+ authors:
13
+ - Eric Seidel
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-22 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ name: rest-client
32
+ version_requirements: *id001
33
+ prerelease: false
34
+ type: :runtime
35
+ - !ruby/object:Gem::Dependency
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ hash: 3
42
+ segments:
43
+ - 0
44
+ version: "0"
45
+ name: json
46
+ version_requirements: *id002
47
+ prerelease: false
48
+ type: :runtime
49
+ - !ruby/object:Gem::Dependency
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ name: shoulda
60
+ version_requirements: *id003
61
+ prerelease: false
62
+ type: :development
63
+ - !ruby/object:Gem::Dependency
64
+ requirement: &id004 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ hash: 23
70
+ segments:
71
+ - 1
72
+ - 0
73
+ - 0
74
+ version: 1.0.0
75
+ name: bundler
76
+ version_requirements: *id004
77
+ prerelease: false
78
+ type: :development
79
+ - !ruby/object:Gem::Dependency
80
+ requirement: &id005 !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ hash: 7
86
+ segments:
87
+ - 1
88
+ - 5
89
+ - 2
90
+ version: 1.5.2
91
+ name: jeweler
92
+ version_requirements: *id005
93
+ prerelease: false
94
+ type: :development
95
+ - !ruby/object:Gem::Dependency
96
+ requirement: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ name: rcov
106
+ version_requirements: *id006
107
+ prerelease: false
108
+ type: :development
109
+ - !ruby/object:Gem::Dependency
110
+ requirement: &id007 !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ name: rest-client
120
+ version_requirements: *id007
121
+ prerelease: false
122
+ type: :runtime
123
+ - !ruby/object:Gem::Dependency
124
+ requirement: &id008 !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ hash: 3
130
+ segments:
131
+ - 0
132
+ version: "0"
133
+ name: json
134
+ version_requirements: *id008
135
+ prerelease: false
136
+ type: :runtime
137
+ description: This gem provides a simple interface to fluidinfo, built on top of the rest-client gem.
138
+ email: gridaphobe@gmail.com
139
+ executables: []
140
+
141
+ extensions: []
142
+
143
+ extra_rdoc_files:
144
+ - LICENSE.txt
145
+ - README.rdoc
146
+ files:
147
+ - .document
148
+ - Gemfile
149
+ - Gemfile.lock
150
+ - LICENSE.txt
151
+ - README.rdoc
152
+ - Rakefile
153
+ - VERSION
154
+ - fluidinfo.gemspec
155
+ - lib/fluidinfo.rb
156
+ - test/helper.rb
157
+ - test/test_fluidinfo.rb
158
+ has_rdoc: true
159
+ homepage: http://github.com/gridaphobe/fluidinfo
160
+ licenses:
161
+ - MIT
162
+ post_install_message:
163
+ rdoc_options: []
164
+
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ none: false
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ hash: 3
173
+ segments:
174
+ - 0
175
+ version: "0"
176
+ required_rubygems_version: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ hash: 3
182
+ segments:
183
+ - 0
184
+ version: "0"
185
+ requirements: []
186
+
187
+ rubyforge_project:
188
+ rubygems_version: 1.6.2
189
+ signing_key:
190
+ specification_version: 3
191
+ summary: Provides a simple interface to fluidinfo
192
+ test_files:
193
+ - test/helper.rb
194
+ - test/test_fluidinfo.rb