viddler-ruby 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +36 -2
- data/lib/viddler/client.rb +4 -1
- data/lib/viddler/version.rb +1 -1
- data/spec/client_spec.rb +9 -3
- data/spec/spec_helper.rb +1 -1
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,39 @@
|
|
1
1
|
viddler-ruby
|
2
2
|
============
|
3
3
|
|
4
|
+
viddler-ruby is the officially supported gem for [Viddler's V2 API](http://developers.viddler.com/documentation/api-v2/).
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
$ gem install viddler-ruby
|
10
|
+
|
11
|
+
### Rails 2
|
12
|
+
|
13
|
+
Add the following to your `config/environment.rb`:
|
14
|
+
|
15
|
+
config.gem 'viddler-ruby'
|
16
|
+
|
17
|
+
Make sure to run `rake gems:install` afterwards.
|
18
|
+
|
19
|
+
### Rails 3 and Bundler
|
20
|
+
|
21
|
+
Add the following to your Gemfile:
|
22
|
+
|
23
|
+
gem 'viddler-ruby'
|
24
|
+
|
25
|
+
Make sure to run `bundle install` afterwards
|
26
|
+
|
27
|
+
### Other
|
28
|
+
|
29
|
+
To use in a regular Ruby project:
|
30
|
+
|
31
|
+
require 'rubygems'
|
32
|
+
require 'viddler-ruby'
|
33
|
+
|
34
|
+
Usage
|
35
|
+
-----
|
36
|
+
|
4
37
|
viddler-ruby provides a simple interface to [Viddler](http://viddler.com)'s API. To use, just instantiate an instance of Viddler::Client and call the `#get` and `#post` methods. For example, to get the details of a video:
|
5
38
|
|
6
39
|
viddler = Viddler::Client.new('your api key')
|
@@ -9,9 +42,10 @@ viddler-ruby provides a simple interface to [Viddler](http://viddler.com)'s API.
|
|
9
42
|
puts video['title'] # => "My video"
|
10
43
|
puts video['id'] # => "abc123"
|
11
44
|
|
12
|
-
For an authenticated client, just
|
45
|
+
For an authenticated client, just call `authenticate!` on the client:
|
13
46
|
|
14
|
-
viddler = Viddler::Client.new('your api key'
|
47
|
+
viddler = Viddler::Client.new('your api key')
|
48
|
+
viddler.authenticate! 'username', 'password'
|
15
49
|
|
16
50
|
Then, any calls made on `viddler` will be done using the correct session id.
|
17
51
|
|
data/lib/viddler/client.rb
CHANGED
@@ -117,6 +117,9 @@ module Viddler
|
|
117
117
|
# Returns a Hash containing the API response.
|
118
118
|
# Raises ApiException if an error is returned from the API
|
119
119
|
def upload(file, arguments)
|
120
|
+
# Call prepareUpload first, to get upload endpoint
|
121
|
+
endpoint = get('viddler.videos.prepareUpload')["upload"]["endpoint"]
|
122
|
+
|
120
123
|
# Need to use OrderedHash, because the API needs the file argument last
|
121
124
|
ordered_arguments = ActiveSupport::OrderedHash.new
|
122
125
|
|
@@ -126,7 +129,7 @@ module Viddler
|
|
126
129
|
ordered_arguments[:sessionid] = sessionid
|
127
130
|
ordered_arguments[:file] = file
|
128
131
|
|
129
|
-
JSON.parse RestClient.post(
|
132
|
+
JSON.parse RestClient.post(endpoint, ordered_arguments)
|
130
133
|
end
|
131
134
|
end
|
132
135
|
end
|
data/lib/viddler/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -120,13 +120,19 @@ describe Viddler::Client, "#upload" do
|
|
120
120
|
before(:each) do
|
121
121
|
@client = Viddler::Client.new('abc123')
|
122
122
|
@file = mock(File)
|
123
|
-
|
124
123
|
@client.sessionid = 'mysess'
|
124
|
+
|
125
125
|
RestClient.stub!(:post).and_return('{"response":["hello","howdy"]}')
|
126
|
+
@client.stub!(:get).and_return({"upload" => {"endpoint" => "http://upload.viddler.com/upload.json"}})
|
127
|
+
end
|
128
|
+
|
129
|
+
it "calls get with viddler.videos.prepareUpload" do
|
130
|
+
@client.should_receive(:get).with('viddler.videos.prepareUpload')
|
131
|
+
@client.upload @file, :param1 => 'asdf', :param2 => true
|
126
132
|
end
|
127
133
|
|
128
|
-
it "calls RestClient.post with params and file" do
|
129
|
-
RestClient.should_receive(:post).with('http://
|
134
|
+
it "calls RestClient.post with endpoint, params, and file" do
|
135
|
+
RestClient.should_receive(:post).with('http://upload.viddler.com/upload.json', hash_including(:param1 => 'asdf', :param2 => true, :file => @file))
|
130
136
|
@client.upload @file, :param1 => 'asdf', :param2 => true
|
131
137
|
end
|
132
138
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: viddler-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kyle Slattery
|