embedly-rb 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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Guardfile +10 -0
- data/LICENSE.md +20 -0
- data/README.md +41 -0
- data/Rakefile +10 -0
- data/embedly.gemspec +30 -0
- data/lib/embedly.rb +18 -0
- data/lib/embedly/configuration.rb +9 -0
- data/lib/embedly/oembed.rb +71 -0
- data/lib/embedly/version.rb +3 -0
- data/spec/embedly/configuration_spec.rb +16 -0
- data/spec/embedly/embedly_spec.rb +17 -0
- data/spec/endpoints/oembed_spec.rb +45 -0
- data/spec/fixtures/vimeo.com.json +1 -0
- data/spec/spec_helper.rb +2 -0
- metadata +165 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
guard 'bundler' do
|
2
|
+
watch('Gemfile')
|
3
|
+
watch(/^.+\.gemspec/)
|
4
|
+
end
|
5
|
+
|
6
|
+
guard 'rspec', :version => 2, :cli => '-c -f d -p' do
|
7
|
+
watch(%r{^spec/.+_spec\.rb$})
|
8
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
9
|
+
watch('spec/spec_helper.rb') { "spec" }
|
10
|
+
end
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Felipe Elias Philipp
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# The embedly-rb gem
|
2
|
+
|
3
|
+
embedly-rb is wrapper for the Embed.ly API
|
4
|
+
|
5
|
+
## Disclaimer
|
6
|
+
|
7
|
+
This gem is currently on development. Only use it if you know what you're doing
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
gem install embedly-rb
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
# configure you key
|
16
|
+
Embedly.configure do |config|
|
17
|
+
config.key = 'my_key'
|
18
|
+
end
|
19
|
+
|
20
|
+
# choose an endpoint
|
21
|
+
api = Embedly::Oembed.new :url => 'http://vimeo.com/18150336'
|
22
|
+
|
23
|
+
# retrieve from embedly
|
24
|
+
api.title
|
25
|
+
# => "Wingsuit Basejumping - The Need 4 Speed: The Art of Flight"
|
26
|
+
|
27
|
+
# is it a video type?
|
28
|
+
api.video?
|
29
|
+
# => true
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
bundle install
|
34
|
+
rake
|
35
|
+
|
36
|
+
Make a fork and send me a pull request
|
37
|
+
|
38
|
+
## Copyright
|
39
|
+
|
40
|
+
Copyright (c) 2011 Felipe Elias Philipp.
|
41
|
+
See [LICENSE](https://github.com/felipeelias/embedly-rb/blob/master/LICENSE.md) for details.
|
data/Rakefile
ADDED
data/embedly.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "embedly/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "embedly-rb"
|
7
|
+
s.version = Embedly::VERSION
|
8
|
+
|
9
|
+
s.authors = ["Felipe Elias Philipp"]
|
10
|
+
s.email = ["felipeelias@gmail.com"]
|
11
|
+
|
12
|
+
s.homepage = "https://github.com/felipeelias/embedly-rb"
|
13
|
+
s.summary = %q{A Ruby wrapper for the Embed.ly API}
|
14
|
+
s.description = %q{A Ruby wrapper for the Embed.ly API}
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_dependency 'hashie', '~> 1.1.0'
|
21
|
+
s.add_dependency 'faraday', '~> 0.7.4'
|
22
|
+
s.add_dependency 'faraday_middleware', '~> 0.7.0'
|
23
|
+
s.add_dependency 'multi_json', '~> 1.0.0'
|
24
|
+
|
25
|
+
s.add_development_dependency "rspec"
|
26
|
+
s.add_development_dependency "guard-rspec"
|
27
|
+
s.add_development_dependency "guard-bundler"
|
28
|
+
s.add_development_dependency "growl"
|
29
|
+
s.add_development_dependency "webmock"
|
30
|
+
end
|
data/lib/embedly.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "embedly/version"
|
2
|
+
require "embedly/configuration"
|
3
|
+
require "embedly/oembed"
|
4
|
+
|
5
|
+
module Embedly
|
6
|
+
|
7
|
+
class MissingKeyError < StandardError; end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def configuration
|
11
|
+
@configuration ||= Embedly::Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def configure
|
15
|
+
yield configuration
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "faraday_middleware"
|
2
|
+
|
3
|
+
module Embedly
|
4
|
+
|
5
|
+
API_URL = 'http://api.embed.ly'
|
6
|
+
|
7
|
+
class Oembed
|
8
|
+
|
9
|
+
ENDPOINT_URL = '/1/oembed'
|
10
|
+
|
11
|
+
ATTRIBUTES = [
|
12
|
+
:provider_url,
|
13
|
+
:description,
|
14
|
+
:title,
|
15
|
+
:author_name,
|
16
|
+
:height,
|
17
|
+
:width,
|
18
|
+
:html,
|
19
|
+
:thumbnail_width,
|
20
|
+
:version,
|
21
|
+
:provider_name,
|
22
|
+
:thumbnail_url,
|
23
|
+
:type,
|
24
|
+
:thumbnail_height,
|
25
|
+
:author_url
|
26
|
+
]
|
27
|
+
|
28
|
+
class << self
|
29
|
+
attr_accessor :key
|
30
|
+
end
|
31
|
+
|
32
|
+
attr_accessor :options, :request
|
33
|
+
|
34
|
+
def initialize(options)
|
35
|
+
@options = options
|
36
|
+
end
|
37
|
+
|
38
|
+
def video?
|
39
|
+
true
|
40
|
+
end
|
41
|
+
|
42
|
+
def url
|
43
|
+
options[:url]
|
44
|
+
end
|
45
|
+
|
46
|
+
ATTRIBUTES.each do |attribute|
|
47
|
+
define_method attribute do
|
48
|
+
request.send(attribute) if request.respond_to?(attribute)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def request
|
53
|
+
@request ||= connection.get { |request|
|
54
|
+
request.url ENDPOINT_URL, :url => url, :key => configuration.key
|
55
|
+
}.body
|
56
|
+
end
|
57
|
+
|
58
|
+
def connection
|
59
|
+
Faraday.new API_URL do |builder|
|
60
|
+
builder.use Faraday::Response::Mashify
|
61
|
+
builder.use Faraday::Response::ParseJson
|
62
|
+
builder.adapter :net_http
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def configuration
|
67
|
+
Embedly.configuration
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Embedly::Configuration do
|
4
|
+
describe "#key" do
|
5
|
+
it "sets the key" do
|
6
|
+
subject.key = 'my_key'
|
7
|
+
subject.key.should == 'my_key'
|
8
|
+
end
|
9
|
+
|
10
|
+
it "raises an error if the key wasn't set" do
|
11
|
+
expect {
|
12
|
+
subject.key
|
13
|
+
}.to raise_error(Embedly::MissingKeyError)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Embedly do
|
4
|
+
describe "#configuration" do
|
5
|
+
it "always returns the same object" do
|
6
|
+
Embedly.configuration.should equal(Embedly.configuration)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "configures the object" do
|
10
|
+
Embedly.configure do |config|
|
11
|
+
config.key = 'my_key'
|
12
|
+
end
|
13
|
+
|
14
|
+
Embedly.configuration.key.should == 'my_key'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Embedly::Oembed do
|
4
|
+
let(:key) { 'my_key' }
|
5
|
+
|
6
|
+
before do
|
7
|
+
Embedly.configure do |c|
|
8
|
+
c.key = key
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'fetching a video' do
|
13
|
+
let(:url) { 'http://vimeo.com/18150336' }
|
14
|
+
|
15
|
+
subject { Embedly::Oembed.new :url => url }
|
16
|
+
|
17
|
+
before do
|
18
|
+
stub_oembed url, :fixture => 'vimeo.com'
|
19
|
+
end
|
20
|
+
|
21
|
+
it { should be_video }
|
22
|
+
|
23
|
+
it 'has the provider name' do
|
24
|
+
subject.provider_name.should == 'Vimeo'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'has the provider url' do
|
28
|
+
subject.provider_url.should == 'http://vimeo.com/'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'has description' do
|
32
|
+
subject.description.should =~ /The Need 4 Speed/
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def stub_oembed(url, options)
|
37
|
+
stub_request(:get, "http://api.embed.ly/1/oembed")
|
38
|
+
.with(:query => {'key' => key, 'url' => url})
|
39
|
+
.to_return(:body => fixture(options[:fixture]))
|
40
|
+
end
|
41
|
+
|
42
|
+
def fixture(name)
|
43
|
+
File.new("spec/fixtures/#{name}.json")
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"provider_url": "http://vimeo.com/", "description": "The Need 4 Speed: The Art of Flight A collection of shots from flights made during the 2009-2010 season by the talented group of wingsuit basejumpers, while flying the V3, Hybrid LD2/Trango rigs and testing several new V-series wingsuit prototypes around Europe. Feel the need. The need for speed!", "title": "Wingsuit Basejumping - The Need 4 Speed: The Art of Flight", "author_name": "Phoenix Fly", "height": 720, "width": 1280, "html": "<iframe src=\"http://player.vimeo.com/video/18150336\" width=\"1280\" height=\"720\" frameborder=\"0\"></iframe>", "thumbnail_width": 1280, "version": "1.0", "provider_name": "Vimeo", "thumbnail_url": "http://b.vimeocdn.com/ts/117/311/117311910_1280.jpg", "type": "video", "thumbnail_height": 720, "author_url": "http://vimeo.com/phoenixfly"}
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embedly-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Felipe Elias Philipp
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-25 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: hashie
|
16
|
+
requirement: &70248033677900 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70248033677900
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: faraday
|
27
|
+
requirement: &70248033677400 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.7.4
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70248033677400
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: faraday_middleware
|
38
|
+
requirement: &70248033676940 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.7.0
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70248033676940
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: multi_json
|
49
|
+
requirement: &70248033676480 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70248033676480
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rspec
|
60
|
+
requirement: &70248033676100 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70248033676100
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: &70248033675640 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70248033675640
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: guard-bundler
|
82
|
+
requirement: &70248033705420 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70248033705420
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: growl
|
93
|
+
requirement: &70248033705000 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70248033705000
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: webmock
|
104
|
+
requirement: &70248033704580 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *70248033704580
|
113
|
+
description: A Ruby wrapper for the Embed.ly API
|
114
|
+
email:
|
115
|
+
- felipeelias@gmail.com
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- .gitignore
|
121
|
+
- Gemfile
|
122
|
+
- Guardfile
|
123
|
+
- LICENSE.md
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- embedly.gemspec
|
127
|
+
- lib/embedly.rb
|
128
|
+
- lib/embedly/configuration.rb
|
129
|
+
- lib/embedly/oembed.rb
|
130
|
+
- lib/embedly/version.rb
|
131
|
+
- spec/embedly/configuration_spec.rb
|
132
|
+
- spec/embedly/embedly_spec.rb
|
133
|
+
- spec/endpoints/oembed_spec.rb
|
134
|
+
- spec/fixtures/vimeo.com.json
|
135
|
+
- spec/spec_helper.rb
|
136
|
+
homepage: https://github.com/felipeelias/embedly-rb
|
137
|
+
licenses: []
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ! '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 1.8.8
|
157
|
+
signing_key:
|
158
|
+
specification_version: 3
|
159
|
+
summary: A Ruby wrapper for the Embed.ly API
|
160
|
+
test_files:
|
161
|
+
- spec/embedly/configuration_spec.rb
|
162
|
+
- spec/embedly/embedly_spec.rb
|
163
|
+
- spec/endpoints/oembed_spec.rb
|
164
|
+
- spec/fixtures/vimeo.com.json
|
165
|
+
- spec/spec_helper.rb
|