embedly 0.3.3 → 0.4.0
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/.rvmrc +1 -1
- data/Gemfile +12 -0
- data/README.rdoc +4 -0
- data/Rakefile +28 -37
- data/VERSION +1 -1
- data/bin/embedly_objectify +1 -1
- data/bin/embedly_oembed +1 -1
- data/bin/embedly_preview +1 -1
- data/features/objectify.feature +2 -2
- data/features/oembed.feature +5 -5
- data/lib/embedly/api.rb +21 -32
- metadata +83 -65
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm 1.9.2@embedly
|
1
|
+
rvm 1.9.2@embedly-ruby
|
data/Gemfile
ADDED
data/README.rdoc
CHANGED
@@ -16,6 +16,10 @@ If you would like cutting edge, then you can clone and install HEAD.
|
|
16
16
|
cd embedly-ruby
|
17
17
|
rake install
|
18
18
|
|
19
|
+
== Requirements
|
20
|
+
|
21
|
+
* querystring <https://github/dokipen/querystring>
|
22
|
+
|
19
23
|
== Getting Started
|
20
24
|
|
21
25
|
You can find rdocs at http://rubydoc.info/github/embedly/embedly-ruby/master/frames
|
data/Rakefile
CHANGED
@@ -1,48 +1,37 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require '
|
2
|
+
require 'bundler'
|
3
3
|
|
4
4
|
begin
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
gem.email = "bob@embed.ly"
|
11
|
-
gem.homepage = "http://github.com/embedly/embedly-ruby"
|
12
|
-
gem.authors = ["Bob Corsaro"]
|
13
|
-
gem.add_development_dependency "cucumber", ">= 0"
|
14
|
-
gem.add_development_dependency "jeweler", ">= 0"
|
15
|
-
gem.add_development_dependency "rspec", ">= 0"
|
16
|
-
end
|
17
|
-
Jeweler::GemcutterTasks.new
|
18
|
-
|
19
|
-
rescue LoadError
|
20
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
21
10
|
end
|
22
11
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
rescue LoadError
|
38
|
-
task :yard do
|
39
|
-
abort "Yard is not installed"
|
40
|
-
end
|
12
|
+
require 'rake'
|
13
|
+
require 'jeweler'
|
14
|
+
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
gem.name = "embedly"
|
17
|
+
gem.summary = %Q{Ruby Embedly client library}
|
18
|
+
gem.description = %Q{Ruby Embedly client library}
|
19
|
+
gem.email = "bob@embed.ly"
|
20
|
+
gem.homepage = "http://github.com/embedly/embedly-ruby"
|
21
|
+
gem.authors = ["Bob Corsaro"]
|
22
|
+
gem.license = "MIT"
|
23
|
+
|
24
|
+
# in Gemfile
|
41
25
|
end
|
26
|
+
Jeweler::GemcutterTasks.new
|
42
27
|
|
43
|
-
task
|
28
|
+
require 'cucumber/rake/task'
|
29
|
+
Cucumber::Rake::Task.new(:features)
|
44
30
|
|
45
|
-
|
31
|
+
require 'yard'
|
32
|
+
YARD::Rake::YardocTask.new do |t|
|
33
|
+
t.files = FileList['lib/**/*.rb'].exclude('lib/jeweler/templates/**/*.rb')
|
34
|
+
end
|
46
35
|
|
47
36
|
require 'rake/rdoctask'
|
48
37
|
Rake::RDocTask.new do |rdoc|
|
@@ -53,3 +42,5 @@ Rake::RDocTask.new do |rdoc|
|
|
53
42
|
rdoc.rdoc_files.include('README*')
|
54
43
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
44
|
end
|
45
|
+
|
46
|
+
task :default => :features
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/bin/embedly_objectify
CHANGED
@@ -65,5 +65,5 @@ Embedly::Config.logging = true if options.verbose
|
|
65
65
|
|
66
66
|
options.args[:urls] = ARGV
|
67
67
|
api = Embedly::API.new options.marshal_dump
|
68
|
-
objs = [api.send(action, options.args)].flatten.collect{|o| o.marshal_dump}
|
68
|
+
objs = [api.send(action.to_sym, options.args)].flatten.collect{|o| o.marshal_dump}
|
69
69
|
puts JSON.pretty_generate(objs)
|
data/bin/embedly_oembed
CHANGED
@@ -65,5 +65,5 @@ Embedly::Config.logging = true if options.verbose
|
|
65
65
|
|
66
66
|
options.args[:urls] = ARGV
|
67
67
|
api = Embedly::API.new options.marshal_dump
|
68
|
-
objs = [api.send(action, options.args)].flatten.collect{|o| o.marshal_dump}
|
68
|
+
objs = [api.send(action.to_sym, options.args)].flatten.collect{|o| o.marshal_dump}
|
69
69
|
puts JSON.pretty_generate(objs)
|
data/bin/embedly_preview
CHANGED
@@ -65,5 +65,5 @@ Embedly::Config.logging = true if options.verbose
|
|
65
65
|
|
66
66
|
options.args[:urls] = ARGV
|
67
67
|
api = Embedly::API.new options.marshal_dump
|
68
|
-
objs = [api.send(action, options.args)].flatten.collect{|o| o.marshal_dump}
|
68
|
+
objs = [api.send(action.to_sym, options.args)].flatten.collect{|o| o.marshal_dump}
|
69
69
|
puts JSON.pretty_generate(objs)
|
data/features/objectify.feature
CHANGED
data/features/oembed.feature
CHANGED
@@ -14,7 +14,7 @@ Feature: OEmbed
|
|
14
14
|
| http://www.scribd.com/doc/13994900/Easter | http://www.scribd.com/ |
|
15
15
|
| http://www.scribd.com/doc/28452730/Easter-Cards | http://www.scribd.com/ |
|
16
16
|
| http://www.youtube.com/watch?v=Zk7dDekYej0 | http://www.youtube.com/ |
|
17
|
-
| http://
|
17
|
+
| http://yfrog.com/h7qqespj | http://yfrog.com |
|
18
18
|
|
19
19
|
|
20
20
|
Scenario Outline: Get the types
|
@@ -27,7 +27,7 @@ Feature: OEmbed
|
|
27
27
|
| http://www.scribd.com/doc/13994900/Easter | rich |
|
28
28
|
| http://www.scribd.com/doc/28452730/Easter-Cards | rich |
|
29
29
|
| http://www.youtube.com/watch?v=Zk7dDekYej0 | video |
|
30
|
-
| http://
|
30
|
+
| http://yfrog.com/h7qqespj | photo |
|
31
31
|
|
32
32
|
|
33
33
|
Scenario Outline: Get the provider_url with force flag
|
@@ -48,7 +48,7 @@ Feature: OEmbed
|
|
48
48
|
Examples:
|
49
49
|
| urls | provider_urls |
|
50
50
|
| http://www.scribd.com/doc/13994900/Easter,http://www.scribd.com/doc/28452730/Easter-Cards | http://www.scribd.com/,http://www.scribd.com/ |
|
51
|
-
| http://www.youtube.com/watch?v=Zk7dDekYej0,http://
|
51
|
+
| http://www.youtube.com/watch?v=Zk7dDekYej0,http://yfrog.com/h7qqespj | http://www.youtube.com/,http://yfrog.com |
|
52
52
|
|
53
53
|
|
54
54
|
Scenario Outline: Get the provider_url with pro
|
@@ -87,8 +87,8 @@ Feature: OEmbed
|
|
87
87
|
| urls | errcode | types |
|
88
88
|
| http://www.youtube.com/watch/a/bassd/url,http://www.youtube.com/watch/ldf/asdlfj | 404,404 | error,error |
|
89
89
|
| http://www.scribd.com/doc/lsbsdlfldsf/kl,http://www.scribd.com/doc/zasdf/asdfl | 404,404 | error,error |
|
90
|
-
| http://www.youtube.com/watch/zzzzasdf/kl,http://
|
91
|
-
| http://
|
90
|
+
| http://www.youtube.com/watch/zzzzasdf/kl,http://yfrog.com/h7qqespj | 404, | error,photo |
|
91
|
+
| http://yfrog.com/h7qqespj,http://www.scribd.com/doc/asdfasdfasdf | ,404 | photo,error |
|
92
92
|
|
93
93
|
Scenario Outline: Attempt at non-api service without key
|
94
94
|
Given an embedly endpoint
|
data/lib/embedly/api.rb
CHANGED
@@ -2,6 +2,7 @@ require 'net/http'
|
|
2
2
|
require 'json'
|
3
3
|
require 'ostruct'
|
4
4
|
require 'embedly/model'
|
5
|
+
require 'querystring'
|
5
6
|
|
6
7
|
|
7
8
|
# Performs api calls to embedly.
|
@@ -45,6 +46,7 @@ class Embedly::API
|
|
45
46
|
# [:+key+] Your pro.embed.ly api key.
|
46
47
|
# [:+user_agent+] Your User-Agent header. Defaults to Mozilla/5.0 (compatible; embedly-ruby/VERSION;)
|
47
48
|
def initialize opts={}
|
49
|
+
@endpoints = [:oembed, :objectify, :preview]
|
48
50
|
@key = opts[:key]
|
49
51
|
@api_version = Hash.new('1')
|
50
52
|
@api_version.merge!({:objectify => '2'})
|
@@ -99,12 +101,12 @@ class Embedly::API
|
|
99
101
|
opts.select{|k,_| not [:url, :urls, :action, :version].index k}
|
100
102
|
]
|
101
103
|
|
102
|
-
path = "/#{opts[:version]}/#{opts[:action]}?#{
|
104
|
+
path = "/#{opts[:version]}/#{opts[:action]}?#{QueryString.stringify(params)}"
|
103
105
|
|
104
106
|
logger.debug { "calling #{endpoint}#{path}" }
|
105
107
|
|
106
|
-
|
107
|
-
response = Net::HTTP.start(
|
108
|
+
host, port = uri_parse(endpoint)
|
109
|
+
response = Net::HTTP.start(host, port) do |http|
|
108
110
|
http.get(path, {'User-Agent' => user_agent})
|
109
111
|
end
|
110
112
|
|
@@ -133,14 +135,14 @@ class Embedly::API
|
|
133
135
|
|
134
136
|
# Returns structured data from the services API method.
|
135
137
|
#
|
136
|
-
# Response is cached per API object.
|
138
|
+
# Response is cached per API object.
|
137
139
|
#
|
138
140
|
# see http://api.embed.ly/docs/service for a description of the response.
|
139
141
|
def services
|
140
142
|
logger.warn { "services isn't availble on the pro endpoint" } if key
|
141
143
|
if not @services
|
142
|
-
|
143
|
-
response = Net::HTTP.start(
|
144
|
+
host, port = uri_parse(endpoint)
|
145
|
+
response = Net::HTTP.start(host, port) do |http|
|
144
146
|
http.get('/1/services/ruby', {'User-Agent' => user_agent})
|
145
147
|
end
|
146
148
|
raise 'services call failed', response if response.code.to_i != 200
|
@@ -164,35 +166,22 @@ class Embedly::API
|
|
164
166
|
# - +preview+ _pro-only_
|
165
167
|
#
|
166
168
|
def method_missing(name, *args, &block)
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
169
|
+
if @endpoints.include?name
|
170
|
+
opts = args[0]
|
171
|
+
opts[:action] = name
|
172
|
+
opts[:version] = @api_version[name]
|
173
|
+
apicall opts
|
174
|
+
else
|
175
|
+
super
|
176
|
+
end
|
171
177
|
end
|
172
178
|
|
173
179
|
private
|
174
|
-
def
|
175
|
-
uri
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
# TODO: move to utils
|
180
|
-
def escape s
|
181
|
-
s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/u) do
|
182
|
-
'%'+$1.unpack('H2'*$1.bytesize).join('%').upcase
|
183
|
-
end.tr(' ', '+')
|
184
|
-
end
|
185
|
-
|
186
|
-
# Creates query string
|
187
|
-
# TODO: move to utils
|
188
|
-
def q params
|
189
|
-
params.collect do |k,v|
|
190
|
-
if v.is_a?Array
|
191
|
-
"#{k.to_s}=#{v.collect{|i|escape(i)}.join(',')}"
|
192
|
-
else
|
193
|
-
"#{k.to_s}=#{escape(v)}"
|
194
|
-
end
|
195
|
-
end.join('&')
|
180
|
+
def uri_parse uri
|
181
|
+
uri =~ %r{^(http(s?)://)?([^:/]+)(:([\d]+))?(/.*)?$}
|
182
|
+
host = $3
|
183
|
+
port = $5 ? $5 : ( $2 ? 443 : 80)
|
184
|
+
[host, port.to_i]
|
196
185
|
end
|
197
186
|
|
198
187
|
def logger
|
metadata
CHANGED
@@ -1,75 +1,97 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: embedly
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 3
|
8
|
-
- 3
|
9
|
-
version: 0.3.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Bob Corsaro
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
date: 2011-02-20 00:00:00 -05:00
|
12
|
+
date: 2011-05-20 00:00:00.000000000 -04:00
|
18
13
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: querystring
|
17
|
+
requirement: &68358050 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
22
24
|
prerelease: false
|
23
|
-
|
25
|
+
version_requirements: *68358050
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: jeweler
|
28
|
+
requirement: &68355990 !ruby/object:Gem::Requirement
|
24
29
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *68355990
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: cucumber
|
39
|
+
requirement: &68353970 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
31
45
|
type: :development
|
32
|
-
version_requirements: *id001
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: jeweler
|
35
46
|
prerelease: false
|
36
|
-
|
47
|
+
version_requirements: *68353970
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rake
|
50
|
+
requirement: &68353080 !ruby/object:Gem::Requirement
|
37
51
|
none: false
|
38
|
-
requirements:
|
39
|
-
- -
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
|
42
|
-
- 0
|
43
|
-
version: "0"
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
44
56
|
type: :development
|
45
|
-
|
46
|
-
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *68353080
|
59
|
+
- !ruby/object:Gem::Dependency
|
47
60
|
name: rspec
|
61
|
+
requirement: &68352090 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
type: :development
|
48
68
|
prerelease: false
|
49
|
-
|
69
|
+
version_requirements: *68352090
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: yard
|
72
|
+
requirement: &68319420 !ruby/object:Gem::Requirement
|
50
73
|
none: false
|
51
|
-
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
|
55
|
-
- 0
|
56
|
-
version: "0"
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
57
78
|
type: :development
|
58
|
-
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *68319420
|
59
81
|
description: Ruby Embedly client library
|
60
82
|
email: bob@embed.ly
|
61
|
-
executables:
|
83
|
+
executables:
|
62
84
|
- embedly_objectify
|
63
85
|
- embedly_oembed
|
64
86
|
- embedly_preview
|
65
87
|
extensions: []
|
66
|
-
|
67
|
-
extra_rdoc_files:
|
88
|
+
extra_rdoc_files:
|
68
89
|
- ChangeLog
|
69
90
|
- README.rdoc
|
70
|
-
files:
|
91
|
+
files:
|
71
92
|
- .rvmrc
|
72
93
|
- ChangeLog
|
94
|
+
- Gemfile
|
73
95
|
- MIT-LICENSE
|
74
96
|
- README.rdoc
|
75
97
|
- Rakefile
|
@@ -87,35 +109,31 @@ files:
|
|
87
109
|
- lib/embedly/model.rb
|
88
110
|
has_rdoc: true
|
89
111
|
homepage: http://github.com/embedly/embedly-ruby
|
90
|
-
licenses:
|
91
|
-
|
112
|
+
licenses:
|
113
|
+
- MIT
|
92
114
|
post_install_message:
|
93
115
|
rdoc_options: []
|
94
|
-
|
95
|
-
require_paths:
|
116
|
+
require_paths:
|
96
117
|
- lib
|
97
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
119
|
none: false
|
99
|
-
requirements:
|
100
|
-
- -
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
segments:
|
103
125
|
- 0
|
104
|
-
|
105
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
hash: -471678371
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
128
|
none: false
|
107
|
-
requirements:
|
108
|
-
- -
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
|
111
|
-
- 0
|
112
|
-
version: "0"
|
129
|
+
requirements:
|
130
|
+
- - ! '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
113
133
|
requirements: []
|
114
|
-
|
115
134
|
rubyforge_project:
|
116
|
-
rubygems_version: 1.
|
135
|
+
rubygems_version: 1.6.2
|
117
136
|
signing_key:
|
118
137
|
specification_version: 3
|
119
138
|
summary: Ruby Embedly client library
|
120
139
|
test_files: []
|
121
|
-
|