vimeo_3 0.0.1
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/lib/vimeo_3.rb +41 -0
- data/lib/vimeo_3/connect.rb +128 -0
- metadata +45 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 60d943b1d0303510b25bc43c6d69914ef73b82c4
|
|
4
|
+
data.tar.gz: abaf9a9ed497342c6bd1131bb379640f4c5d1c26
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d4835258e92159fc69f8675a5fdf0d4ce5ed81ba1f8dee30855327b64b5a92fb9365b844ac1ae5025f89ecd8b4dfc44477791279be882cc5a6eba2b9685060a4
|
|
7
|
+
data.tar.gz: 368cb85712f61ef2b5b30fd91a589fc557c90ac1489c92d893aebb01395c4892a3772959e260543c49b2829536deda81e8605ec0079833d803c719cc874f1792
|
data/lib/vimeo_3.rb
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
class Vimeo3
|
|
2
|
+
require 'vimeo_3/connect'
|
|
3
|
+
@clientID
|
|
4
|
+
@clientSecret
|
|
5
|
+
@accessToken
|
|
6
|
+
|
|
7
|
+
# Initializes Vimeo3 Object with parameters
|
|
8
|
+
#
|
|
9
|
+
# @param clientID [String] the Vimeo Client ID
|
|
10
|
+
# @param clientSecret [String] the Vimeo Client Secret
|
|
11
|
+
# @param options [Hash] an options parameter that may have an :accessToken key containing Vimeo's Access Token.
|
|
12
|
+
# @return the object
|
|
13
|
+
# @note to pass an Access Token pass "options" as { :accessToken => 'your_token_here' }.
|
|
14
|
+
def initialize(clientID, clientSecret, options = {})
|
|
15
|
+
@clientID = clientID
|
|
16
|
+
@clientSecret = clientSecret
|
|
17
|
+
@options = options
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Returns Vimeo3 Object's basic parameters
|
|
21
|
+
#
|
|
22
|
+
# @return a Hash with :clientID, :clientSecret and :accessToken
|
|
23
|
+
# @note the returned :accessToken will be set to nil if it was not defined.
|
|
24
|
+
def getValues
|
|
25
|
+
return {
|
|
26
|
+
:clientID => @clientID,
|
|
27
|
+
:clientSecret => @clientSecret,
|
|
28
|
+
:accessToken => @options[:accessToken]
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Asks for UploadForm
|
|
33
|
+
#
|
|
34
|
+
# @param redirectURL [String] The URL to Redirect after Upload Completes
|
|
35
|
+
# @return Upload View
|
|
36
|
+
def getForm(redirectURL)
|
|
37
|
+
vimeoConnection = Connect.new(@clientID, @clientSecret, @options)
|
|
38
|
+
|
|
39
|
+
return vimeoConnection.getTicket(redirectURL)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
class Connect
|
|
5
|
+
# Returns default Connection Parametes
|
|
6
|
+
#
|
|
7
|
+
# @return Hash with :scheme, :host, :port, :method, :query and :headers.
|
|
8
|
+
# @note :headers is an object containing :Accept and :UserAgent
|
|
9
|
+
def requireDefaults
|
|
10
|
+
return {
|
|
11
|
+
:scheme => 'https',
|
|
12
|
+
:host => 'api.vimeo.com',
|
|
13
|
+
:port => 443,
|
|
14
|
+
:method => 'GET',
|
|
15
|
+
:query => '',
|
|
16
|
+
:headers => {
|
|
17
|
+
:Accept => "application/vnd.vimeo.*+json;version=3.2",
|
|
18
|
+
:UserAgent => 'Vimeo3RubyGem/0.0.1'
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Constructor
|
|
24
|
+
#
|
|
25
|
+
# @param [Type] clientID Client ID on Vimeo
|
|
26
|
+
# @param [Type] clientSecret Client Secret on Vimeo
|
|
27
|
+
# @param [Type] options = {} a Hash that may contain a Token. In the future may accept other parameters as well.
|
|
28
|
+
def initialize(clientID, clientSecret, options = {})
|
|
29
|
+
@clientID = clientID
|
|
30
|
+
@clientSecret = clientSecret
|
|
31
|
+
@token = options[:accessToken] if options[:accessToken]
|
|
32
|
+
|
|
33
|
+
@tokenType = "basic"
|
|
34
|
+
@tokenType = "bearer" if options[:accessToken]
|
|
35
|
+
|
|
36
|
+
@redirectURL = options[:redirectURL]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# Get Credentials for connection
|
|
41
|
+
#
|
|
42
|
+
# @return [String] Authentication Token for Header
|
|
43
|
+
def setCredentials
|
|
44
|
+
if @token.blank?
|
|
45
|
+
creds = Base64.strict_encode64("#{@clientID}:#{@clientSecret}")
|
|
46
|
+
return "basic #{creds}"
|
|
47
|
+
else
|
|
48
|
+
return "bearer #{@token}"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# Description of method
|
|
54
|
+
#
|
|
55
|
+
# @return [Type] description of returned object
|
|
56
|
+
def self.authEndpoints
|
|
57
|
+
return {
|
|
58
|
+
:authorization => '/oauth/authorize',
|
|
59
|
+
:accessToken => '/oauth/access_token',
|
|
60
|
+
:clientCredentials => '/oauth/authorize/client'
|
|
61
|
+
};
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Get user's upload quota
|
|
65
|
+
#
|
|
66
|
+
# @param oAuthToken [String] OAuth Token for auth with Vimeo.
|
|
67
|
+
# @param options [Hash] Options Hash, not used yet.
|
|
68
|
+
# @return [Hash] upload_quota segment of Vimeo API's return JSON, converted to Hash.
|
|
69
|
+
def getQuota(oAuthToken, options = {})
|
|
70
|
+
defaults = requireDefaults
|
|
71
|
+
headers = defaults[:headers]
|
|
72
|
+
uri_params = defaults
|
|
73
|
+
headers[:Authorization] = @tokenType+' '+@token
|
|
74
|
+
uri_params[:path] = 'me'
|
|
75
|
+
uri = URI::HTTP.new(uri_params)
|
|
76
|
+
res = Net::HTTP::Get(uri, headers)
|
|
77
|
+
|
|
78
|
+
if res.is_a?(Net::HTTPSuccess)
|
|
79
|
+
body = JSON.parse(res.body)
|
|
80
|
+
|
|
81
|
+
return body[:upload_quota]
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
return false
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def getTicket(redirectURL)
|
|
88
|
+
defaults = requireDefaults
|
|
89
|
+
|
|
90
|
+
headers = defaults[:headers]
|
|
91
|
+
body = {
|
|
92
|
+
:redirect_url => redirectURL
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
uri_params = defaults
|
|
96
|
+
|
|
97
|
+
headers[:Authorization] = @tokenType+' '+@token
|
|
98
|
+
uri_params[:path] = '/me/videos'
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
uri = URI::HTTP.build(uri_params)
|
|
102
|
+
uri.scheme = uri_params[:scheme]
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
req = Net::HTTP::Post.new(uri)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
#req.headers(headers)
|
|
109
|
+
|
|
110
|
+
req.set_form_data(body)
|
|
111
|
+
|
|
112
|
+
req.add_field 'Authorization', headers[:Authorization]
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https') do |http|
|
|
116
|
+
http.request(req)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
if res.is_a?(Net::HTTPSuccess)
|
|
121
|
+
body = JSON.parse(res.body)
|
|
122
|
+
|
|
123
|
+
return body
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
return false
|
|
127
|
+
end
|
|
128
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: vimeo_3
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Fernando Cordeiro
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-02-01 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Vimeo API v3 Integration
|
|
14
|
+
email: fernando@fernandocordeiro.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/vimeo_3.rb
|
|
20
|
+
- lib/vimeo_3/connect.rb
|
|
21
|
+
homepage: http://harmisweb.com.br
|
|
22
|
+
licenses:
|
|
23
|
+
- MIT
|
|
24
|
+
metadata: {}
|
|
25
|
+
post_install_message:
|
|
26
|
+
rdoc_options: []
|
|
27
|
+
require_paths:
|
|
28
|
+
- lib
|
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
requirements: []
|
|
40
|
+
rubyforge_project:
|
|
41
|
+
rubygems_version: 2.4.6
|
|
42
|
+
signing_key:
|
|
43
|
+
specification_version: 4
|
|
44
|
+
summary: Vimeo API v3
|
|
45
|
+
test_files: []
|