omeka_client 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -5
- data/lib/omeka_client.rb +2 -0
- data/lib/omeka_client/client.rb +31 -1
- data/lib/omeka_client/omeka-item.rb +63 -0
- data/lib/omeka_client/version.rb +1 -1
- data/test/{omekaclient_test.rb → client_test.rb} +18 -6
- data/test/omeka-item_test.rb +78 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ff4f2bddc2555b7645ff60265bf425785d5ea97
|
4
|
+
data.tar.gz: d6333149ed0684f15812558ca5941b57dc0a8bf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5c3269e51e86f0d63044227ad2de0e103691703733624246abd630bc7e5d971cc587db22f99ddc5b67292b6ab885029a1c9ddff8d6d30903381a0981df5b5f3
|
7
|
+
data.tar.gz: 7143ea1c58405c9c0ff7bd5a214da4004008b178e87ce67b9a3925e91a983c4f88cde103f17d2f6ed3e8e80ebea586bf4a88541a80eb3627a1f5134273f8dd38
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Omeka Client
|
2
2
|
|
3
3
|
A REST client for [Omeka][], using the API introduced in Omeka 2.1.
|
4
4
|
|
@@ -28,10 +28,29 @@ First, load the gem in your script:
|
|
28
28
|
|
29
29
|
Next, create a client to interact with your Omeka site. You'll need your endpoint and, optionally, an API key.
|
30
30
|
|
31
|
-
client = OmekaClient::Client.new(http://localhost/omeka/api, "api_key")
|
31
|
+
client = OmekaClient::Client.new("http://localhost/omeka/api", "api_key")
|
32
32
|
# => #<OmekaClient::Client:0x007f4307937aa0>
|
33
33
|
|
34
|
-
You can use the convenience methods for easy access to data.
|
34
|
+
You can use the convenience methods for easy access to data. The most useful methods return classes that represent OmekaItems.
|
35
|
+
|
36
|
+
item = client.omeka_items(1)
|
37
|
+
item.id
|
38
|
+
# => 1
|
39
|
+
item.public
|
40
|
+
# => true
|
41
|
+
item.dublin_core.title
|
42
|
+
# => "Questions of the Soul"
|
43
|
+
item.dublin_core.author
|
44
|
+
# => "Hecker, Isaac Thomas, 1819-1888."
|
45
|
+
item.item_type
|
46
|
+
# => "book"
|
47
|
+
item.item_type_metadata.binding
|
48
|
+
# => "cloth"
|
49
|
+
|
50
|
+
item = client.omeka_items
|
51
|
+
# returns array of OmekaItem instances
|
52
|
+
|
53
|
+
There are some helper methods to get other results in other forms:
|
35
54
|
|
36
55
|
site_info = client.site
|
37
56
|
puts site_info['title']
|
@@ -43,7 +62,7 @@ You can use the convenience methods for easy access to data.
|
|
43
62
|
puts items[0]['url']
|
44
63
|
# => http://localhost/omeka/api/items/1
|
45
64
|
|
46
|
-
If you want more flexibility, you can use the
|
65
|
+
If you want more flexibility about what you're requesting, you can use the lower-level methods.
|
47
66
|
|
48
67
|
client.get('collections', 1)
|
49
68
|
|
@@ -61,7 +80,7 @@ You can generate the documentation by running `rake yard`.
|
|
61
80
|
|
62
81
|
## Future plans
|
63
82
|
|
64
|
-
For now the gem only handles GET requests. I'm going to work on making methods that pull information out of Omeka as robust as possible before I deal with POST, PUT, and DELETE. Contributions are more than welcome.
|
83
|
+
For now the gem only handles GET requests. I'm going to work on making methods that pull information out of Omeka as robust as possible before I deal with POST, PUT, and DELETE. In particular, the class representations of Omeka items are important. Contributions are more than welcome.
|
65
84
|
|
66
85
|
## License
|
67
86
|
|
data/lib/omeka_client.rb
CHANGED
@@ -2,12 +2,14 @@ require "rest"
|
|
2
2
|
require "json"
|
3
3
|
require "omeka_client/version"
|
4
4
|
require "omeka_client/client"
|
5
|
+
require "omeka_client/omeka-item"
|
5
6
|
|
6
7
|
|
7
8
|
#
|
8
9
|
# The module wrapping the classes that do the work
|
9
10
|
#
|
10
11
|
# @author Lincoln Mullen
|
12
|
+
# @since 0.0.1
|
11
13
|
#
|
12
14
|
module OmekaClient
|
13
15
|
|
data/lib/omeka_client/client.rb
CHANGED
@@ -35,6 +35,7 @@ module OmekaClient
|
|
35
35
|
# @param query [Hash] Additional query parameters
|
36
36
|
#
|
37
37
|
# @return [NetHttpPersistentResponseWrapper] A wrapper around the object
|
38
|
+
# @since 0.0.1
|
38
39
|
def get(resource, id = nil, query = {} )
|
39
40
|
url = self.endpoint + "/" + resource
|
40
41
|
url += "/" + id.to_s unless id.nil?
|
@@ -51,6 +52,7 @@ module OmekaClient
|
|
51
52
|
#
|
52
53
|
# @return [Array or Hash] A hash of the representation of the object,
|
53
54
|
# or an array of hashes.
|
55
|
+
# @since 0.0.1
|
54
56
|
def get_hash(resource, id = nil, query = {} )
|
55
57
|
response = self.get(resource, id, query)
|
56
58
|
if response.code == 200
|
@@ -63,6 +65,31 @@ module OmekaClient
|
|
63
65
|
# TODO: put
|
64
66
|
# TODO: delete
|
65
67
|
|
68
|
+
# Methods that return classes
|
69
|
+
# -------------------------------------------------------------------
|
70
|
+
|
71
|
+
#
|
72
|
+
# Get an array or a single Omeka item represented as an OmekaItem class
|
73
|
+
# @param id [Integer] The ID of the item to return. No value gets an
|
74
|
+
# array of all the items.
|
75
|
+
# @param query = {} [Hash] Additional query parameters
|
76
|
+
# @since 0.0.2
|
77
|
+
#
|
78
|
+
# @return [OmekaItem] An OmekaItem representation of the desired item,
|
79
|
+
# or an array of OmekaItems
|
80
|
+
def omeka_items(id = nil, query = {} )
|
81
|
+
response = self.get_hash('items', id = id, query = query)
|
82
|
+
if id.nil?
|
83
|
+
items = Array.new
|
84
|
+
response.each do |item_hash|
|
85
|
+
items.push OmekaItem.new(item_hash)
|
86
|
+
end
|
87
|
+
return items
|
88
|
+
else
|
89
|
+
OmekaItem.new(response)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
66
93
|
# Convenience methods
|
67
94
|
# -------------------------------------------------------------------
|
68
95
|
|
@@ -74,8 +101,9 @@ module OmekaClient
|
|
74
101
|
end
|
75
102
|
|
76
103
|
# Get a list of the resources available from the Omeka API
|
77
|
-
#
|
104
|
+
#
|
78
105
|
# @return [Hash] Returns a hash of the resources available via the API
|
106
|
+
# @since 0.0.1
|
79
107
|
def resources
|
80
108
|
self.get_hash('resources')
|
81
109
|
end
|
@@ -85,6 +113,7 @@ module OmekaClient
|
|
85
113
|
# TODO: Check that items are available in the resources
|
86
114
|
#
|
87
115
|
# @return [Array] Returns an array of item hashes
|
116
|
+
# @since 0.0.1
|
88
117
|
def items
|
89
118
|
self.get_hash('items')
|
90
119
|
end
|
@@ -94,6 +123,7 @@ module OmekaClient
|
|
94
123
|
# TODO: Check that items are available in the resources
|
95
124
|
#
|
96
125
|
# @return [Array] Returns an array of collection hashes
|
126
|
+
# @since 0.0.1
|
97
127
|
def collections
|
98
128
|
self.get_hash('collections')
|
99
129
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
|
3
|
+
module OmekaClient
|
4
|
+
|
5
|
+
#
|
6
|
+
# A class to represent an item in an Omeka site
|
7
|
+
#
|
8
|
+
# @author Lincoln Mullen
|
9
|
+
# @since 0.0.2
|
10
|
+
#
|
11
|
+
class OmekaItem
|
12
|
+
|
13
|
+
# Instance variables for each of the main parts of the metadata
|
14
|
+
attr_accessor :id, :url, :public, :featured, :added, :modified, \
|
15
|
+
:item_type, :collection, :owner, :files, :tags, :dublin_core, \
|
16
|
+
:item_type_metadata, :extended_resources
|
17
|
+
|
18
|
+
#
|
19
|
+
# Parse the data we got from the API into handy methods
|
20
|
+
# @param hash [Hash] Uses the hash from OmekaClient::Client::get_hash
|
21
|
+
#
|
22
|
+
def initialize(hash)
|
23
|
+
|
24
|
+
# Some of these values have strings. Others return arrays or hashes.
|
25
|
+
@id = hash['id']
|
26
|
+
@url = hash['url']
|
27
|
+
@public = hash['public']
|
28
|
+
@featured = hash['featured']
|
29
|
+
@added = hash['added']
|
30
|
+
@modified = hash['modified']
|
31
|
+
@item_type = hash['item_type']
|
32
|
+
@collection = hash['collection']
|
33
|
+
@owner = hash['owner']
|
34
|
+
@files = hash['files']
|
35
|
+
@tags = hash['tags']
|
36
|
+
@extended_resources = ['extended_resources']
|
37
|
+
|
38
|
+
# OpenStruct.new requires a hash of method names and methods values,
|
39
|
+
# which we construct here for Dublin Core and for the Item Type
|
40
|
+
# Metadata. The downside is that we are discarding some data.
|
41
|
+
# Element names become method names: "Lesson Plan" to "lesson_plan"
|
42
|
+
dc_metadata = Hash.new
|
43
|
+
item_metadata = Hash.new
|
44
|
+
hash['element_texts'].each do |e|
|
45
|
+
if e['element_set']['name'] == "Dublin Core"
|
46
|
+
method_name = e['element']['name'].downcase.gsub(/\s/, '_')
|
47
|
+
dc_metadata[method_name] = e['text']
|
48
|
+
elsif e['element_set']['name'] == "Item Type Metadata"
|
49
|
+
method_name = e['element']['name'].downcase.gsub(/\s/, '_')
|
50
|
+
item_metadata[method_name] = e['text']
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# The OpenStruct will provide methods of the style
|
55
|
+
# item.dublin_core.title
|
56
|
+
@dublin_core = OpenStruct.new(dc_metadata)
|
57
|
+
@item_type_metadata = OpenStruct.new(item_metadata)
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/lib/omeka_client/version.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require "minitest/autorun"
|
2
2
|
require "omeka_client"
|
3
3
|
|
4
|
-
# Set up an test client
|
5
|
-
test_endpoint = "http://localhost/omeka-2.1-rc1/api"
|
6
|
-
test_api_key = "c56c8f542bc98483b71896523d4faa6321de193b"
|
7
|
-
resources = ["items", "collections"]
|
8
|
-
client = OmekaClient::Client.new(test_endpoint, test_api_key)
|
9
|
-
|
10
4
|
describe OmekaClient::Client do
|
11
5
|
|
6
|
+
# Setup a test client
|
7
|
+
test_endpoint = "http://localhost/omeka-2.1-rc1/api"
|
8
|
+
test_api_key = "c56c8f542bc98483b71896523d4faa6321de193b"
|
9
|
+
resources = ["items", "collections"]
|
10
|
+
client = OmekaClient::Client.new(test_endpoint, test_api_key)
|
11
|
+
|
12
12
|
it "must have an endpoint" do
|
13
13
|
client.endpoint.must_equal test_endpoint
|
14
14
|
end
|
@@ -67,4 +67,16 @@ describe OmekaClient::Client do
|
|
67
67
|
client.collections.wont_be_empty
|
68
68
|
end
|
69
69
|
|
70
|
+
it "must return an OmekaItem class" do
|
71
|
+
puts client.omeka_items(1).must_be_instance_of OmekaClient::OmekaItem
|
72
|
+
end
|
73
|
+
|
74
|
+
it "must return an array of OmekaItem classes" do
|
75
|
+
puts client.omeka_items.must_be_instance_of Array
|
76
|
+
[0,1].each do |number|
|
77
|
+
puts client.omeka_items[number].must_be_instance_of \
|
78
|
+
OmekaClient::OmekaItem
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
70
82
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "omeka_client"
|
3
|
+
|
4
|
+
# Set up an test client
|
5
|
+
test_endpoint = "http://localhost/omeka-2.1-rc1/api"
|
6
|
+
test_api_key = "c56c8f542bc98483b71896523d4faa6321de193b"
|
7
|
+
resources = ["items", "collections"]
|
8
|
+
client = OmekaClient::Client.new(test_endpoint, test_api_key)
|
9
|
+
# item_array = client.omeka_items
|
10
|
+
item_single = client.omeka_items(1)
|
11
|
+
|
12
|
+
|
13
|
+
describe OmekaClient::OmekaItem do
|
14
|
+
|
15
|
+
it "should have an ID" do
|
16
|
+
item_single.id.must_equal 1
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have a URL" do
|
20
|
+
item_single.url.must_be_instance_of String
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have a URL" do
|
24
|
+
item_single.url.must_be_instance_of String
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should know whether it's public" do
|
28
|
+
item_single.public.wont_be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should know whether it's featured" do
|
32
|
+
item_single.featured.wont_be_nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have a date added" do
|
36
|
+
item_single.added.must_be_instance_of String
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should have a date modified" do
|
40
|
+
item_single.modified.must_be_instance_of String
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should have an item type" do
|
44
|
+
item_single.item_type.must_be_instance_of Hash
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should have a collection" do
|
48
|
+
item_single.collection.must_be_instance_of Hash
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should have files" do
|
52
|
+
item_single.files.must_be_instance_of Hash
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should have tags" do
|
56
|
+
item_single.tags.must_be_instance_of Array
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should have extended resources" do
|
60
|
+
item_single.extended_resources.must_be_instance_of Array
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should have the Dublin Core metadata" do
|
64
|
+
item_single.dublin_core.must_be_instance_of OpenStruct
|
65
|
+
dc_fields = [:title, :subject, :contributor, :description, :creator, \
|
66
|
+
:source, :publisher, :date, :rights, :relation, :format, :language, \
|
67
|
+
:type, :identifier, :coverage]
|
68
|
+
dc_fields.each do |field|
|
69
|
+
item_single.dublin_core.send(field).must_be_instance_of String
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should have the Item Type metadata" do
|
74
|
+
item_single.item_type_metadata.must_be_instance_of OpenStruct
|
75
|
+
# The item type is unpredictable, so it's hard to be more specific
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
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.2
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,9 +94,11 @@ files:
|
|
94
94
|
- Rakefile
|
95
95
|
- lib/omeka_client.rb
|
96
96
|
- lib/omeka_client/client.rb
|
97
|
+
- lib/omeka_client/omeka-item.rb
|
97
98
|
- lib/omeka_client/version.rb
|
98
99
|
- omeka_client.gemspec
|
99
|
-
- test/
|
100
|
+
- test/client_test.rb
|
101
|
+
- test/omeka-item_test.rb
|
100
102
|
homepage: https://github.com/lmullen/omeka_client
|
101
103
|
licenses:
|
102
104
|
- GPLv3
|
@@ -122,5 +124,6 @@ signing_key:
|
|
122
124
|
specification_version: 4
|
123
125
|
summary: A REST client to access the Omeka API
|
124
126
|
test_files:
|
125
|
-
- test/
|
127
|
+
- test/client_test.rb
|
128
|
+
- test/omeka-item_test.rb
|
126
129
|
has_rdoc:
|