fluidinfo 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +10 -5
- data/VERSION +1 -1
- data/fluidinfo.gemspec +2 -2
- data/lib/fluidinfo.rb +38 -20
- data/test/test_fluidinfo.rb +30 -2
- metadata +19 -19
data/README.rdoc
CHANGED
@@ -14,14 +14,19 @@ For now, check out Fluidinfo's extensive
|
|
14
14
|
|
15
15
|
|
16
16
|
== Contributing to fluidinfo
|
17
|
-
|
18
|
-
* Check out the latest master to make sure the feature hasn't been implemented
|
19
|
-
|
17
|
+
|
18
|
+
* Check out the latest master to make sure the feature hasn't been implemented
|
19
|
+
or the bug hasn't been fixed yet
|
20
|
+
* Check out the issue tracker to make sure someone already hasn't requested it
|
21
|
+
and/or contributed it
|
20
22
|
* Fork the project
|
21
23
|
* Start a feature/bugfix branch
|
22
24
|
* 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
|
24
|
-
|
25
|
+
* Make sure to add tests for it. This is important so I don't break it in a
|
26
|
+
future version unintentionally.
|
27
|
+
* Please try not to mess with the Rakefile, version, or history. If you want
|
28
|
+
to have your own version, or is otherwise necessary, that is fine, but please
|
29
|
+
isolate to its own commit so I can cherry-pick around it.
|
25
30
|
|
26
31
|
== Copyright
|
27
32
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/fluidinfo.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{fluidinfo}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Eric Seidel"]
|
12
|
-
s.date = %q{2011-04-
|
12
|
+
s.date = %q{2011-04-09}
|
13
13
|
s.description = %q{This gem provides a simple interface to fluidinfo, built on top of the rest-client gem.}
|
14
14
|
s.email = %q{gridaphobe@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/fluidinfo.rb
CHANGED
@@ -5,12 +5,12 @@ require "base64"
|
|
5
5
|
require "set"
|
6
6
|
|
7
7
|
module Fluidinfo
|
8
|
-
ITERABLE_TYPES
|
9
|
-
|
10
|
-
|
11
|
-
JSON_TYPES
|
12
|
-
|
13
|
-
|
8
|
+
ITERABLE_TYPES = Set.new [Array]
|
9
|
+
SERIALIZEABLE_TYPES = Set.new [NilClass, String, Fixnum, Float, Symbol,
|
10
|
+
TrueClass, FalseClass, Array]
|
11
|
+
JSON_TYPES = Set.new ["application/json",
|
12
|
+
"application/vnd.fluiddb.value+json"]
|
13
|
+
|
14
14
|
class Client
|
15
15
|
# The main fluidinfo instance.
|
16
16
|
@@MAIN = 'https://fluiddb.fluidinfo.com'
|
@@ -24,13 +24,14 @@ module Fluidinfo
|
|
24
24
|
@instance = @@MAIN
|
25
25
|
end
|
26
26
|
@headers = {
|
27
|
-
:accept => "*/*"
|
27
|
+
:accept => "*/*",
|
28
|
+
:user_agent => "fluidinfo.rb/#{Fluidinfo.version}"
|
28
29
|
}
|
29
30
|
end
|
30
31
|
|
31
32
|
def login(user, pass)
|
32
|
-
|
33
|
-
|
33
|
+
@headers[:authorization] = "Basic " +
|
34
|
+
(Base64.encode64 "#{user}:#{pass}").strip
|
34
35
|
end
|
35
36
|
|
36
37
|
def logout
|
@@ -58,7 +59,7 @@ module Fluidinfo
|
|
58
59
|
# of a tag
|
59
60
|
def head(path)
|
60
61
|
path = @instance + path
|
61
|
-
RestClient.head path
|
62
|
+
RestClient.head path, @headers
|
62
63
|
end
|
63
64
|
|
64
65
|
##
|
@@ -73,7 +74,7 @@ module Fluidinfo
|
|
73
74
|
headers = @headers.merge :content_type => payload[:mime]
|
74
75
|
JSON.parse(RestClient.post path, payload[:body], headers)
|
75
76
|
else
|
76
|
-
JSON.parse(RestClient.post path, nil)
|
77
|
+
JSON.parse(RestClient.post path, nil, @headers)
|
77
78
|
end
|
78
79
|
end
|
79
80
|
|
@@ -82,7 +83,8 @@ module Fluidinfo
|
|
82
83
|
#
|
83
84
|
# +options[:body]+ contains the request payload.
|
84
85
|
#
|
85
|
-
# +options[:mime]+ contains the MIME-type unless the payload is
|
86
|
+
# +options[:mime]+ contains the MIME-type unless the payload is
|
87
|
+
# JSON-encodable
|
86
88
|
def put(path, options={})
|
87
89
|
url = build_url path, options
|
88
90
|
payload = build_payload options
|
@@ -95,8 +97,8 @@ module Fluidinfo
|
|
95
97
|
# Call DELETE on one of the APIs
|
96
98
|
#
|
97
99
|
# +options+ contains URI arguments that will be appended to +path+
|
98
|
-
# consult the {Fluidinfo API documentation}[api.fluidinfo.com] for a list
|
99
|
-
# appropriate options
|
100
|
+
# consult the {Fluidinfo API documentation}[api.fluidinfo.com] for a list
|
101
|
+
# of appropriate options
|
100
102
|
def delete(path, options={})
|
101
103
|
url = build_url path, options
|
102
104
|
# nothing returned in response body for DELETE
|
@@ -140,18 +142,34 @@ module Fluidinfo
|
|
140
142
|
else
|
141
143
|
payload[:size] = payload[:body].size
|
142
144
|
end
|
143
|
-
|
144
|
-
elsif ITERABLE_TYPES.include? payload[:body].class
|
145
|
+
elsif payload[:body].is_a? Hash
|
145
146
|
payload[:body] = JSON.dump payload[:body]
|
146
147
|
payload[:mime] = "application/json"
|
147
|
-
|
148
|
-
|
148
|
+
elsif SERIALIZEABLE_TYPES.include? payload[:body].class
|
149
|
+
if ITERABLE_TYPES.include? payload[:body].class
|
150
|
+
if is_set_of_strings? payload[:body]
|
151
|
+
# set of strings is primitive
|
152
|
+
payload[:mime] = "application/vnd.fluiddb.value+json"
|
153
|
+
else
|
154
|
+
# we have an Array with some non-String items
|
155
|
+
payload[:mime] = "application/json"
|
156
|
+
end
|
157
|
+
else
|
158
|
+
# primitive type
|
159
|
+
payload[:mime] = "application/vnd.fluiddb.value+json"
|
160
|
+
end
|
149
161
|
payload[:body] = JSON.dump payload[:body]
|
150
|
-
payload[:mime] = "application/vnd.fluiddb.value+json"
|
151
|
-
payload
|
152
162
|
else
|
153
163
|
raise TypeError, "You must supply the mime-type"
|
154
164
|
end
|
165
|
+
payload
|
166
|
+
end
|
167
|
+
|
168
|
+
##
|
169
|
+
# Check if payload is a "set of strings"
|
170
|
+
def is_set_of_strings?(list)
|
171
|
+
# are all elements unique strings?
|
172
|
+
list.all? { |x| x.is_a? String } && list == list.uniq
|
155
173
|
end
|
156
174
|
end
|
157
175
|
|
data/test/test_fluidinfo.rb
CHANGED
@@ -151,8 +151,11 @@ class FluidinfoTest < Test::Unit::TestCase
|
|
151
151
|
end
|
152
152
|
|
153
153
|
# now cleanup
|
154
|
-
@fluid.delete "/tags/test/#{new_ns}/#{new_tag}"
|
155
|
-
|
154
|
+
response = @fluid.delete "/tags/test/#{new_ns}/#{new_tag}"
|
155
|
+
assert_equal 204, response.code
|
156
|
+
|
157
|
+
response = @fluid.delete "/namespaces/test/#{new_ns}"
|
158
|
+
assert_equal 204, response.code
|
156
159
|
end
|
157
160
|
|
158
161
|
should "update opaque tag values" do
|
@@ -190,4 +193,29 @@ class FluidinfoTest < Test::Unit::TestCase
|
|
190
193
|
end
|
191
194
|
end
|
192
195
|
end
|
196
|
+
|
197
|
+
context "private functions" do
|
198
|
+
setup do
|
199
|
+
@fluid = Fluidinfo::Client.new
|
200
|
+
def @fluid.test_build_payload(*args)
|
201
|
+
build_payload(*args)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context "build_payload" do
|
206
|
+
should "set proper mime-types" do
|
207
|
+
primitives = [1, 1.1, true, false, nil, ["1", "2", "hi"]]
|
208
|
+
primitives.each do |p|
|
209
|
+
h = @fluid.test_build_payload :body => p
|
210
|
+
assert_equal "application/vnd.fluiddb.value+json", h[:mime]
|
211
|
+
end
|
212
|
+
|
213
|
+
non_primitives = [[1, 2, 3], {"hi" => "there"}]
|
214
|
+
non_primitives.each do |n|
|
215
|
+
h = @fluid.test_build_payload :body => n
|
216
|
+
assert_equal "application/json", h[:mime]
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
193
221
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluidinfo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eric Seidel
|
@@ -15,10 +15,10 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-09 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
22
|
none: false
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
@@ -29,12 +29,12 @@ dependencies:
|
|
29
29
|
- 6
|
30
30
|
- 1
|
31
31
|
version: 1.6.1
|
32
|
-
version_requirements: *id001
|
33
32
|
name: rest-client
|
34
33
|
prerelease: false
|
35
34
|
type: :runtime
|
35
|
+
requirement: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
|
37
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
38
|
none: false
|
39
39
|
requirements:
|
40
40
|
- - ">="
|
@@ -45,12 +45,12 @@ dependencies:
|
|
45
45
|
- 8
|
46
46
|
- 2
|
47
47
|
version: 0.8.2
|
48
|
-
version_requirements: *id002
|
49
48
|
name: yajl-ruby
|
50
49
|
prerelease: false
|
51
50
|
type: :runtime
|
51
|
+
requirement: *id002
|
52
52
|
- !ruby/object:Gem::Dependency
|
53
|
-
|
53
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
54
|
none: false
|
55
55
|
requirements:
|
56
56
|
- - ">="
|
@@ -59,12 +59,12 @@ dependencies:
|
|
59
59
|
segments:
|
60
60
|
- 0
|
61
61
|
version: "0"
|
62
|
-
version_requirements: *id003
|
63
62
|
name: shoulda
|
64
63
|
prerelease: false
|
65
64
|
type: :development
|
65
|
+
requirement: *id003
|
66
66
|
- !ruby/object:Gem::Dependency
|
67
|
-
|
67
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
68
68
|
none: false
|
69
69
|
requirements:
|
70
70
|
- - ~>
|
@@ -75,12 +75,12 @@ dependencies:
|
|
75
75
|
- 0
|
76
76
|
- 0
|
77
77
|
version: 1.0.0
|
78
|
-
version_requirements: *id004
|
79
78
|
name: bundler
|
80
79
|
prerelease: false
|
81
80
|
type: :development
|
81
|
+
requirement: *id004
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
|
-
|
83
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ~>
|
@@ -91,12 +91,12 @@ dependencies:
|
|
91
91
|
- 5
|
92
92
|
- 2
|
93
93
|
version: 1.5.2
|
94
|
-
version_requirements: *id005
|
95
94
|
name: jeweler
|
96
95
|
prerelease: false
|
97
96
|
type: :development
|
97
|
+
requirement: *id005
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
|
-
|
99
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
100
100
|
none: false
|
101
101
|
requirements:
|
102
102
|
- - ">="
|
@@ -105,12 +105,12 @@ dependencies:
|
|
105
105
|
segments:
|
106
106
|
- 0
|
107
107
|
version: "0"
|
108
|
-
version_requirements: *id006
|
109
108
|
name: rcov
|
110
109
|
prerelease: false
|
111
110
|
type: :development
|
111
|
+
requirement: *id006
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
|
-
|
113
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
114
114
|
none: false
|
115
115
|
requirements:
|
116
116
|
- - ">="
|
@@ -121,10 +121,10 @@ dependencies:
|
|
121
121
|
- 1
|
122
122
|
- 2
|
123
123
|
version: 2.1.2
|
124
|
-
version_requirements: *id007
|
125
124
|
name: uuidtools
|
126
125
|
prerelease: false
|
127
126
|
type: :development
|
127
|
+
requirement: *id007
|
128
128
|
description: This gem provides a simple interface to fluidinfo, built on top of the rest-client gem.
|
129
129
|
email: gridaphobe@gmail.com
|
130
130
|
executables: []
|