thewalters 0.1.0 → 0.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae269e1906ac9327a4f5bd6577f658e555c485ad
4
- data.tar.gz: d7e620929b4b14dae693eace2a02ca4aebfc0395
3
+ metadata.gz: 9c3d6404eaed8587006923b7871440d9204b5722
4
+ data.tar.gz: 172f50a4c1f3e32ce904238113e92681cb0ff97d
5
5
  SHA512:
6
- metadata.gz: 9da9ad04a2758fa7e17e942a365715d381071e06e8d8e7d5cc44511754a6a63f6c54de7aab2d3327dc1ec41f90361b432a695a7e7be6aa524ae86d3429de0a3b
7
- data.tar.gz: 38762f5215aa5c187f8ff79f95975426b22e995b2fae65455cad42cef2e17c45b9999c95ee9b1cc8d1af30e1876c5ca66e9dc7b7252633becaf2183ff9cd5578
6
+ metadata.gz: ab50fcddd98c38f33a2c217d537243cd232e048aea9f2411303b4a456767a68ba202107eb1498e835f8c9c0902df0c6680454cca7638c7b3e0de00a0f4d23912
7
+ data.tar.gz: da8afe64874d3356527a6bb52f3c74be0ba9e25f16f1225c161f7f64643a1b3dcba6a12597974218cadc477d2c7e7ffbe5723b6c3fef8ee16e11ebba29ff70f0
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = thewalters-ruby
2
2
 
3
- A Ruby gem for communicating with {The Walters API}[http://api.thewalters.org/help/index].
3
+ A Ruby gem for communicating with {The Walters API}[http://api.thewalters.org/help/index]. {Documentation}[https://github.com/WaltersArtMuseum/walters-api]
4
4
 
5
5
  {<img src="https://travis-ci.org/WaltersArtMuseum/thewalters-ruby.png?branch=master" alt="Build Status" />}[https://travis-ci.org/WaltersArtMuseum/thewalters-ruby]
6
6
  {<img src="https://gemnasium.com/WaltersArtMuseum/thewalters-ruby.png" alt="Dependency Status" />}[https://gemnasium.com/WaltersArtMuseum/thewalters-ruby]
@@ -33,9 +33,8 @@ This is a very immature project, and I need your help! The goal is to have a ful
33
33
  API client available for attendees of {ArtBytes 2014}[http://www.eventbrite.com/e/art-bytes-at-the-walters-tickets-9534980383].
34
34
 
35
35
  === Things that need to be done
36
- * Add more endpoints
37
- * Implement parameter passing to the endpoints
38
36
  * Add more tests
37
+ * implement objects/:id/images with a first-class image object
39
38
 
40
39
  === Do's and Don'ts
41
40
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.1
@@ -1,7 +1,13 @@
1
1
  module TheWalters
2
- # An ArtObject is known in the Walters API as an "Object"
2
+ # An ArtObject is a piece of art, an artifact or similar item within the
3
+ # Walters collections. It's known in the Walters API as an "Object".
3
4
  class ArtObject < Base
4
5
 
6
+ # Find a specific Object by id.
7
+ def self.find(id)
8
+ get_by_id(id)
9
+ end
10
+
5
11
  # Get the images for this object
6
12
  def images
7
13
  # TODO
@@ -1,6 +1,14 @@
1
1
  module TheWalters
2
2
  # An error accessing the Walters API.
3
3
  class ApiError < StandardError; end
4
+ class NotFound < StandardError; end
5
+
6
+ def self.apikey=(apikey)
7
+ @apikey = apikey
8
+ end
9
+ def self.apikey
10
+ @apikey
11
+ end
4
12
 
5
13
  # A base objet for all endpoints.
6
14
  class Base < Hashie::Mash
@@ -10,25 +18,30 @@ module TheWalters
10
18
  get_all(params)
11
19
  end
12
20
 
13
- # Find a specific item by id.
14
- def self.find(id)
15
- get_by_id(id)
16
- end
17
-
18
21
  private
19
22
 
23
+ # Returns a Hash; "Items" contains the array of items.
20
24
  def self.get_all(params)
21
25
  path = [version, api_path].join("/")
22
- objects = fetch(path, params)
23
- objects.map {|o| self.new(o) }
26
+ result = fetch(path, params)
27
+ result["Items"] = result["Items"].map {|o| self.new(o) }
28
+ result
24
29
  end
25
30
 
26
31
  def self.get_by_id(id)
27
32
  path = [version, api_path, id].join("/")
28
- object = fetch(path)
33
+ result = fetch(path)
34
+ object = result["Data"]
29
35
  self.new(object)
30
36
  end
31
37
 
38
+ def self.get_objects(id, params)
39
+ path = [version, api_path, id, 'objects'].join("/")
40
+ result = fetch(path, params)
41
+ result["Items"] = result["Items"].map {|o| ArtObject.new(o) }
42
+ result
43
+ end
44
+
32
45
  def self.version; "v1" end
33
46
  def self.base_url; "http://api.thewalters.org" end
34
47
  def self.path
@@ -38,7 +51,7 @@ module TheWalters
38
51
  def self.faraday
39
52
  Faraday.new(
40
53
  base_url,
41
- headers: {user_agent: "walters-ruby (Faraday v#{Faraday::VERSION})"}
54
+ headers: {:user_agent => "walters-ruby (Faraday v#{Faraday::VERSION})", :accept => 'application/json'}
42
55
  ) do |faraday|
43
56
  # faraday.response :logger
44
57
  faraday.adapter Faraday.default_adapter
@@ -46,19 +59,27 @@ module TheWalters
46
59
  end
47
60
 
48
61
  def self.fetch(path, params={})
62
+ raise "You must first set your api key: try `TheWalters.apikey = '<mykey>'" if TheWalters.apikey.nil?
63
+ params = {:apikey => TheWalters.apikey}.merge(params)
49
64
  response = faraday.get(path, params)
50
65
  # puts "body: #{response.body}"
51
- if response.headers['content-type'] =~ /json/
52
- parsed = JSON.parse(response.body)
53
- if response.success?
54
- parsed
66
+ if response.success?
67
+ if response.headers['content-type'] =~ /json/
68
+ parsed = JSON.parse(response.body)
55
69
  else
56
- details = ": #{parsed['Message'] || parsed['ReturnMessage']}"
57
- # p parsed['ExceptionMessage']
58
- raise ApiError.new("#{response.status}#{details}")
70
+ raise ApiError.new("Response is not JSON: #{response.body}")
59
71
  end
72
+ elsif response.status == 404
73
+ raise NotFound.new("This resource was not found: #{path}")
60
74
  else
61
- raise ApiError.new("Response is not JSON: #{response.body}")
75
+ if response.headers['content-type'] =~ /json/
76
+ parsed = JSON.parse(response.body)
77
+ # p parsed['ExceptionMessage']
78
+ details = parsed['Message'] || parsed['ReturnMessage']
79
+ else
80
+ details = response.body
81
+ end
82
+ raise ApiError.new("#{response.status}: #{details}")
62
83
  end
63
84
  end
64
85
 
@@ -0,0 +1,15 @@
1
+ module TheWalters
2
+ # A collection is a group of artworks, artifacts, or similar items within
3
+ # the Walters Art Museum. Collections at the Walters are grouped by
4
+ # primarily by culture and sometimes by date.
5
+ class Collection < Base
6
+
7
+ def objects(params)
8
+ TheWalters::Collection.get_objects(self.CollectionID, params)
9
+ end
10
+
11
+ private
12
+
13
+ def self.api_path; "collections" end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module TheWalters
2
+ # An exhibition is an organized presentation and display of a selection
3
+ # of museum objects.
4
+ class Exhibition < Base
5
+
6
+ def objects(params)
7
+ TheWalters::Exhibition.get_objects(self.ExhibitionID, params)
8
+ end
9
+
10
+ private
11
+
12
+ def self.api_path; "exhibitions" end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module TheWalters
2
+ # Geographies are locations on Earth where museum objects have been created
3
+ # or discovered, or locations that an object depicts or mentions.
4
+ class Geography < Base
5
+
6
+ def objects(params)
7
+ TheWalters::Geography.get_objects(self.GeographyID, params)
8
+ end
9
+
10
+ private
11
+
12
+ def self.api_path; "geographies" end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module TheWalters
2
+ # Locations are locations within the Walters Art Museum where the various
3
+ # museum objects are on view. If an object is not on view, it will be
4
+ # associated with a 'not on view' location.
5
+ class Location < Base
6
+
7
+ def objects(params)
8
+ TheWalters::Location.get_objects(self.LocationID, params)
9
+ end
10
+
11
+ private
12
+
13
+ def self.api_path; "museum/locations" end
14
+ end
15
+ end
data/lib/thewalters.rb CHANGED
@@ -3,3 +3,7 @@ require 'hashie'
3
3
  require 'faraday'
4
4
  require 'thewalters/base'
5
5
  require 'thewalters/art_object'
6
+ require 'thewalters/collection'
7
+ require 'thewalters/geography'
8
+ require 'thewalters/exhibition'
9
+ require 'thewalters/location'
data/test/test_base.rb CHANGED
@@ -2,17 +2,21 @@ require 'helper'
2
2
 
3
3
  class BaseTest < Test::Unit::TestCase
4
4
  class ExampleObject < TheWalters::Base
5
+ def self.find(id)
6
+ get_by_id(id)
7
+ end
5
8
  def self.api_path; "foo" end
6
9
  end
7
10
 
8
11
  def test_all_returns_objects
12
+ TheWalters.apikey = 'abc'
9
13
  test_faraday = Faraday.new do |builder|
10
14
  builder.adapter :test, Faraday::Adapter::Test::Stubs.new do |stub|
11
- stub.get('/v1/foo') {[ 200, {"content-type" => "application/json"}, '[{"id": 1},{"id": 2},{"id": 3}]' ]}
15
+ stub.get('/v1/foo') {[ 200, {"content-type" => "application/json"}, '{"Items": [{"id": 1},{"id": 2},{"id": 3}]}' ]}
12
16
  end
13
17
  end
14
18
  ExampleObject.expects(:faraday).returns(test_faraday)
15
- rows = ExampleObject.all
19
+ rows = ExampleObject.all["Items"]
16
20
  assert_equal 3, rows.size
17
21
  assert_equal ExampleObject, rows.first.class
18
22
  assert_equal 1, rows.first.id
@@ -20,13 +24,14 @@ class BaseTest < Test::Unit::TestCase
20
24
  end
21
25
 
22
26
  def test_all_with_params_returns_objects
27
+ TheWalters.apikey = 'abc'
23
28
  test_faraday = Faraday.new do |builder|
24
29
  builder.adapter :test, Faraday::Adapter::Test::Stubs.new do |stub|
25
- stub.get('/v1/foo') {[ 200, {"content-type" => "application/json"}, '[{"id": 1},{"id": 2}]' ]}
30
+ stub.get('/v1/foo') {[ 200, {"content-type" => "application/json"}, '{"Items": [{"id": 1},{"id": 2}]}' ]}
26
31
  end
27
32
  end
28
33
  ExampleObject.expects(:faraday).returns(test_faraday)
29
- rows = ExampleObject.all(:pageSize => 2)
34
+ rows = ExampleObject.all(:pageSize => 2)["Items"]
30
35
  assert_equal 2, rows.size
31
36
  assert_equal ExampleObject, rows.first.class
32
37
  assert_equal 1, rows.first.id
@@ -34,9 +39,10 @@ class BaseTest < Test::Unit::TestCase
34
39
  end
35
40
 
36
41
  def test_find_returns_object
42
+ TheWalters.apikey = 'abc'
37
43
  test_faraday = Faraday.new do |builder|
38
44
  builder.adapter :test, Faraday::Adapter::Test::Stubs.new do |stub|
39
- stub.get('/v1/foo/1') {[ 200, {"content-type" => "application/json"}, '{"id": 1}' ]}
45
+ stub.get('/v1/foo/1') {[ 200, {"content-type" => "application/json"}, '{"Data": {"id": 1}}' ]}
40
46
  end
41
47
  end
42
48
  ExampleObject.expects(:faraday).returns(test_faraday)
@@ -0,0 +1,77 @@
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
+ # stub: thewalters 0.2.1 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "thewalters"
9
+ s.version = "0.2.1"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.authors = ["Jonathan Julian"]
13
+ s.date = "2014-01-19"
14
+ s.description = "Easily get object metadata from The Walters API"
15
+ s.email = "jonathan@jonathanjulian.com"
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".travis.yml",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/thewalters-ruby.rb",
30
+ "lib/thewalters.rb",
31
+ "lib/thewalters/art_object.rb",
32
+ "lib/thewalters/base.rb",
33
+ "lib/thewalters/collection.rb",
34
+ "lib/thewalters/exhibition.rb",
35
+ "lib/thewalters/geography.rb",
36
+ "lib/thewalters/location.rb",
37
+ "test/helper.rb",
38
+ "test/test_base.rb",
39
+ "thewalters.gemspec"
40
+ ]
41
+ s.homepage = "http://github.com/WaltersArtMuseum/thewalters-ruby"
42
+ s.licenses = ["MIT"]
43
+ s.require_paths = ["lib"]
44
+ s.rubygems_version = "2.1.11"
45
+ s.summary = "A Ruby gem for communicating with The Walters API"
46
+
47
+ if s.respond_to? :specification_version then
48
+ s.specification_version = 4
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<hashie>, [">= 1.2.0"])
52
+ s.add_runtime_dependency(%q<faraday>, [">= 0.8.1"])
53
+ s.add_runtime_dependency(%q<json>, [">= 1.7.0"])
54
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
55
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
56
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
57
+ s.add_development_dependency(%q<mocha>, [">= 0"])
58
+ else
59
+ s.add_dependency(%q<hashie>, [">= 1.2.0"])
60
+ s.add_dependency(%q<faraday>, [">= 0.8.1"])
61
+ s.add_dependency(%q<json>, [">= 1.7.0"])
62
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
65
+ s.add_dependency(%q<mocha>, [">= 0"])
66
+ end
67
+ else
68
+ s.add_dependency(%q<hashie>, [">= 1.2.0"])
69
+ s.add_dependency(%q<faraday>, [">= 0.8.1"])
70
+ s.add_dependency(%q<json>, [">= 1.7.0"])
71
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
72
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
73
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
74
+ s.add_dependency(%q<mocha>, [">= 0"])
75
+ end
76
+ end
77
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thewalters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Julian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-01 00:00:00.000000000 Z
11
+ date: 2014-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -128,8 +128,13 @@ files:
128
128
  - lib/thewalters.rb
129
129
  - lib/thewalters/art_object.rb
130
130
  - lib/thewalters/base.rb
131
+ - lib/thewalters/collection.rb
132
+ - lib/thewalters/exhibition.rb
133
+ - lib/thewalters/geography.rb
134
+ - lib/thewalters/location.rb
131
135
  - test/helper.rb
132
136
  - test/test_base.rb
137
+ - thewalters.gemspec
133
138
  homepage: http://github.com/WaltersArtMuseum/thewalters-ruby
134
139
  licenses:
135
140
  - MIT