audio_vision 1.0.0.rc1
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 +7 -0
- data/.gitignore +17 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +22 -0
- data/README.md +52 -0
- data/Rakefile +1 -0
- data/audio_vision.gemspec +28 -0
- data/lib/audio_vision.rb +22 -0
- data/lib/audio_vision/asset.rb +40 -0
- data/lib/audio_vision/attribution.rb +18 -0
- data/lib/audio_vision/base.rb +78 -0
- data/lib/audio_vision/billboard.rb +54 -0
- data/lib/audio_vision/bucket.rb +37 -0
- data/lib/audio_vision/category.rb +20 -0
- data/lib/audio_vision/client.rb +34 -0
- data/lib/audio_vision/post.rb +73 -0
- data/lib/audio_vision/version.rb +3 -0
- data/spec/fixtures/billboard1_updated_v1.json +737 -0
- data/spec/fixtures/billboard1_v1.json +1164 -0
- data/spec/fixtures/billboards_v1.json +8 -0
- data/spec/fixtures/bucket_v1.json +1953 -0
- data/spec/fixtures/buckets_v1.json +26 -0
- data/spec/fixtures/post_v1.json +280 -0
- data/spec/fixtures/posts_images_v1.json +407 -0
- data/spec/fixtures/posts_v1.json +466 -0
- data/spec/lib/audio_vision/asset_spec.rb +55 -0
- data/spec/lib/audio_vision/attribution_spec.rb +19 -0
- data/spec/lib/audio_vision/billboard_spec.rb +77 -0
- data/spec/lib/audio_vision/bucket_spec.rb +74 -0
- data/spec/lib/audio_vision/category_spec.rb +22 -0
- data/spec/lib/audio_vision/client_spec.rb +14 -0
- data/spec/lib/audio_vision/post_spec.rb +82 -0
- data/spec/lib/audio_vision_spec.rb +9 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/fake_response.rb +53 -0
- metadata +182 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 65f96343d62472eca34e5f679543b6d94740a9d3
|
4
|
+
data.tar.gz: 83781ab608c3594fbe0afa38aecfd459bf254398
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 53745f097f82206eed4675ff9e4c33be0dde68321cf13bba4a6ade2e110861789cfeb735db3a9e03739c4e30ce56e967c8a469d823f9d31e2e7e9ff9c63489d8
|
7
|
+
data.tar.gz: 76d9377bcaa27b448ad7d9b557823c13deaf43b403bd33877a9ba2b0b9016ae2484911cf76d4a558fd1d77633688b72be1301b83cc59e5871772ab11b47393af
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Bryan Ricker
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# AudioVision
|
2
|
+
|
3
|
+
This is a simple Ruby client for the AudioVision API.
|
4
|
+
Documentation for the AudioVision API can be found
|
5
|
+
[**here**](https://github.com/SCPR/api-docs/tree/master/AudioVision/v1).
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'audio_vision'
|
13
|
+
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
### Posts
|
18
|
+
```ruby
|
19
|
+
# Find by ID
|
20
|
+
AudioVision::Post.find(109)
|
21
|
+
|
22
|
+
# Find by URL
|
23
|
+
AudioVision::Post.find_by_url("http://audiovision.scpr.org/319/public-square-thankful-for")
|
24
|
+
|
25
|
+
# Find Collection - all parameters are passed directly to API
|
26
|
+
AudioVision::Post.collection(limit: 10, query: "Los Angeles", category: "video")
|
27
|
+
```
|
28
|
+
|
29
|
+
### Billboards
|
30
|
+
```ruby
|
31
|
+
# Find by ID
|
32
|
+
AudioVision::Billboard.find(4)
|
33
|
+
|
34
|
+
# Get the current Billboard
|
35
|
+
AudioVision::Billboard.current
|
36
|
+
|
37
|
+
# Get all Billboards
|
38
|
+
AudioVision::Billboard.collection
|
39
|
+
```
|
40
|
+
|
41
|
+
### Buckets
|
42
|
+
```ruby
|
43
|
+
# Find by UUID (key)
|
44
|
+
AudioVision::Billboard.find("featured-posts")
|
45
|
+
|
46
|
+
# Get all Buckets
|
47
|
+
AudioVision::Bucket.collection
|
48
|
+
```
|
49
|
+
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
Fork it, fix it, send a PR. `bundle exec rspec` to run tests.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'audio_vision/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "audio_vision"
|
8
|
+
spec.version = AudioVision::VERSION
|
9
|
+
spec.authors = ["Bryan Ricker"]
|
10
|
+
spec.email = ["bricker@kpcc.org"]
|
11
|
+
spec.description = %q{Ruby client for the AudioVision API.}
|
12
|
+
spec.summary = %q{Ruby client for the AudioVision API.}
|
13
|
+
spec.homepage = "https://github.com/SCPR/audio_vision-ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(spec)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "faraday", "~> 0.8.8"
|
22
|
+
spec.add_dependency "faraday_middleware", "~> 0.9.0"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "webmock"
|
28
|
+
end
|
data/lib/audio_vision.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module AudioVision
|
2
|
+
URL = "http://audiovision.scpr.org"
|
3
|
+
API_ROOT = "/api"
|
4
|
+
API_VERSION = "v1"
|
5
|
+
|
6
|
+
class << self
|
7
|
+
# The API root path for all requests.
|
8
|
+
def api_root
|
9
|
+
@api_root ||= [API_ROOT, API_VERSION].join("/")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'audio_vision/version'
|
15
|
+
require 'audio_vision/client'
|
16
|
+
require 'audio_vision/attribution'
|
17
|
+
require 'audio_vision/category'
|
18
|
+
require 'audio_vision/asset'
|
19
|
+
require 'audio_vision/base'
|
20
|
+
require 'audio_vision/billboard'
|
21
|
+
require 'audio_vision/bucket'
|
22
|
+
require 'audio_vision/post'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module AudioVision
|
2
|
+
class Asset
|
3
|
+
|
4
|
+
class Size
|
5
|
+
attr_accessor :width, :height, :url
|
6
|
+
|
7
|
+
def initialize(attributes={})
|
8
|
+
@width = attributes['width']
|
9
|
+
@height = attributes['height']
|
10
|
+
@url = attributes['url']
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
ATTRIBUTES = [
|
16
|
+
:caption,
|
17
|
+
:owner,
|
18
|
+
:title
|
19
|
+
]
|
20
|
+
|
21
|
+
SIZES = [
|
22
|
+
:thumbnail,
|
23
|
+
:small,
|
24
|
+
:large,
|
25
|
+
:full
|
26
|
+
]
|
27
|
+
|
28
|
+
attr_accessor *(ATTRIBUTES + SIZES)
|
29
|
+
|
30
|
+
def initialize(attributes={})
|
31
|
+
@caption = attributes["caption"]
|
32
|
+
@owner = attributes["owner"]
|
33
|
+
@title = attributes["title"]
|
34
|
+
|
35
|
+
SIZES.each do |size|
|
36
|
+
self.send("#{size}=", Asset::Size.new(attributes[size.to_s]))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module AudioVision
|
2
|
+
class Attribution
|
3
|
+
|
4
|
+
attr_accessor \
|
5
|
+
:name,
|
6
|
+
:url,
|
7
|
+
:role_text,
|
8
|
+
:role
|
9
|
+
|
10
|
+
|
11
|
+
def initialize(attributes={})
|
12
|
+
@name = attributes["name"]
|
13
|
+
@url = attributes["url"]
|
14
|
+
@role_text = attributes["role_text"]
|
15
|
+
@role = attributes["role"]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module AudioVision
|
4
|
+
# This is a private class and shouldn't be used directly.
|
5
|
+
# It acts as a base class for all of the AudioVision classes which
|
6
|
+
# are available in the API.
|
7
|
+
class Base
|
8
|
+
|
9
|
+
class << self
|
10
|
+
# Returns the API path for this class.
|
11
|
+
# Example: /api/v1/posts
|
12
|
+
def api_path
|
13
|
+
@api_path ||= [AudioVision.api_root, self.api_namespace].join("/")
|
14
|
+
end
|
15
|
+
|
16
|
+
# Find an object by its ID.
|
17
|
+
# Returns the object if found, otherwise false.
|
18
|
+
#
|
19
|
+
# Example:
|
20
|
+
# AudioVision::Post.find(10) #=> #<AudioVision::Post>
|
21
|
+
def find(id)
|
22
|
+
response = client.get(endpoint(id))
|
23
|
+
|
24
|
+
if response.success?
|
25
|
+
new(response.body)
|
26
|
+
else
|
27
|
+
false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# Get a collection of posts.
|
33
|
+
# Passed-in parameters are passed directly to the API.
|
34
|
+
# Returns an array of Posts.
|
35
|
+
#
|
36
|
+
# Example:
|
37
|
+
# AudionVision::Post.collection(limit: 5, query: "Photos") #=> [ ... ]
|
38
|
+
def collection(options={})
|
39
|
+
response = client.get(api_path, options)
|
40
|
+
|
41
|
+
if response.success?
|
42
|
+
collection = []
|
43
|
+
|
44
|
+
response.body.each do |json|
|
45
|
+
collection << new(json)
|
46
|
+
end
|
47
|
+
|
48
|
+
collection
|
49
|
+
else
|
50
|
+
[]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def endpoint(*segments)
|
58
|
+
[self.api_namespace, *segments].join("/")
|
59
|
+
end
|
60
|
+
|
61
|
+
def client
|
62
|
+
@client ||= AudioVision::Client.new
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
# Steal the ActiveRecord behavior for object comparison.
|
68
|
+
# If they're the same class and the ID is the same, then it's "same"
|
69
|
+
# enough for us.
|
70
|
+
def ==(comparison_object)
|
71
|
+
super ||
|
72
|
+
comparison_object.instance_of?(self.class) &&
|
73
|
+
self.id && self.id == comparison_object.id
|
74
|
+
end
|
75
|
+
alias :eql? :==
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module AudioVision
|
2
|
+
class Billboard < Base
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def api_namespace
|
6
|
+
:billboards
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
# Get the current Billboard on AudioVision.
|
11
|
+
# Returns a Billboard if success, otherwise nil.
|
12
|
+
#
|
13
|
+
# Example:
|
14
|
+
# AudioVision::Billboard.current #=> #<AudioVision::Billboard>
|
15
|
+
def current
|
16
|
+
response = client.get(endpoint("current"))
|
17
|
+
|
18
|
+
if response.success?
|
19
|
+
new(response.body)
|
20
|
+
else
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
attr_accessor \
|
28
|
+
:id,
|
29
|
+
:layout,
|
30
|
+
:published_at,
|
31
|
+
:updated_at,
|
32
|
+
:posts
|
33
|
+
|
34
|
+
|
35
|
+
def initialize(attributes={})
|
36
|
+
@id = attributes["id"]
|
37
|
+
@layout = attributes["layout"]
|
38
|
+
|
39
|
+
if attributes["published_at"]
|
40
|
+
@published_at = Time.parse(attributes["published_at"].to_s)
|
41
|
+
end
|
42
|
+
|
43
|
+
if attributes["updated_at"]
|
44
|
+
@updated_at = Time.parse(attributes["updated_at"].to_s)
|
45
|
+
end
|
46
|
+
|
47
|
+
@posts = []
|
48
|
+
|
49
|
+
Array(attributes["posts"]).each do |json|
|
50
|
+
@posts << AudioVision::Post.new(json)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module AudioVision
|
2
|
+
class Bucket < Base
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def api_namespace
|
6
|
+
:buckets
|
7
|
+
end
|
8
|
+
|
9
|
+
alias :find_by_key :find
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
attr_accessor \
|
14
|
+
:id,
|
15
|
+
:title,
|
16
|
+
:description,
|
17
|
+
:updated_at,
|
18
|
+
:posts
|
19
|
+
|
20
|
+
|
21
|
+
def initialize(attributes={})
|
22
|
+
@id = attributes["id"]
|
23
|
+
@title = attributes["title"]
|
24
|
+
@description = attributes["description"]
|
25
|
+
|
26
|
+
if attributes["updated_at"]
|
27
|
+
@updated_at = Time.parse(attributes["updated_at"].to_s)
|
28
|
+
end
|
29
|
+
|
30
|
+
@posts = []
|
31
|
+
|
32
|
+
Array(attributes["posts"]).each do |json|
|
33
|
+
@posts << AudioVision::Post.new(json)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module AudioVision
|
2
|
+
class Category
|
3
|
+
|
4
|
+
attr_accessor \
|
5
|
+
:id,
|
6
|
+
:title,
|
7
|
+
:slug,
|
8
|
+
:description,
|
9
|
+
:public_url
|
10
|
+
|
11
|
+
|
12
|
+
def initialize(attributes={})
|
13
|
+
@id = attributes["id"]
|
14
|
+
@title = attributes["title"]
|
15
|
+
@slug = attributes["slug"]
|
16
|
+
@description = attributes["description"]
|
17
|
+
@public_url = attributes["public_url"]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
|
4
|
+
module AudioVision
|
5
|
+
class Client
|
6
|
+
# Get a response from the AudioVision API.
|
7
|
+
# Returns a Faraday Response object.
|
8
|
+
#
|
9
|
+
# Example:
|
10
|
+
# client.get("posts/1")
|
11
|
+
def get(path, params={})
|
12
|
+
connection.get do |request|
|
13
|
+
request.url path
|
14
|
+
request.params = params
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def connection
|
22
|
+
@connection ||= begin
|
23
|
+
Faraday.new(:url => api_root) do |conn|
|
24
|
+
conn.response :json
|
25
|
+
conn.adapter Faraday.default_adapter
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def api_root
|
31
|
+
@api_root ||= AudioVision::URL + AudioVision.api_root
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|