audio_vision 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe AudioVision::Asset do
4
+ it 'is a representation of the Asset JSON' do
5
+ asset = AudioVision::Asset.new({
6
+ "title" => "02 - DCFS Night Shift",
7
+ "caption" => "Social worker Gesenia Macias leaves an apartment with two police officers after unsuccessfully trying to find the parents in a reported neglect case. ",
8
+ "owner" => "Grant Slater/KPCC",
9
+ "thumbnail" => {
10
+ "url" => "http://a.scpr.org/i/2ee96431ba36e1985a12c3212db6ee20/71930-lsquare.jpg",
11
+ "width" => 188,
12
+ "height" => 188
13
+ },
14
+ "small" => {
15
+ "url" => "http://a.scpr.org/i/2ee96431ba36e1985a12c3212db6ee20/71930-small.jpg",
16
+ "width" => 450,
17
+ "height" => 300
18
+ },
19
+ "large" => {
20
+ "url" => "http://a.scpr.org/i/2ee96431ba36e1985a12c3212db6ee20/71930-eight.jpg",
21
+ "width" => 729,
22
+ "height" => 486
23
+ },
24
+ "full" => {
25
+ "url" => "http://a.scpr.org/i/2ee96431ba36e1985a12c3212db6ee20/71930-full.jpg",
26
+ "width" => 1024,
27
+ "height" => 682
28
+ }
29
+ })
30
+
31
+ asset.caption.should eq "Social worker Gesenia Macias leaves an apartment with two police officers after unsuccessfully trying to find the parents in a reported neglect case. "
32
+ asset.owner.should eq "Grant Slater/KPCC"
33
+ asset.title.should eq "02 - DCFS Night Shift"
34
+
35
+ asset.thumbnail.should be_a AudioVision::Asset::Size
36
+ asset.small.should be_a AudioVision::Asset::Size
37
+ asset.large.should be_a AudioVision::Asset::Size
38
+ asset.full.should be_a AudioVision::Asset::Size
39
+ end
40
+
41
+
42
+ describe AudioVision::Asset::Size do
43
+ it "is a representation of the asset size JSON" do
44
+ size = AudioVision::Asset::Size.new({
45
+ "url" => "http://a.scpr.org/i/2ee96431ba36e1985a12c3212db6ee20/71930-full.jpg",
46
+ "width" => 1024,
47
+ "height" => 682
48
+ })
49
+
50
+ size.width.should eq 1024
51
+ size.height.should eq 682
52
+ size.url.should eq "http://a.scpr.org/i/2ee96431ba36e1985a12c3212db6ee20/71930-full.jpg"
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe AudioVision::Attribution do
4
+ it "is a representation of the Attribution JSON object" do
5
+ attribution = AudioVision::Attribution.new(
6
+ {
7
+ "name" => "Grant Slater",
8
+ "url" => "http://audiovision.scpr.org/about/grant-slater",
9
+ "role_text" => "Author",
10
+ "role" => 1
11
+ }
12
+ )
13
+
14
+ attribution.name.should eq "Grant Slater"
15
+ attribution.url.should eq "http://audiovision.scpr.org/about/grant-slater"
16
+ attribution.role_text.should eq "Author"
17
+ attribution.role.should eq 1
18
+ end
19
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe AudioVision::Billboard do
4
+ describe '::api_path' do
5
+ it "is the API path for the class" do
6
+ AudioVision::Billboard.api_path.should eq "/api/v1/billboards"
7
+ end
8
+ end
9
+
10
+
11
+ describe '::find' do
12
+ it 'returns the object if it is found' do
13
+ respond_with("billboard1_v1.json", uri: %r|api/v1/billboards|)
14
+
15
+ billboard = AudioVision::Billboard.find(1)
16
+ billboard.should be_a AudioVision::Billboard
17
+ billboard.id.should eq 'billboard-1'
18
+ end
19
+
20
+ it 'is false if nothing is found' do
21
+ respond_with(nil, {
22
+ :uri => %r|api/v1/billboards|,
23
+ :body => { error: "Not Found" },
24
+ :status => 404
25
+ })
26
+
27
+ AudioVision::Billboard.find(999).should eq false
28
+ end
29
+ end
30
+
31
+
32
+ describe '::collection' do
33
+ it "returns an array of objects" do
34
+ respond_with("billboards_v1.json", uri: %r|api/v1/billboards|)
35
+
36
+ billboards = AudioVision::Billboard.collection
37
+ billboards.size.should eq 1
38
+ end
39
+ end
40
+
41
+
42
+ describe '::current' do
43
+ it 'finds the current billboard' do
44
+ respond_with("billboard1_v1.json", uri: %r|api/v1/billboards/current|)
45
+
46
+ billboard = AudioVision::Billboard.current
47
+ billboard.should be_a AudioVision::Billboard
48
+ billboard.id.should eq "billboard-1"
49
+ end
50
+
51
+ it "is nil if nothing found" do
52
+ respond_with(nil, {
53
+ :uri => %r|api/v1/billboards/current|,
54
+ :body => { error: "Not Found" },
55
+ :status => 404
56
+ })
57
+
58
+ AudioVision::Billboard.current.should eq nil
59
+ end
60
+ end
61
+
62
+
63
+ describe 'initialization' do
64
+ it 'makes a new Billboard object' do
65
+ t = Time.now
66
+
67
+ billboard = AudioVision::Billboard.new({
68
+ "id" => "billboard-1",
69
+ "published_at" => t.to_s
70
+ })
71
+
72
+ billboard.id.should eq "billboard-1"
73
+ billboard.published_at.to_s.should eq t.to_s
74
+ billboard.posts.should eq Array.new
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe AudioVision::Bucket do
4
+ describe '::api_path' do
5
+ it "is the API path for the class" do
6
+ AudioVision::Bucket.api_path.should eq "/api/v1/buckets"
7
+ end
8
+ end
9
+
10
+
11
+ describe '::find' do
12
+ it 'returns the object if it is found' do
13
+ respond_with("bucket_v1.json", uri: %r|api/v1/buckets|)
14
+
15
+ bucket = AudioVision::Bucket.find("featured-posts")
16
+ bucket.should be_a AudioVision::Bucket
17
+ bucket.id.should eq 'featured-posts'
18
+ end
19
+
20
+ it 'is false if nothing is found' do
21
+ respond_with(nil, {
22
+ :uri => %r|api/v1/buckets|,
23
+ :body => { error: "Not Found" },
24
+ :status => 404
25
+ })
26
+
27
+ AudioVision::Bucket.find(999).should eq false
28
+ end
29
+ end
30
+
31
+
32
+ describe '::collection' do
33
+ it "returns an array of objects" do
34
+ respond_with("buckets_v1.json", uri: %r|api/v1/buckets|)
35
+
36
+ buckets = AudioVision::Bucket.collection
37
+ buckets.size.should eq 4
38
+ end
39
+ end
40
+
41
+
42
+ describe '::find_by_key' do
43
+ it 'finds the bucket if available' do
44
+ respond_with("bucket_v1.json", uri: %r|api/v1/buckets|)
45
+
46
+ bucket = AudioVision::Bucket.find_by_key('featured-posts')
47
+ bucket.should be_a AudioVision::Bucket
48
+ bucket.id.should eq "featured-posts"
49
+ end
50
+
51
+ it "is false if nothing found" do
52
+ respond_with(nil, {
53
+ :uri => %r|api/v1/buckets|,
54
+ :body => { error: "Not Found" },
55
+ :status => 404
56
+ })
57
+
58
+ AudioVision::Bucket.find_by_key("lolnope").should eq false
59
+ end
60
+ end
61
+
62
+
63
+ describe 'initialization' do
64
+ it 'makes a new Bucket object' do
65
+ bucket = AudioVision::Bucket.new({
66
+ "id" => "featured-posts",
67
+ "updated_at" => Time.now.to_s
68
+ })
69
+
70
+ bucket.id.should eq "featured-posts"
71
+ bucket.posts.should eq Array.new
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe AudioVision::Category do
4
+ it "is a representation of the Category JSON object" do
5
+ category = AudioVision::Category.new(
6
+ {
7
+ "id" => 2,
8
+ "title" => "Images",
9
+ "slug" => "images",
10
+ "description" => "The heartbeat of AudioVision. The best from our team of photojournalists — and discover images from the photographers who inspire them.",
11
+ "public_url" => "http://audiovision.scpr.org/images",
12
+ "permalink" => "http://audiovision.scpr.org/images"
13
+ }
14
+ )
15
+
16
+ category.id.should eq 2
17
+ category.title.should eq "Images"
18
+ category.slug.should eq "images"
19
+ category.description.should eq "The heartbeat of AudioVision. The best from our team of photojournalists — and discover images from the photographers who inspire them."
20
+ category.public_url.should eq "http://audiovision.scpr.org/images"
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe AudioVision::Client do
4
+ describe '#get' do
5
+ it 'fires a GET request to the API' do
6
+ respond_with("post_v1.json", uri: "http://audiovision.scpr.org/api/v1/posts/1")
7
+ client = AudioVision::Client.new
8
+
9
+ response = client.get("posts/1")
10
+ response.should be_a Faraday::Response
11
+ response.body["id"].should eq "post-104"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe AudioVision::Post do
4
+ describe '::api_path' do
5
+ it "is the API path for the class" do
6
+ AudioVision::Post.api_path.should eq "/api/v1/posts"
7
+ end
8
+ end
9
+
10
+
11
+ describe '::find' do
12
+ it 'returns the object if it is found' do
13
+ respond_with("post_v1.json", uri: %r|api/v1/posts|)
14
+
15
+ post = AudioVision::Post.find(104)
16
+ post.should be_a AudioVision::Post
17
+ post.id.should eq 'post-104'
18
+ end
19
+
20
+ it 'is false if nothing is found' do
21
+ respond_with(nil, {
22
+ :uri => %r|api/v1/posts|,
23
+ :body => { error: "Not Found" },
24
+ :status => 404
25
+ })
26
+
27
+ AudioVision::Post.find(999).should eq false
28
+ end
29
+ end
30
+
31
+
32
+ describe '::collection' do
33
+ it "returns an array of objects" do
34
+ respond_with("posts_v1.json", uri: %r|api/v1/posts|)
35
+
36
+ posts = AudioVision::Post.collection
37
+ posts.size.should eq 2
38
+ end
39
+
40
+ it "accepts options" do
41
+ respond_with("posts_images_v1.json", uri: %r|api/v1/posts\?category=images|)
42
+ posts = AudioVision::Post.collection(category: "images")
43
+ posts.first.id.should eq "post-321"
44
+ end
45
+ end
46
+
47
+
48
+ describe '::find_by_url' do
49
+ it "finds the post" do
50
+ respond_with("post_v1.json", uri: %r|api/v1/posts|)
51
+
52
+ post = AudioVision::Post.find_by_url("http://audiovision.scpr.org/posts/104")
53
+ post.should be_a AudioVision::Post
54
+ post.id.should eq "post-104"
55
+ end
56
+
57
+ it "returns nil if no post is found" do
58
+ respond_with(nil, {
59
+ :uri => %r|api/v1/posts|,
60
+ :body => { error: "Not Found" },
61
+ :status => 404
62
+ })
63
+
64
+ post = AudioVision::Post.find_by_url("http://audiovision.scpr.org/posts/104")
65
+ post.should eq nil
66
+ end
67
+ end
68
+
69
+
70
+ describe "initialization" do
71
+ it 'is a Post' do
72
+ post = AudioVision::Post.new({
73
+ "id" => "post-104",
74
+ "published_at" => Time.now.to_s
75
+ })
76
+
77
+ post.id.should eq "post-104"
78
+ post.assets.should eq Array.new
79
+ post.attributions.should be_a Array
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe AudioVision do
4
+ describe '::api_root' do
5
+ it 'is the API root' do
6
+ AudioVision.api_root.should eq "/api/v1"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ require 'bundler/setup'
2
+ Bundler.require
3
+
4
+ SPEC_ROOT = File.dirname(__FILE__)
5
+ FIXTURE_ROOT = File.join SPEC_ROOT, "fixtures"
6
+
7
+ # Require the support files
8
+ Dir["#{SPEC_ROOT}/support/**/*.rb"].each { |f| require f }
9
+
10
+ # Disallow real network connections
11
+ require 'webmock/rspec'
12
+ WebMock.disable_net_connect!
13
+
14
+
15
+ # Configuration
16
+ RSpec.configure do |config|
17
+ config.include FakeResponse
18
+
19
+ config.before do
20
+ WebMock.reset!
21
+ end
22
+ end
@@ -0,0 +1,53 @@
1
+ ##
2
+ # FakeResponse
3
+ #
4
+ # Helpers for faking responses from the API
5
+ #
6
+ module FakeResponse
7
+ DEFAULT_CONTENT_TYPE = "application/json"
8
+ DEFAULT_URI = %r{#{AudioVision::URL}}
9
+
10
+ #---------------------
11
+ # Takes the filename to respond with,
12
+ # and (optionally) any options to be passed to
13
+ # +FakeWeb.register_uri+.
14
+ #
15
+ # If no block is given, the registry will not be cleaned
16
+ # by this method.
17
+ #
18
+ # If passed a block, it will clean the registry after
19
+ # the block has been run.
20
+ #
21
+ def mock_response(filename, options={}, &block)
22
+ respond_with(filename, options)
23
+
24
+ response = yield
25
+ WebMock.reset!
26
+
27
+ response
28
+ end
29
+
30
+ #---------------------
31
+ # Register the root with WebMock, and set its
32
+ # response body to the contents of the requested file.
33
+ def respond_with(filename, options={})
34
+ content_type = options[:content_type] || DEFAULT_CONTENT_TYPE
35
+ uri = options.delete(:uri) || DEFAULT_URI
36
+
37
+ stub_request(:get, uri).to_return(
38
+ {
39
+ :body => load_fixture(filename),
40
+ :content_type => content_type
41
+ }.merge(options)
42
+ )
43
+ end
44
+
45
+ #---------------------
46
+ # Read a fixure file
47
+ def load_fixture(filename)
48
+ return if !filename || filename.empty?
49
+
50
+ file = filename == :random ? random_filename : filename
51
+ File.read(File.join FIXTURE_ROOT, file)
52
+ end
53
+ end # FakeResponse
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: audio_vision
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.rc1
5
+ platform: ruby
6
+ authors:
7
+ - Bryan Ricker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.8
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.8
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Ruby client for the AudioVision API.
98
+ email:
99
+ - bricker@kpcc.org
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - CHANGELOG.md
106
+ - Gemfile
107
+ - MIT-LICENSE
108
+ - README.md
109
+ - Rakefile
110
+ - audio_vision.gemspec
111
+ - lib/audio_vision.rb
112
+ - lib/audio_vision/asset.rb
113
+ - lib/audio_vision/attribution.rb
114
+ - lib/audio_vision/base.rb
115
+ - lib/audio_vision/billboard.rb
116
+ - lib/audio_vision/bucket.rb
117
+ - lib/audio_vision/category.rb
118
+ - lib/audio_vision/client.rb
119
+ - lib/audio_vision/post.rb
120
+ - lib/audio_vision/version.rb
121
+ - spec/fixtures/billboard1_updated_v1.json
122
+ - spec/fixtures/billboard1_v1.json
123
+ - spec/fixtures/billboards_v1.json
124
+ - spec/fixtures/bucket_v1.json
125
+ - spec/fixtures/buckets_v1.json
126
+ - spec/fixtures/post_v1.json
127
+ - spec/fixtures/posts_images_v1.json
128
+ - spec/fixtures/posts_v1.json
129
+ - spec/lib/audio_vision/asset_spec.rb
130
+ - spec/lib/audio_vision/attribution_spec.rb
131
+ - spec/lib/audio_vision/billboard_spec.rb
132
+ - spec/lib/audio_vision/bucket_spec.rb
133
+ - spec/lib/audio_vision/category_spec.rb
134
+ - spec/lib/audio_vision/client_spec.rb
135
+ - spec/lib/audio_vision/post_spec.rb
136
+ - spec/lib/audio_vision_spec.rb
137
+ - spec/spec_helper.rb
138
+ - spec/support/fake_response.rb
139
+ homepage: https://github.com/SCPR/audio_vision-ruby
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - '>'
155
+ - !ruby/object:Gem::Version
156
+ version: 1.3.1
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.0.3
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Ruby client for the AudioVision API.
163
+ test_files:
164
+ - spec/fixtures/billboard1_updated_v1.json
165
+ - spec/fixtures/billboard1_v1.json
166
+ - spec/fixtures/billboards_v1.json
167
+ - spec/fixtures/bucket_v1.json
168
+ - spec/fixtures/buckets_v1.json
169
+ - spec/fixtures/post_v1.json
170
+ - spec/fixtures/posts_images_v1.json
171
+ - spec/fixtures/posts_v1.json
172
+ - spec/lib/audio_vision/asset_spec.rb
173
+ - spec/lib/audio_vision/attribution_spec.rb
174
+ - spec/lib/audio_vision/billboard_spec.rb
175
+ - spec/lib/audio_vision/bucket_spec.rb
176
+ - spec/lib/audio_vision/category_spec.rb
177
+ - spec/lib/audio_vision/client_spec.rb
178
+ - spec/lib/audio_vision/post_spec.rb
179
+ - spec/lib/audio_vision_spec.rb
180
+ - spec/spec_helper.rb
181
+ - spec/support/fake_response.rb
182
+ has_rdoc: