anideo-embedly 1.3.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.
@@ -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, :typhoeus # :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,20 @@
1
+ class Embedly::BadResponseException < RuntimeError
2
+ attr_accessor :response, :path
3
+
4
+ def initialize(response, path = nil)
5
+ @response ||= response
6
+ @path ||= path
7
+ end
8
+
9
+ def message
10
+ "Bad Response : #{@response.inspect} for path: #{@path.inspect}"
11
+ end
12
+
13
+ def inspect
14
+ self.message
15
+ end
16
+
17
+ def to_s
18
+ self.message
19
+ end
20
+ end
@@ -0,0 +1,32 @@
1
+ require 'ostruct'
2
+
3
+ class Embedly::EmbedlyObject < OpenStruct
4
+
5
+ # Resursively make ostruct
6
+ def initialize obj
7
+ o = obj.clone
8
+ o.each do |k,v|
9
+ if v.is_a?Hash
10
+ o[k] = Embedly::EmbedlyObject.new v
11
+ end
12
+ end
13
+ super o
14
+ end
15
+
16
+ # for ruby 1.8.x, type should return @table[:type], not the
17
+ # class.
18
+ def type
19
+ method_missing :type
20
+ end
21
+
22
+ def marshal_dump
23
+ o = @table.clone
24
+ o.each do |k,v|
25
+ if v.is_a?Embedly::EmbedlyObject
26
+ o[k] = v.marshal_dump
27
+ end
28
+ end
29
+ return o
30
+ end
31
+
32
+ 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
@@ -0,0 +1,118 @@
1
+ require "spec_helper"
2
+ require "embedly/command_line"
3
+
4
+ module Embedly
5
+ describe CommandLine do
6
+ after do
7
+ ENV['EMBEDLY_KEY'] = nil
8
+ ENV['EMBEDLY_SECRET'] = nil
9
+ end
10
+
11
+ describe "::run!" do
12
+ let(:arguments) { ['-k', 'MY_KEY', 'http://yfrog.com/h7qqespj', '-o', 'maxwidth=10'] }
13
+ let(:api) { mock(API) }
14
+
15
+ it "calls api with options" do
16
+ API.should_receive(:new).with(:key => 'MY_KEY', :headers => {}) { api }
17
+ api.should_receive(:oembed).with(:urls => ['http://yfrog.com/h7qqespj'], :maxwidth => '10')
18
+ CommandLine.run!(:oembed, arguments)
19
+ end
20
+
21
+ it "raises an error if the arguments are empty" do
22
+ $stdout = StringIO.new
23
+ expect {
24
+ CommandLine.run!(:oembed, [])
25
+ }.to raise_error(SystemExit)
26
+ end
27
+ end
28
+
29
+ describe "#run" do
30
+ before do
31
+ API.any_instance.stub(:oembed)
32
+ end
33
+
34
+ describe "with option --hostname" do
35
+ %w[-H --hostname].each do |option|
36
+ it "sets the hostname using #{option}" do
37
+ command([option, "sth.embed.ly"])[:hostname].should == 'sth.embed.ly'
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "with --header" do
43
+ it "sets the header" do
44
+ command(%w[--header Header=value])[:headers].should == { 'Header' => 'value' }
45
+ end
46
+ end
47
+
48
+ describe "with --key" do
49
+ %w[-k --key].each do |option|
50
+ it "sets the key using #{option}" do
51
+ command([option, "SOME_KEY"])[:key].should == 'SOME_KEY'
52
+ end
53
+ end
54
+
55
+ it "gets the key from environment variables if no key was set" do
56
+ ENV['EMBEDLY_KEY'] = 'ENVIRONMENT_KEY'
57
+
58
+ command([])[:key].should == 'ENVIRONMENT_KEY'
59
+ end
60
+ end
61
+
62
+ describe "with --secret" do
63
+ %w[-s --secret].each do |option|
64
+ it "sets the secret using #{option}" do
65
+ command([option, "SECRET"])[:secret].should == 'SECRET'
66
+ end
67
+ end
68
+
69
+ it "gets the secret from environment variables if no secret was set" do
70
+ ENV['EMBEDLY_SECRET'] = 'ENVIRONMENT_SECRET'
71
+
72
+ command([])[:secret].should == 'ENVIRONMENT_SECRET'
73
+ end
74
+ end
75
+
76
+ describe "with --no-key" do
77
+ %w[-N --no-key].each do |option|
78
+ it "unsets the key using #{option}" do
79
+ command([option])[:key].should be_nil
80
+ end
81
+ end
82
+ end
83
+
84
+ describe "with --no-secret" do
85
+ it "unsets the secret" do
86
+ command(['--no-secret'])[:secret].should be_nil
87
+ end
88
+ end
89
+
90
+ describe "with --option" do
91
+ %w[-o --option].each do |option|
92
+ it "sets custom option with #{option}" do
93
+ command([option, "maxwidth=100"])[:query][:maxwidth].should == '100'
94
+ end
95
+ end
96
+ end
97
+
98
+ describe "with --verbose" do
99
+ it "enables logging" do
100
+ command(["--verbose"])
101
+ Embedly.configuration.should be_debug
102
+ end
103
+
104
+ it "disables logging" do
105
+ command(["--no-verbose"])
106
+ Embedly.configuration.should_not be_debug
107
+ end
108
+ end
109
+ end
110
+
111
+ def command(arguments)
112
+ arguments << 'testurl.com'
113
+ command = CommandLine.new(arguments)
114
+ command.run
115
+ command.options
116
+ end
117
+ end
118
+ 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
@@ -0,0 +1,7 @@
1
+ require "embedly"
2
+
3
+ RSpec.configure do |config|
4
+ config.after do
5
+ Embedly.configuration.reset
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: anideo-embedly
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bob Corsaro
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: querystring
16
+ requirement: &2155295700 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2155295700
25
+ - !ruby/object:Gem::Dependency
26
+ name: oauth
27
+ requirement: &2155295200 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2155295200
36
+ - !ruby/object:Gem::Dependency
37
+ name: typhoeus
38
+ requirement: &2155294680 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2155294680
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &2155294160 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2155294160
58
+ - !ruby/object:Gem::Dependency
59
+ name: cucumber
60
+ requirement: &2155293600 !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: *2155293600
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: &2155373720 !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: *2155373720
80
+ - !ruby/object:Gem::Dependency
81
+ name: rspec
82
+ requirement: &2155373160 !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: *2155373160
91
+ - !ruby/object:Gem::Dependency
92
+ name: yard
93
+ requirement: &2155372660 !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: *2155372660
102
+ - !ruby/object:Gem::Dependency
103
+ name: aruba
104
+ requirement: &2155372120 !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: *2155372120
113
+ description: Ruby Embedly client library
114
+ email: bob@embed.ly
115
+ executables:
116
+ - embedly_objectify
117
+ - embedly_oembed
118
+ - embedly_preview
119
+ extensions: []
120
+ extra_rdoc_files:
121
+ - ChangeLog
122
+ - README.rdoc
123
+ files:
124
+ - .rvmrc
125
+ - ChangeLog
126
+ - Gemfile
127
+ - MIT-LICENSE
128
+ - README.rdoc
129
+ - Rakefile
130
+ - VERSION
131
+ - anideo-embedly.gemspec
132
+ - bin/embedly_objectify
133
+ - bin/embedly_oembed
134
+ - bin/embedly_preview
135
+ - cucumber.yml
136
+ - features/command_line.feature
137
+ - features/objectify.feature
138
+ - features/oembed.feature
139
+ - features/steps/api_steps.rb
140
+ - features/steps/env.rb
141
+ - lib/embedly.rb
142
+ - lib/embedly/api.rb
143
+ - lib/embedly/command_line.rb
144
+ - lib/embedly/configuration.rb
145
+ - lib/embedly/exceptions.rb
146
+ - lib/embedly/model.rb
147
+ - spec/embedly/api_spec.rb
148
+ - spec/embedly/command_line_spec.rb
149
+ - spec/embedly/configuration_spec.rb
150
+ - spec/spec_helper.rb
151
+ homepage: http://github.com/embedly/embedly-ruby
152
+ licenses:
153
+ - MIT
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ segments:
165
+ - 0
166
+ hash: 1741436886336218838
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ none: false
169
+ requirements:
170
+ - - ! '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 1.8.6
176
+ signing_key:
177
+ specification_version: 3
178
+ summary: Ruby Embedly client library
179
+ test_files: []