omeka_client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/lib/omeka_client/client.rb +54 -4
- data/lib/omeka_client/version.rb +1 -1
- data/omeka_client.gemspec +2 -2
- data/test/client_test.rb +30 -8
- data/test/omeka-item_test.rb +0 -1
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad08751ec7991ecc76863bf3f80e24e82e5a34f9
|
4
|
+
data.tar.gz: 65f8d081ee86f044ba6a8da39606a18395da6488
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 836c522e5ffe3984195df0b833ca1a8df3a6f18f7f2f04e184759839e846fffac0c6915b378ce56812bdaa044b6efb242fbec99cbb4b77d94c2d85b66fb724c2
|
7
|
+
data.tar.gz: 877faf52eb48ef0d1cec2765c6c254597c7634c2f13d806602357b8e27abceb0db117e76f524a87288007d79838a488fb1ee5b98019cae93c421fd6fb00b3604
|
data/CHANGELOG.md
ADDED
data/lib/omeka_client/client.rb
CHANGED
@@ -60,10 +60,60 @@ module OmekaClient
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
63
|
+
# Generic POST request to the Omeka site
|
64
|
+
# @param resource [String] The Omeka resource to request, e.g.
|
65
|
+
# "items", "collections"
|
66
|
+
# @param body [String] A string containing a JSON representation of the body of the item
|
67
|
+
# @param query = {} [Hash] Additional query parameters (optional)
|
68
|
+
#
|
69
|
+
# @return [NetHttpPersistentResponseWrapper] A wrapper around the object
|
70
|
+
# @since 0.0.3
|
71
|
+
def post(resource, body = nil, query = {} )
|
72
|
+
url = self.endpoint + "/" + resource
|
73
|
+
query['key'] = self.api_key unless self.api_key.nil?
|
74
|
+
self.connection.post(url, :body => body, :params => query)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Generic DELETE request to the Omeka site
|
78
|
+
# @param resource [String] The type of Omeka resource to delete, e.g.
|
79
|
+
# "items", "collections"
|
80
|
+
# @param id [Integer] The id number of the Omeka resource to delete
|
81
|
+
# @param query = {} [Hash] Additional query parameters
|
82
|
+
#
|
83
|
+
# @return [NetHttpPersistentResponseWrapper] A wrapper around the object
|
84
|
+
# @since 0.0.3
|
85
|
+
def delete(resource, id, query = {} )
|
86
|
+
url = self.endpoint + "/" + resource
|
87
|
+
url += "/" + id.to_s unless id.nil?
|
88
|
+
query[:key] = self.api_key unless self.api_key.nil?
|
89
|
+
|
90
|
+
# The rest gem that provides out functionality has a bug. The Omeka API
|
91
|
+
# returns 204 No Content on DELETE, indicating that the item has been
|
92
|
+
# successfully deleted but that there is no body to return. The rest
|
93
|
+
# gem assumes there will be a body, so it throws a type error. Until
|
94
|
+
# this is fixed, we just rescue the error and don't worry about it.
|
95
|
+
begin
|
96
|
+
self.connection.delete(url, :params => query)
|
97
|
+
rescue TypeError
|
98
|
+
# Not putting the error to stdout
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
# Generic DELETE request to the Omeka site
|
104
|
+
# @param resource [String] The type of Omeka resource to update, e.g.
|
105
|
+
# "items", "collections"
|
106
|
+
# @param id [Integer] The id number of the Omeka resource to update
|
107
|
+
# @param query = {} [Hash] Additional query parameters
|
108
|
+
#
|
109
|
+
# @return [NetHttpPersistentResponseWrapper] A wrapper around the object
|
110
|
+
# @since 0.0.3
|
111
|
+
def put(resource, id, body, query = {} )
|
112
|
+
url = self.endpoint + "/" + resource
|
113
|
+
url += "/" + id.to_s unless id.nil?
|
114
|
+
query[:key] = self.api_key unless self.api_key.nil?
|
115
|
+
self.connection.put(url, :body => body, :params => query)
|
116
|
+
end
|
67
117
|
|
68
118
|
# Methods that return classes
|
69
119
|
# -------------------------------------------------------------------
|
data/lib/omeka_client/version.rb
CHANGED
data/omeka_client.gemspec
CHANGED
@@ -19,9 +19,9 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
-
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.1.0"
|
23
23
|
spec.add_development_dependency "minitest"
|
24
|
-
spec.add_development_dependency "yard"
|
24
|
+
spec.add_development_dependency "yard", "~> 0.8.6.2"
|
25
25
|
|
26
26
|
spec.add_dependency "rest", "~> 2.6.3"
|
27
27
|
end
|
data/test/client_test.rb
CHANGED
@@ -5,9 +5,9 @@ describe OmekaClient::Client do
|
|
5
5
|
|
6
6
|
# Setup a test client
|
7
7
|
test_endpoint = "http://localhost/omeka-2.1-rc1/api"
|
8
|
-
test_api_key
|
9
|
-
resources
|
10
|
-
client
|
8
|
+
test_api_key = "3b036221e180af46bafa4b5e4a1db30e84e78e89" # contributor
|
9
|
+
resources = ["items", "collections"]
|
10
|
+
client = OmekaClient::Client.new(test_endpoint, test_api_key)
|
11
11
|
|
12
12
|
it "must have an endpoint" do
|
13
13
|
client.endpoint.must_equal test_endpoint
|
@@ -68,15 +68,37 @@ describe OmekaClient::Client do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it "must return an OmekaItem class" do
|
71
|
-
|
72
|
-
|
71
|
+
client.omeka_items(1).must_be_instance_of OmekaClient::OmekaItem
|
72
|
+
end
|
73
73
|
|
74
74
|
it "must return an array of OmekaItem classes" do
|
75
|
-
|
75
|
+
client.omeka_items.must_be_instance_of Array
|
76
76
|
[0,1].each do |number|
|
77
|
-
|
78
|
-
|
77
|
+
client.omeka_items[number].must_be_instance_of \
|
78
|
+
OmekaClient::OmekaItem
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
+
it "must be able to POST an item and then DELETE it" do
|
83
|
+
body = '{"public":true,"featured":false,"element_texts":[{"html":false,"text":"Item Added via API","element_set":{"id":1,"url":"http:\/\/localhost\/omeka-2.1-rc1\/api\/element_sets\/1","name":"Dublin Core","resource":"element_sets"},"element":{"id":50,"url":"http:\/\/localhost\/omeka-2.1-rc1\/api\/elements\/50","name":"Title","resource":"elements"}}]}'
|
84
|
+
client.post("items", body).code.must_equal 201
|
85
|
+
id = client.omeka_items.last.id
|
86
|
+
|
87
|
+
# We can't make an assertion yet, because of a bug in the rest gem.
|
88
|
+
client.delete("items", id)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "must be able to update an item via PUT" do
|
92
|
+
body_original = '{"public":true,"featured":false,"element_texts":[{"html":false,"text":"Item Added via API","element_set":{"id":1,"url":"http:\/\/localhost\/omeka-2.1-rc1\/api\/element_sets\/1","name":"Dublin Core","resource":"element_sets"},"element":{"id":50,"url":"http:\/\/localhost\/omeka-2.1-rc1\/api\/elements\/50","name":"Title","resource":"elements"}}]}'
|
93
|
+
body_updated = '{"featured":true,"element_texts":[{"html":false,"text":"Item Updated via API","element_set":{"id":1,"url":"http:\/\/localhost\/omeka-2.1-rc1\/api\/element_sets\/1","name":"Dublin Core","resource":"element_sets"},"element":{"id":50,"url":"http:\/\/localhost\/omeka-2.1-rc1\/api\/elements\/50","name":"Title","resource":"elements"}}]}'
|
94
|
+
client.post("items", body_original)
|
95
|
+
item_original = client.omeka_items.last
|
96
|
+
item_original.dublin_core.title.must_equal "Item Added via API"
|
97
|
+
item_original.featured.must_equal false
|
98
|
+
client.put("items", item_original.id, body_updated).code.must_equal 200
|
99
|
+
item_updated = client.omeka_items(item_original.id)
|
100
|
+
item_updated.dublin_core.title.must_equal "Item Updated via API"
|
101
|
+
item_updated.featured.must_equal true
|
102
|
+
end
|
103
|
+
|
82
104
|
end
|
data/test/omeka-item_test.rb
CHANGED
@@ -4,7 +4,6 @@ require "omeka_client"
|
|
4
4
|
# Set up an test client
|
5
5
|
test_endpoint = "http://localhost/omeka-2.1-rc1/api"
|
6
6
|
test_api_key = "c56c8f542bc98483b71896523d4faa6321de193b"
|
7
|
-
resources = ["items", "collections"]
|
8
7
|
client = OmekaClient::Client.new(test_endpoint, test_api_key)
|
9
8
|
# item_array = client.omeka_items
|
10
9
|
item_single = client.omeka_items(1)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omeka_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lincoln Mullen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 10.1.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 10.1.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: yard
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.8.6.2
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.8.6.2
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rest
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,6 +88,7 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- .gitignore
|
91
|
+
- CHANGELOG.md
|
91
92
|
- Gemfile
|
92
93
|
- LICENSE.txt
|
93
94
|
- README.md
|