embedly 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/README.rdoc +12 -0
- data/Rakefile +9 -1
- data/VERSION +1 -1
- data/features/command_line.feature +17 -0
- data/features/steps/api_steps.rb +3 -8
- data/features/steps/env.rb +8 -1
- data/lib/embedly.rb +8 -10
- data/lib/embedly/api.rb +8 -9
- data/lib/embedly/command_line.rb +1 -1
- data/lib/embedly/configuration.rb +59 -0
- data/spec/embedly/api_spec.rb +23 -0
- data/spec/embedly/command_line_spec.rb +2 -2
- data/spec/embedly/configuration_spec.rb +57 -0
- data/spec/spec_helper.rb +6 -0
- metadata +32 -17
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -52,6 +52,18 @@ You can find rdocs at http://rubydoc.info/github/embedly/embedly-ruby/master/fra
|
|
52
52
|
obj = embedly_api.preview :url => url
|
53
53
|
puts JSON.pretty_generate(obj[0].marshal_dump)
|
54
54
|
|
55
|
+
== Configuration options
|
56
|
+
|
57
|
+
You can configure some parameters in the api:
|
58
|
+
|
59
|
+
Embedly.configure do |config|
|
60
|
+
# prints debug messages to the logger
|
61
|
+
config.debug = true
|
62
|
+
|
63
|
+
# use a custom logger
|
64
|
+
config.logger = MyAwesomeLogger.new(STDERR)
|
65
|
+
end
|
66
|
+
|
55
67
|
== Testing
|
56
68
|
|
57
69
|
gem install jeweler
|
data/Rakefile
CHANGED
@@ -28,6 +28,12 @@ Jeweler::GemcutterTasks.new
|
|
28
28
|
require 'cucumber/rake/task'
|
29
29
|
Cucumber::Rake::Task.new(:features)
|
30
30
|
|
31
|
+
require "rspec/core/rake_task"
|
32
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
33
|
+
t.rspec_opts = %w[--color]
|
34
|
+
t.verbose = false
|
35
|
+
end
|
36
|
+
|
31
37
|
require 'yard'
|
32
38
|
YARD::Rake::YardocTask.new do |t|
|
33
39
|
t.files = FileList['lib/**/*.rb'].exclude('lib/jeweler/templates/**/*.rb')
|
@@ -43,4 +49,6 @@ Rake::RDocTask.new do |rdoc|
|
|
43
49
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
44
50
|
end
|
45
51
|
|
46
|
-
task :
|
52
|
+
task :all_specs => [:spec, :features]
|
53
|
+
|
54
|
+
task :default => :all_specs
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Feature: Command line runner
|
2
|
+
As an embedly user
|
3
|
+
I want to call the the embedly api via command line
|
4
|
+
|
5
|
+
Scenario: Run oembed command
|
6
|
+
When I run `embedly_oembed http://lockerz.com/s/136425091`
|
7
|
+
Then the output should contain:
|
8
|
+
"""
|
9
|
+
"provider_url": "http://lockerz.com"
|
10
|
+
"""
|
11
|
+
|
12
|
+
Scenario: Run oembed command verbosely
|
13
|
+
When I run `embedly_oembed -v http://lockerz.com/s/136425091`
|
14
|
+
Then the output should contain:
|
15
|
+
"""
|
16
|
+
DEBUG -- : calling http://api.embed.ly/1/oembed
|
17
|
+
"""
|
data/features/steps/api_steps.rb
CHANGED
@@ -8,8 +8,8 @@ Given /an embedly api( with key)?$/ do |key_enabled|
|
|
8
8
|
opts = {}
|
9
9
|
if key_enabled
|
10
10
|
raise 'Please set env variable $EMBEDLY_KEY' unless ENV['EMBEDLY_KEY']
|
11
|
-
opts[:key] = ENV["EMBEDLY_KEY"]
|
12
|
-
opts[:secret] = ENV["EMBEDLY_SECRET"]
|
11
|
+
opts[:key] = ENV["EMBEDLY_KEY"]
|
12
|
+
opts[:secret] = ENV["EMBEDLY_SECRET"]
|
13
13
|
end
|
14
14
|
if not HOSTNAMES[opts]
|
15
15
|
HOSTNAMES[opts] = Embedly::API.new opts
|
@@ -44,18 +44,13 @@ end
|
|
44
44
|
|
45
45
|
Then /([^\s]+) should be (.+)$/ do |key, value|
|
46
46
|
raise @error if @error
|
47
|
-
|
48
|
-
@result.collect do |o|
|
49
|
-
logger.debug { "result: #{o.marshal_dump}"}
|
47
|
+
@result.collect do |o|
|
50
48
|
o.send(key).to_s
|
51
49
|
end.join(',').should == value
|
52
50
|
end
|
53
51
|
|
54
52
|
Then /([^\s]+) should start with ([^\s]+)/ do |key, value|
|
55
53
|
raise @error if @error
|
56
|
-
logger = Embedly.logger('api_steps')
|
57
|
-
logger.debug { "result: #{@result[0].marshal_dump}"}
|
58
54
|
v = key.split('.').inject(@result[0]){|o,c| o.send(c)}.to_s
|
59
55
|
v.to_s.should match(/^#{value}/)
|
60
56
|
end
|
61
|
-
|
data/features/steps/env.rb
CHANGED
data/lib/embedly.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
-
require 'logger'
|
2
|
-
require 'ostruct'
|
3
|
-
|
4
1
|
module Embedly
|
5
2
|
VERSION = File.read(File.expand_path('../../VERSION', __FILE__)).strip
|
6
|
-
Config = OpenStruct.new
|
7
3
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
class << self
|
5
|
+
def configure
|
6
|
+
yield configuration
|
7
|
+
end
|
8
|
+
|
9
|
+
def configuration
|
10
|
+
@configuration ||= Configuration.new
|
11
|
+
end
|
14
12
|
end
|
15
13
|
end
|
16
14
|
|
data/lib/embedly/api.rb
CHANGED
@@ -2,12 +2,12 @@ require 'net/http'
|
|
2
2
|
require 'net/https'
|
3
3
|
require 'json'
|
4
4
|
require 'ostruct'
|
5
|
+
require 'embedly/configuration'
|
5
6
|
require 'embedly/model'
|
6
7
|
require 'embedly/exceptions'
|
7
8
|
require 'querystring'
|
8
9
|
require 'oauth'
|
9
10
|
|
10
|
-
|
11
11
|
# Performs api calls to embedly.
|
12
12
|
#
|
13
13
|
# You won't find methods. We are using method_missing and passing the method
|
@@ -39,10 +39,6 @@ require 'oauth'
|
|
39
39
|
class Embedly::API
|
40
40
|
attr_reader :key, :hostname, :api_version, :headers, :secret
|
41
41
|
|
42
|
-
def logger *args
|
43
|
-
Embedly.logger *args
|
44
|
-
end
|
45
|
-
|
46
42
|
# === Options
|
47
43
|
#
|
48
44
|
# [:+hostname+] Hostname of embedly server. Defaults to api.embed.ly.
|
@@ -72,10 +68,10 @@ class Embedly::API
|
|
72
68
|
|
73
69
|
def _do_oauth_call path
|
74
70
|
consumer = OAuth::Consumer.new(key, secret,
|
75
|
-
:site => site,
|
71
|
+
:site => site,
|
76
72
|
:http_method => :get,
|
77
73
|
:scheme => :query_string)
|
78
|
-
# our implementation is broken for header authorization, thus the
|
74
|
+
# our implementation is broken for header authorization, thus the
|
79
75
|
# query_string
|
80
76
|
|
81
77
|
access_token = OAuth::AccessToken.new consumer
|
@@ -140,7 +136,7 @@ class Embedly::API
|
|
140
136
|
if response.code.to_i == 200
|
141
137
|
logger.debug { response.body }
|
142
138
|
# [].flatten is to be sure we have an array
|
143
|
-
objs = [JSON.parse(response.body)].flatten.collect do |o|
|
139
|
+
objs = [JSON.parse(response.body)].flatten.collect do |o|
|
144
140
|
Embedly::EmbedlyObject.new(o)
|
145
141
|
end
|
146
142
|
else
|
@@ -218,7 +214,10 @@ class Embedly::API
|
|
218
214
|
end
|
219
215
|
|
220
216
|
def logger
|
221
|
-
|
217
|
+
configuration.logger
|
222
218
|
end
|
223
219
|
|
220
|
+
def configuration
|
221
|
+
Embedly.configuration
|
222
|
+
end
|
224
223
|
end
|
data/lib/embedly/command_line.rb
CHANGED
@@ -89,7 +89,7 @@ Usage [OPTIONS] <url> [url] ..
|
|
89
89
|
parser.separator "Common Options:"
|
90
90
|
|
91
91
|
parser.on("-v", "--[no-]verbose", "Run verbosely") do |verbose|
|
92
|
-
Embedly
|
92
|
+
Embedly.configuration.debug = verbose
|
93
93
|
end
|
94
94
|
|
95
95
|
parser.on("-h", "--help", "Display this message") do
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
# Configure the api
|
4
|
+
#
|
5
|
+
# === Available settings
|
6
|
+
#
|
7
|
+
# * [+debug+] Prints debugging information to logger. Default +false+. Errors still will be logged
|
8
|
+
# * [+logger+] Configure the logger; set this if you want to use a custom logger.
|
9
|
+
#
|
10
|
+
# === Usage
|
11
|
+
#
|
12
|
+
# Embedly.configure do |config|
|
13
|
+
# # prints debug messages
|
14
|
+
# config.debug = true
|
15
|
+
#
|
16
|
+
# # customize the logger
|
17
|
+
# config.logger = MyAwesomeLogger.new(STDERR)
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
class Embedly::Configuration
|
21
|
+
attr_accessor :key # :nodoc:
|
22
|
+
|
23
|
+
def initialize # :nodoc:
|
24
|
+
self.reset
|
25
|
+
end
|
26
|
+
|
27
|
+
def debug? # :nodoc:
|
28
|
+
self.logger.debug?
|
29
|
+
end
|
30
|
+
|
31
|
+
def debug=(true_or_false) # :nodoc:
|
32
|
+
set_logger_level(true_or_false)
|
33
|
+
end
|
34
|
+
|
35
|
+
def logger # :nodoc:
|
36
|
+
@logger ||= default_logger
|
37
|
+
end
|
38
|
+
|
39
|
+
def logger=(log) # :nodoc:
|
40
|
+
@logger = log
|
41
|
+
set_logger_level(self.debug?)
|
42
|
+
end
|
43
|
+
|
44
|
+
# reset configuration
|
45
|
+
def reset
|
46
|
+
self.logger = default_logger
|
47
|
+
self.debug = false
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def default_logger # :nodoc:
|
53
|
+
Logger.new(STDERR)
|
54
|
+
end
|
55
|
+
|
56
|
+
def set_logger_level(true_or_false) # :nodoc:
|
57
|
+
logger.level = true_or_false ? Logger::DEBUG : Logger::ERROR
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Embedly
|
4
|
+
describe API do
|
5
|
+
let(:api) { API.new :key => ENV['EMBEDLY_KEY'] }
|
6
|
+
|
7
|
+
describe "logger" do
|
8
|
+
let(:io) { StringIO.new }
|
9
|
+
|
10
|
+
before do
|
11
|
+
Embedly.configure do |c|
|
12
|
+
c.debug = true
|
13
|
+
c.logger = Logger.new(io)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "logs if debug is enabled" do
|
18
|
+
api.oembed :url => 'http://blog.doki-pen.org/'
|
19
|
+
io.string.should =~ %r{DEBUG -- : calling http://api.embed.ly/1/oembed?}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -98,12 +98,12 @@ module Embedly
|
|
98
98
|
describe "with --verbose" do
|
99
99
|
it "enables logging" do
|
100
100
|
command(["--verbose"])
|
101
|
-
Embedly
|
101
|
+
Embedly.configuration.should be_debug
|
102
102
|
end
|
103
103
|
|
104
104
|
it "disables logging" do
|
105
105
|
command(["--no-verbose"])
|
106
|
-
Embedly
|
106
|
+
Embedly.configuration.should_not be_debug
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Embedly
|
4
|
+
describe Configuration do
|
5
|
+
|
6
|
+
let(:config) { Configuration.new }
|
7
|
+
|
8
|
+
describe "debug and logging" do
|
9
|
+
let(:logger) { Logger.new(STDERR) }
|
10
|
+
|
11
|
+
it "has debugger disabled by default" do
|
12
|
+
config.should_not have_debug_enabled
|
13
|
+
end
|
14
|
+
|
15
|
+
it "has default logger level as error" do
|
16
|
+
config.logger.level.should == Logger::ERROR
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can enable debugging" do
|
20
|
+
config.debug = true
|
21
|
+
config.should have_debug_enabled
|
22
|
+
end
|
23
|
+
|
24
|
+
it "can disable debugging" do
|
25
|
+
config.debug = false
|
26
|
+
config.should_not have_debug_enabled
|
27
|
+
end
|
28
|
+
|
29
|
+
it "can change the logger" do
|
30
|
+
config.logger = logger
|
31
|
+
config.logger.should === logger
|
32
|
+
end
|
33
|
+
|
34
|
+
it "sets the logger level for the new logger" do
|
35
|
+
config.debug = true
|
36
|
+
config.logger = logger
|
37
|
+
config.logger.level.should == Logger::DEBUG
|
38
|
+
end
|
39
|
+
|
40
|
+
it "changes the logger level when enable debugging" do
|
41
|
+
config.debug = true
|
42
|
+
config.logger.level.should == Logger::DEBUG
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "setting options" do
|
47
|
+
it "sets the api key" do
|
48
|
+
config.key = 'my_api_key'
|
49
|
+
config.key.should == 'my_api_key'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
RSpec::Matchers.define :have_debug_enabled do
|
56
|
+
match { |actual| actual.debug? }
|
57
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embedly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-12 00:00:00.000000000 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: querystring
|
17
|
-
requirement: &
|
17
|
+
requirement: &69757780 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *69757780
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: oauth
|
28
|
-
requirement: &
|
28
|
+
requirement: &69752680 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *69752680
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: jeweler
|
39
|
-
requirement: &
|
39
|
+
requirement: &69752030 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *69752030
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: cucumber
|
50
|
-
requirement: &
|
50
|
+
requirement: &69751240 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *69751240
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: rake
|
61
|
-
requirement: &
|
61
|
+
requirement: &69750240 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *69750240
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rspec
|
72
|
-
requirement: &
|
72
|
+
requirement: &69749290 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *69749290
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: yard
|
83
|
-
requirement: &
|
83
|
+
requirement: &69748410 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ! '>='
|
@@ -88,7 +88,18 @@ dependencies:
|
|
88
88
|
version: '0'
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *69748410
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: aruba
|
94
|
+
requirement: &69747860 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
type: :development
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: *69747860
|
92
103
|
description: Ruby Embedly client library
|
93
104
|
email: bob@embed.ly
|
94
105
|
executables:
|
@@ -111,6 +122,7 @@ files:
|
|
111
122
|
- bin/embedly_oembed
|
112
123
|
- bin/embedly_preview
|
113
124
|
- cucumber.yml
|
125
|
+
- features/command_line.feature
|
114
126
|
- features/objectify.feature
|
115
127
|
- features/oembed.feature
|
116
128
|
- features/steps/api_steps.rb
|
@@ -118,9 +130,12 @@ files:
|
|
118
130
|
- lib/embedly.rb
|
119
131
|
- lib/embedly/api.rb
|
120
132
|
- lib/embedly/command_line.rb
|
133
|
+
- lib/embedly/configuration.rb
|
121
134
|
- lib/embedly/exceptions.rb
|
122
135
|
- lib/embedly/model.rb
|
136
|
+
- spec/embedly/api_spec.rb
|
123
137
|
- spec/embedly/command_line_spec.rb
|
138
|
+
- spec/embedly/configuration_spec.rb
|
124
139
|
- spec/spec_helper.rb
|
125
140
|
has_rdoc: true
|
126
141
|
homepage: http://github.com/embedly/embedly-ruby
|
@@ -138,7 +153,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
153
|
version: '0'
|
139
154
|
segments:
|
140
155
|
- 0
|
141
|
-
hash:
|
156
|
+
hash: -397755075
|
142
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
158
|
none: false
|
144
159
|
requirements:
|