wistia-api 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/README.rdoc +42 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/wistia.rb +39 -2
- data/lib/wistia/base.rb +10 -4
- data/lib/wistia/media.rb +0 -8
- data/lib/wistia/projects/sharing.rb +18 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/config.test.yml +6 -0
- data/spec/support/local_config.rb +5 -0
- data/spec/wistia/base_spec.rb +28 -0
- data/spec/wistia/projects/sharing_spec.rb +17 -0
- data/spec/wistia_spec.rb +80 -0
- data/wistia-api.gemspec +18 -10
- metadata +16 -8
- data/spec/wistia-api_spec.rb +0 -7
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -4,9 +4,15 @@ Ruby wrapper for Wistia's API
|
|
4
4
|
|
5
5
|
== Installation
|
6
6
|
|
7
|
+
Required gems:
|
8
|
+
* activeresource >= 2.3.8
|
9
|
+
* configatron >= 2.6.4
|
10
|
+
|
7
11
|
gem install wistia-api
|
8
12
|
|
9
|
-
|
13
|
+
RDoc[http://rubydoc.info/gems/wistia-api/0.1.3/frames]
|
14
|
+
|
15
|
+
== Basic Usage
|
10
16
|
|
11
17
|
Start by requiring wistia:
|
12
18
|
require 'wistia'
|
@@ -14,10 +20,44 @@ Start by requiring wistia:
|
|
14
20
|
Configure your API password:
|
15
21
|
Wistia.password = 'your-api-key-here'
|
16
22
|
|
17
|
-
|
23
|
+
You can get an API password by following the instructions here: http://wistia.com/doc/api-enable
|
24
|
+
|
25
|
+
Now you can use the +Wistia::Media+, +Wistia::Project+, and +Wistia::Projects::Sharing+ classes as ActiveResource wrappers around Wistia's API.
|
18
26
|
|
19
27
|
See http://wistia.com/doc/data-api for more info.
|
20
28
|
|
29
|
+
== Configuration Options
|
30
|
+
|
31
|
+
Set the format of the API:
|
32
|
+
Wistia.format = 'json' # This is the default.
|
33
|
+
Wistia.format = 'xml'
|
34
|
+
|
35
|
+
Read configuration from an external YAML file:
|
36
|
+
Wistia.use_config!(path_to_yaml)
|
37
|
+
|
38
|
+
For an example YAML config, see spec/support/config.local.yml
|
39
|
+
|
40
|
+
Configure using a Hash:
|
41
|
+
Wistia.use_config!(:wistia => {
|
42
|
+
:api => {
|
43
|
+
:url => 'custom-api-url',
|
44
|
+
:user => 'custom-api-user',
|
45
|
+
:password => 'your-api-password',
|
46
|
+
:format => 'xml-or-json'
|
47
|
+
}
|
48
|
+
})
|
49
|
+
|
50
|
+
== Examples
|
51
|
+
|
52
|
+
List all Media in your account:
|
53
|
+
Wistia::Media.find(:all)
|
54
|
+
|
55
|
+
List all Projects in your account:
|
56
|
+
Wistia::Project.find(:all)
|
57
|
+
|
58
|
+
List all Sharing objects for project 23:
|
59
|
+
Wistia::Projects::Sharing.find(:all, :params => { :project_id => 23 })
|
60
|
+
|
21
61
|
== Copyright
|
22
62
|
|
23
63
|
Copyright (c) 2011 Wistia, Inc. See LICENSE.txt for
|
data/Rakefile
CHANGED
@@ -23,7 +23,7 @@ Jeweler::Tasks.new do |gem|
|
|
23
23
|
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
24
|
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
25
|
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
-
gem.add_runtime_dependency 'activeresource', '
|
26
|
+
gem.add_runtime_dependency 'activeresource', '>= 2.3.8'
|
27
27
|
gem.add_runtime_dependency 'configatron', '>= 2.6.4'
|
28
28
|
end
|
29
29
|
Jeweler::RubygemsDotOrgTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/wistia.rb
CHANGED
@@ -3,10 +3,47 @@ require 'active_resource'
|
|
3
3
|
require 'wistia/base'
|
4
4
|
require 'wistia/media'
|
5
5
|
require 'wistia/project'
|
6
|
+
require 'wistia/projects/sharing'
|
6
7
|
|
7
8
|
module Wistia
|
9
|
+
|
10
|
+
# Specifies a new configuration to use for the API.
|
11
|
+
# Accepts either a Hash or a String pointing to a YAML configuration file.
|
12
|
+
#
|
13
|
+
# Example using a Hash:
|
14
|
+
# Wistia.use_config!(:wistia => { :api => { :key => 'your-api-key', :format => 'json-or-xml' } })
|
15
|
+
def self.use_config!(config)
|
16
|
+
if config.is_a?(String) && File.exists?(config) && File.extname(config) == '.yml'
|
17
|
+
configatron.configure_from_yaml(config)
|
18
|
+
elsif config.is_a?(Hash)
|
19
|
+
configatron.configure_from_hash(config)
|
20
|
+
else
|
21
|
+
raise ArgumentError, 'Invalid config'
|
22
|
+
end
|
23
|
+
|
24
|
+
refresh_config!
|
25
|
+
end
|
26
|
+
|
27
|
+
# Set your API password using this method.
|
28
|
+
# For instructions to find your API password, go here: http://wistia.com/doc/api-enable
|
8
29
|
def self.password=(pw)
|
9
|
-
|
10
|
-
|
30
|
+
use_config!(:wistia => { :api => { :key => pw } })
|
31
|
+
end
|
32
|
+
|
33
|
+
# Set the format that the API uses to either 'json' or 'xml'.
|
34
|
+
# Accepts either a String or a Symbol.
|
35
|
+
def self.format=(fmt)
|
36
|
+
valid_formats = [ :json, :xml ]
|
37
|
+
raise ArgumentError, "Invalid format. Supported formats: #{valid_formats.join(', ')}." unless valid_formats.include?(fmt.to_sym)
|
38
|
+
use_config!(:wistia => { :api => { :format => fmt.to_sym } })
|
39
|
+
end
|
40
|
+
|
41
|
+
# Force each ActiveResource descendant to re-read its configuration from the configatron.
|
42
|
+
def self.refresh_config!
|
43
|
+
Wistia::Media.refresh_config!
|
44
|
+
Wistia::Project.refresh_config!
|
45
|
+
Wistia::Projects::Sharing.refresh_config!
|
11
46
|
end
|
47
|
+
|
12
48
|
end
|
49
|
+
|
data/lib/wistia/base.rb
CHANGED
@@ -2,10 +2,15 @@ require File.join(File.dirname(__FILE__), 'config')
|
|
2
2
|
|
3
3
|
module Wistia
|
4
4
|
class Base < ActiveResource::Base
|
5
|
-
|
6
|
-
self.
|
7
|
-
|
8
|
-
|
5
|
+
# Resets all the ActiveResource configuration options to what's currently stored in the configatron.
|
6
|
+
def self.refresh_config!
|
7
|
+
self.site = Wistia::Config.config.api.url
|
8
|
+
self.user = Wistia::Config.config.api.user
|
9
|
+
self.password = Wistia::Config.config.api.key
|
10
|
+
self.format = Wistia::Config.config.api.format.to_sym
|
11
|
+
end
|
12
|
+
|
13
|
+
refresh_config!
|
9
14
|
|
10
15
|
def to_json(options = {})
|
11
16
|
return self.attributes.to_json(options)
|
@@ -13,3 +18,4 @@ module Wistia
|
|
13
18
|
|
14
19
|
end
|
15
20
|
end
|
21
|
+
|
data/lib/wistia/media.rb
CHANGED
@@ -13,14 +13,6 @@ module Wistia
|
|
13
13
|
return nil
|
14
14
|
end
|
15
15
|
|
16
|
-
# Needed when deserializing from cache:
|
17
|
-
class Thumbnail < Wistia::Base
|
18
|
-
end # Thumbnail
|
19
|
-
|
20
|
-
# Needed when deserializing from cache:
|
21
|
-
class Asset < Wistia::Base
|
22
|
-
end # Asset
|
23
|
-
|
24
16
|
end # Media
|
25
17
|
end # Wistia
|
26
18
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Wistia
|
2
|
+
module Projects
|
3
|
+
class Sharing < Wistia::Base
|
4
|
+
def self.refresh_config!
|
5
|
+
super
|
6
|
+
self.site = "#{Wistia::Config.config.api.url}projects/:project_id/"
|
7
|
+
end
|
8
|
+
|
9
|
+
refresh_config!
|
10
|
+
|
11
|
+
def to_json(options = {})
|
12
|
+
return self.attributes.to_json(options)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
3
|
require 'rspec'
|
4
|
-
require 'wistia
|
4
|
+
require 'wistia'
|
5
5
|
|
6
6
|
# Requires supporting files with custom matchers and macros, etc,
|
7
7
|
# in ./support/ and its subdirectories.
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Wistia
|
4
|
+
describe Base do
|
5
|
+
describe 'refresh_config!' do
|
6
|
+
it 'sets the "site" public class attribute' do
|
7
|
+
Wistia::Base.should_receive(:site=)
|
8
|
+
Wistia::Base.refresh_config!
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'sets the "user" public class attribute' do
|
12
|
+
Wistia::Base.should_receive(:user=)
|
13
|
+
Wistia::Base.refresh_config!
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'sets the "password" public class attribute' do
|
17
|
+
Wistia::Base.should_receive(:password=)
|
18
|
+
Wistia::Base.refresh_config!
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'sets the "format" public class attribute' do
|
22
|
+
Wistia::Base.should_receive(:format=)
|
23
|
+
Wistia::Base.refresh_config!
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Wistia
|
4
|
+
module Projects
|
5
|
+
describe Sharing do
|
6
|
+
describe 'refresh_config!' do
|
7
|
+
it 'overrides the site value to indicate nesting under projects' do
|
8
|
+
api_url = Wistia::Config.config.api.url
|
9
|
+
Wistia::Projects::Sharing.should_receive(:site=).with(api_url).ordered
|
10
|
+
|
11
|
+
Wistia::Projects::Sharing.should_receive(:site=).with("#{api_url}projects/:project_id/").ordered
|
12
|
+
Wistia::Projects::Sharing.refresh_config!
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/wistia_spec.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Wistia do
|
4
|
+
|
5
|
+
describe 'use_config!' do
|
6
|
+
context 'given a hash argument' do
|
7
|
+
it 'uses the hash to configure configatron' do
|
8
|
+
Wistia.use_config!( :wistia => { :api => { :key => 'test' } } )
|
9
|
+
configatron.wistia.api.key.should == 'test'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'given a path to a yaml file' do
|
14
|
+
it 'makes configatron use the yaml file for configuration' do
|
15
|
+
path_to_yaml = File.dirname(__FILE__) + '/support/config.test.yml'
|
16
|
+
configatron.should_receive(:configure_from_yaml).with(path_to_yaml)
|
17
|
+
Wistia.use_config!(path_to_yaml)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'given an invalid config' do
|
22
|
+
it 'raises an ArgumentError' do
|
23
|
+
lambda {
|
24
|
+
Wistia.use_config!(nil)
|
25
|
+
}.should raise_error(ArgumentError, 'Invalid config')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'uses the new configuration' do
|
30
|
+
Wistia.should_receive(:refresh_config!)
|
31
|
+
Wistia.use_config!( :wistia => { :api => { :key => 'test' } } )
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'password=' do
|
36
|
+
it 'reconfigures the API using the new password parameter' do
|
37
|
+
new_password = 'test'
|
38
|
+
Wistia.password = new_password
|
39
|
+
Wistia.should_receive(:use_config!).with(hash_including(:wistia => { :api => { :key => new_password } }))
|
40
|
+
Wistia.password = new_password
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'format=' do
|
45
|
+
context 'given a valid format' do
|
46
|
+
it 'reconfigures the API using the new format parameter' do
|
47
|
+
new_format = :xml
|
48
|
+
Wistia.should_receive(:use_config!).with(hash_including(:wistia => { :api => { :format => new_format } }))
|
49
|
+
Wistia.format = new_format
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'given an invalid format' do
|
54
|
+
it 'raises an ArgumentError' do
|
55
|
+
lambda {
|
56
|
+
Wistia.format = 'invalid_format'
|
57
|
+
}.should raise_error(ArgumentError, /Invalid format/)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'refresh_config!' do
|
63
|
+
it 'forces Wistia::Media to re-read its configuration from the configatron' do
|
64
|
+
Wistia::Media.should_receive(:refresh_config!)
|
65
|
+
Wistia.refresh_config!
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'forces Wistia::Project to re-read its configuration from the configatron' do
|
69
|
+
Wistia::Project.should_receive(:refresh_config!)
|
70
|
+
Wistia.refresh_config!
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'forces Wistia::Projects::Sharing to re-read its configuration from the configatron' do
|
74
|
+
Wistia::Projects::Sharing.should_receive(:refresh_config!)
|
75
|
+
Wistia.refresh_config!
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
data/wistia-api.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{wistia-api}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jim Bancroft", "Mark Bates"]
|
12
|
-
s.date = %q{2011-01-
|
12
|
+
s.date = %q{2011-01-23}
|
13
13
|
s.description = %q{A ruby library for working with Wistia's data API.}
|
14
14
|
s.email = %q{support@wistia.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,8 +32,13 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/wistia/config.rb",
|
33
33
|
"lib/wistia/media.rb",
|
34
34
|
"lib/wistia/project.rb",
|
35
|
+
"lib/wistia/projects/sharing.rb",
|
35
36
|
"spec/spec_helper.rb",
|
36
|
-
"spec/
|
37
|
+
"spec/support/config.test.yml",
|
38
|
+
"spec/support/local_config.rb",
|
39
|
+
"spec/wistia/base_spec.rb",
|
40
|
+
"spec/wistia/projects/sharing_spec.rb",
|
41
|
+
"spec/wistia_spec.rb",
|
37
42
|
"wistia-api.gemspec"
|
38
43
|
]
|
39
44
|
s.homepage = %q{http://github.com/wistia/wistia-api}
|
@@ -43,7 +48,10 @@ Gem::Specification.new do |s|
|
|
43
48
|
s.summary = %q{Ruby wrapper for Wistia's API}
|
44
49
|
s.test_files = [
|
45
50
|
"spec/spec_helper.rb",
|
46
|
-
"spec/
|
51
|
+
"spec/support/local_config.rb",
|
52
|
+
"spec/wistia/base_spec.rb",
|
53
|
+
"spec/wistia/projects/sharing_spec.rb",
|
54
|
+
"spec/wistia_spec.rb"
|
47
55
|
]
|
48
56
|
|
49
57
|
if s.respond_to? :specification_version then
|
@@ -51,32 +59,32 @@ Gem::Specification.new do |s|
|
|
51
59
|
s.specification_version = 3
|
52
60
|
|
53
61
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
54
|
-
s.add_runtime_dependency(%q<activeresource>, ["
|
62
|
+
s.add_runtime_dependency(%q<activeresource>, [">= 2.3.8"])
|
55
63
|
s.add_runtime_dependency(%q<configatron>, [">= 2.6.4"])
|
56
64
|
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
57
65
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
58
66
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
59
67
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
60
|
-
s.add_runtime_dependency(%q<activeresource>, ["
|
68
|
+
s.add_runtime_dependency(%q<activeresource>, [">= 2.3.8"])
|
61
69
|
s.add_runtime_dependency(%q<configatron>, [">= 2.6.4"])
|
62
70
|
else
|
63
|
-
s.add_dependency(%q<activeresource>, ["
|
71
|
+
s.add_dependency(%q<activeresource>, [">= 2.3.8"])
|
64
72
|
s.add_dependency(%q<configatron>, [">= 2.6.4"])
|
65
73
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
66
74
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
67
75
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
68
76
|
s.add_dependency(%q<rcov>, [">= 0"])
|
69
|
-
s.add_dependency(%q<activeresource>, ["
|
77
|
+
s.add_dependency(%q<activeresource>, [">= 2.3.8"])
|
70
78
|
s.add_dependency(%q<configatron>, [">= 2.6.4"])
|
71
79
|
end
|
72
80
|
else
|
73
|
-
s.add_dependency(%q<activeresource>, ["
|
81
|
+
s.add_dependency(%q<activeresource>, [">= 2.3.8"])
|
74
82
|
s.add_dependency(%q<configatron>, [">= 2.6.4"])
|
75
83
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
76
84
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
77
85
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
78
86
|
s.add_dependency(%q<rcov>, [">= 0"])
|
79
|
-
s.add_dependency(%q<activeresource>, ["
|
87
|
+
s.add_dependency(%q<activeresource>, [">= 2.3.8"])
|
80
88
|
s.add_dependency(%q<configatron>, [">= 2.6.4"])
|
81
89
|
end
|
82
90
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 4
|
9
|
+
version: 0.1.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jim Bancroft
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-23 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -23,7 +23,7 @@ dependencies:
|
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
26
|
-
- - "
|
26
|
+
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
segments:
|
29
29
|
- 2
|
@@ -111,7 +111,7 @@ dependencies:
|
|
111
111
|
requirement: &id007 !ruby/object:Gem::Requirement
|
112
112
|
none: false
|
113
113
|
requirements:
|
114
|
-
- - "
|
114
|
+
- - ">="
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
segments:
|
117
117
|
- 2
|
@@ -161,8 +161,13 @@ files:
|
|
161
161
|
- lib/wistia/config.rb
|
162
162
|
- lib/wistia/media.rb
|
163
163
|
- lib/wistia/project.rb
|
164
|
+
- lib/wistia/projects/sharing.rb
|
164
165
|
- spec/spec_helper.rb
|
165
|
-
- spec/
|
166
|
+
- spec/support/config.test.yml
|
167
|
+
- spec/support/local_config.rb
|
168
|
+
- spec/wistia/base_spec.rb
|
169
|
+
- spec/wistia/projects/sharing_spec.rb
|
170
|
+
- spec/wistia_spec.rb
|
166
171
|
- wistia-api.gemspec
|
167
172
|
has_rdoc: true
|
168
173
|
homepage: http://github.com/wistia/wistia-api
|
@@ -178,7 +183,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
178
183
|
requirements:
|
179
184
|
- - ">="
|
180
185
|
- !ruby/object:Gem::Version
|
181
|
-
hash:
|
186
|
+
hash: 3620978099506273417
|
182
187
|
segments:
|
183
188
|
- 0
|
184
189
|
version: "0"
|
@@ -199,4 +204,7 @@ specification_version: 3
|
|
199
204
|
summary: Ruby wrapper for Wistia's API
|
200
205
|
test_files:
|
201
206
|
- spec/spec_helper.rb
|
202
|
-
- spec/
|
207
|
+
- spec/support/local_config.rb
|
208
|
+
- spec/wistia/base_spec.rb
|
209
|
+
- spec/wistia/projects/sharing_spec.rb
|
210
|
+
- spec/wistia_spec.rb
|