thewalters 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ae269e1906ac9327a4f5bd6577f658e555c485ad
4
+ data.tar.gz: d7e620929b4b14dae693eace2a02ca4aebfc0395
5
+ SHA512:
6
+ metadata.gz: 9da9ad04a2758fa7e17e942a365715d381071e06e8d8e7d5cc44511754a6a63f6c54de7aab2d3327dc1ec41f90361b432a695a7e7be6aa524ae86d3429de0a3b
7
+ data.tar.gz: 38762f5215aa5c187f8ff79f95975426b22e995b2fae65455cad42cef2e17c45b9999c95ee9b1cc8d1af30e1876c5ca66e9dc7b7252633becaf2183ff9cd5578
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ # - 1.8.7
4
+ - 1.9.3
5
+ - 2.0.0
6
+ # - 2.1.0
7
+ script: bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ gem "hashie", ">= 1.2.0"
4
+ gem "faraday", ">= 0.8.1"
5
+ gem "json", ">= 1.7.0"
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0"
12
+ gem "jeweler", "~> 1.8.7"
13
+ gem "mocha", :require => false
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,60 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.3.5)
5
+ builder (3.2.2)
6
+ faraday (0.8.8)
7
+ multipart-post (~> 1.2.0)
8
+ git (1.2.6)
9
+ github_api (0.10.1)
10
+ addressable
11
+ faraday (~> 0.8.1)
12
+ hashie (>= 1.2)
13
+ multi_json (~> 1.4)
14
+ nokogiri (~> 1.5.2)
15
+ oauth2
16
+ hashie (2.0.5)
17
+ highline (1.6.20)
18
+ httpauth (0.2.0)
19
+ jeweler (1.8.8)
20
+ builder
21
+ bundler (~> 1.0)
22
+ git (>= 1.2.5)
23
+ github_api (= 0.10.1)
24
+ highline (>= 1.6.15)
25
+ nokogiri (= 1.5.10)
26
+ rake
27
+ rdoc
28
+ json (1.8.1)
29
+ jwt (0.1.8)
30
+ multi_json (>= 1.5)
31
+ metaclass (0.0.1)
32
+ mocha (0.14.0)
33
+ metaclass (~> 0.0.1)
34
+ multi_json (1.8.2)
35
+ multi_xml (0.5.5)
36
+ multipart-post (1.2.0)
37
+ nokogiri (1.5.10)
38
+ oauth2 (0.9.2)
39
+ faraday (~> 0.8)
40
+ httpauth (~> 0.2)
41
+ jwt (~> 0.1.4)
42
+ multi_json (~> 1.0)
43
+ multi_xml (~> 0.5)
44
+ rack (~> 1.2)
45
+ rack (1.5.2)
46
+ rake (10.1.1)
47
+ rdoc (3.12.2)
48
+ json (~> 1.4)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ bundler (~> 1.0)
55
+ faraday (>= 0.8.1)
56
+ hashie (>= 1.2.0)
57
+ jeweler (~> 1.8.7)
58
+ json (>= 1.7.0)
59
+ mocha
60
+ rdoc (~> 3.12)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Jonathan Julian
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,53 @@
1
+ = thewalters-ruby
2
+
3
+ A Ruby gem for communicating with {The Walters API}[http://api.thewalters.org/help/index].
4
+
5
+ {<img src="https://travis-ci.org/WaltersArtMuseum/thewalters-ruby.png?branch=master" alt="Build Status" />}[https://travis-ci.org/WaltersArtMuseum/thewalters-ruby]
6
+ {<img src="https://gemnasium.com/WaltersArtMuseum/thewalters-ruby.png" alt="Dependency Status" />}[https://gemnasium.com/WaltersArtMuseum/thewalters-ruby]
7
+
8
+ == Install
9
+
10
+ Via rubygems.org:
11
+
12
+ gem install thewalters
13
+
14
+ Via bundler in a Gemfile:
15
+
16
+ gem "thewalters"
17
+
18
+ == Accessing the REST API
19
+
20
+ require 'thewalters'
21
+
22
+ objects = TheWalters::ArtObject.all
23
+ object = TheWalters::ArtObject.find(objects.first.id)
24
+
25
+ +all+ returns an array of ruby objects, each object has all the API attributes on it. +find+ returns
26
+ a single ruby object.
27
+
28
+ See The Walters API at http://api.thewalters.org/help/index for up-to-date documentation.
29
+
30
+ == Contributing to thewalters-ruby
31
+
32
+ This is a very immature project, and I need your help! The goal is to have a fully-featured
33
+ API client available for attendees of {ArtBytes 2014}[http://www.eventbrite.com/e/art-bytes-at-the-walters-tickets-9534980383].
34
+
35
+ === Things that need to be done
36
+ * Add more endpoints
37
+ * Implement parameter passing to the endpoints
38
+ * Add more tests
39
+
40
+ === Do's and Don'ts
41
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
42
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
43
+ * Fork the project.
44
+ * Start a feature/bugfix branch.
45
+ * Commit and push until you are happy with your contribution.
46
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
47
+ * 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.
48
+
49
+ == Copyright
50
+
51
+ Copyright (c) 2014 Jonathan Julian. See LICENSE.txt for
52
+ further details.
53
+
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "thewalters"
18
+ gem.homepage = "http://github.com/WaltersArtMuseum/thewalters-ruby"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A Ruby gem for communicating with The Walters API}
21
+ gem.description = %Q{Easily get object metadata from The Walters API}
22
+ gem.email = "jonathan@jonathanjulian.com"
23
+ gem.authors = ["Jonathan Julian"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'rdoc/task'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "thewalters #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,14 @@
1
+ module TheWalters
2
+ # An ArtObject is known in the Walters API as an "Object"
3
+ class ArtObject < Base
4
+
5
+ # Get the images for this object
6
+ def images
7
+ # TODO
8
+ end
9
+
10
+ private
11
+
12
+ def self.api_path; "objects" end
13
+ end
14
+ end
@@ -0,0 +1,66 @@
1
+ module TheWalters
2
+ # An error accessing the Walters API.
3
+ class ApiError < StandardError; end
4
+
5
+ # A base objet for all endpoints.
6
+ class Base < Hashie::Mash
7
+
8
+ # Get a list of all.
9
+ def self.all(params={})
10
+ get_all(params)
11
+ end
12
+
13
+ # Find a specific item by id.
14
+ def self.find(id)
15
+ get_by_id(id)
16
+ end
17
+
18
+ private
19
+
20
+ def self.get_all(params)
21
+ path = [version, api_path].join("/")
22
+ objects = fetch(path, params)
23
+ objects.map {|o| self.new(o) }
24
+ end
25
+
26
+ def self.get_by_id(id)
27
+ path = [version, api_path, id].join("/")
28
+ object = fetch(path)
29
+ self.new(object)
30
+ end
31
+
32
+ def self.version; "v1" end
33
+ def self.base_url; "http://api.thewalters.org" end
34
+ def self.path
35
+ raise "Path not defined for this class"
36
+ end
37
+
38
+ def self.faraday
39
+ Faraday.new(
40
+ base_url,
41
+ headers: {user_agent: "walters-ruby (Faraday v#{Faraday::VERSION})"}
42
+ ) do |faraday|
43
+ # faraday.response :logger
44
+ faraday.adapter Faraday.default_adapter
45
+ end
46
+ end
47
+
48
+ def self.fetch(path, params={})
49
+ response = faraday.get(path, params)
50
+ # puts "body: #{response.body}"
51
+ if response.headers['content-type'] =~ /json/
52
+ parsed = JSON.parse(response.body)
53
+ if response.success?
54
+ parsed
55
+ else
56
+ details = ": #{parsed['Message'] || parsed['ReturnMessage']}"
57
+ # p parsed['ExceptionMessage']
58
+ raise ApiError.new("#{response.status}#{details}")
59
+ end
60
+ else
61
+ raise ApiError.new("Response is not JSON: #{response.body}")
62
+ end
63
+ end
64
+
65
+ end
66
+ end
@@ -0,0 +1 @@
1
+ require 'thewalters'
data/lib/thewalters.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'json'
2
+ require 'hashie'
3
+ require 'faraday'
4
+ require 'thewalters/base'
5
+ require 'thewalters/art_object'
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 "mocha/setup"
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'thewalters'
16
+
17
+ class Test::Unit::TestCase
18
+ end
data/test/test_base.rb ADDED
@@ -0,0 +1,51 @@
1
+ require 'helper'
2
+
3
+ class BaseTest < Test::Unit::TestCase
4
+ class ExampleObject < TheWalters::Base
5
+ def self.api_path; "foo" end
6
+ end
7
+
8
+ def test_all_returns_objects
9
+ test_faraday = Faraday.new do |builder|
10
+ 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}]' ]}
12
+ end
13
+ end
14
+ ExampleObject.expects(:faraday).returns(test_faraday)
15
+ rows = ExampleObject.all
16
+ assert_equal 3, rows.size
17
+ assert_equal ExampleObject, rows.first.class
18
+ assert_equal 1, rows.first.id
19
+ assert_equal 3, rows.last.id
20
+ end
21
+
22
+ def test_all_with_params_returns_objects
23
+ test_faraday = Faraday.new do |builder|
24
+ builder.adapter :test, Faraday::Adapter::Test::Stubs.new do |stub|
25
+ stub.get('/v1/foo') {[ 200, {"content-type" => "application/json"}, '[{"id": 1},{"id": 2}]' ]}
26
+ end
27
+ end
28
+ ExampleObject.expects(:faraday).returns(test_faraday)
29
+ rows = ExampleObject.all(:pageSize => 2)
30
+ assert_equal 2, rows.size
31
+ assert_equal ExampleObject, rows.first.class
32
+ assert_equal 1, rows.first.id
33
+ assert_equal 2, rows.last.id
34
+ end
35
+
36
+ def test_find_returns_object
37
+ test_faraday = Faraday.new do |builder|
38
+ builder.adapter :test, Faraday::Adapter::Test::Stubs.new do |stub|
39
+ stub.get('/v1/foo/1') {[ 200, {"content-type" => "application/json"}, '{"id": 1}' ]}
40
+ end
41
+ end
42
+ ExampleObject.expects(:faraday).returns(test_faraday)
43
+ row = ExampleObject.find(1)
44
+ assert_equal ExampleObject, row.class
45
+ assert_equal 1, row.id
46
+ end
47
+ end
48
+
49
+
50
+ # Live error response
51
+ # {"Data":null,"ReturnStatus":false,"ReturnCode":200,"ReturnMessage":["An error occurred while executing the command definition. See the inner exception for details."]
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thewalters
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Julian
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashie
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.7.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.7.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '3.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: jeweler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 1.8.7
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 1.8.7
97
+ - !ruby/object:Gem::Dependency
98
+ name: mocha
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Easily get object metadata from The Walters API
112
+ email: jonathan@jonathanjulian.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files:
116
+ - LICENSE.txt
117
+ - README.rdoc
118
+ files:
119
+ - .document
120
+ - .travis.yml
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - LICENSE.txt
124
+ - README.rdoc
125
+ - Rakefile
126
+ - VERSION
127
+ - lib/thewalters-ruby.rb
128
+ - lib/thewalters.rb
129
+ - lib/thewalters/art_object.rb
130
+ - lib/thewalters/base.rb
131
+ - test/helper.rb
132
+ - test/test_base.rb
133
+ homepage: http://github.com/WaltersArtMuseum/thewalters-ruby
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.1.11
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: A Ruby gem for communicating with The Walters API
157
+ test_files: []