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 CHANGED
@@ -1 +1 @@
1
- rvm 1.9.2@embedly
1
+ rvm 1.9.2@embedly-ruby
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source :rubygems
2
+
3
+ gem "querystring"
4
+
5
+ group :development do
6
+ gem "jeweler"
7
+ gem "cucumber"
8
+ gem "rake"
9
+ gem "rspec"
10
+ gem "yard"
11
+ end
12
+
@@ -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 'rake'
2
+ require 'bundler'
3
3
 
4
4
  begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "embedly"
8
- gem.summary = %Q{Ruby Embedly client library}
9
- gem.description = %Q{Ruby Embedly client library}
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
- begin
24
- require 'cucumber/rake/task'
25
- Cucumber::Rake::Task.new(:features)
26
- rescue LoadError
27
- task :features do
28
- abort "Cucumber is not installed"
29
- end
30
- end
31
-
32
- begin
33
- require 'yard'
34
- YARD::Rake::YardocTask.new do |t|
35
- t.files = FileList['lib/**/*.rb'].exclude('lib/jeweler/templates/**/*.rb')
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 :features => :check_dependencies
28
+ require 'cucumber/rake/task'
29
+ Cucumber::Rake::Task.new(:features)
44
30
 
45
- task :default => :features
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.3.3
1
+ 0.4.0
@@ -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)
@@ -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)
@@ -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)
@@ -11,5 +11,5 @@ Feature: Objectify
11
11
  And objectify api_version is 2
12
12
 
13
13
  Examples:
14
- | url | metadesc |
15
- | http://tweetphoto.com/14784358 | Plixi allows user to ins |
14
+ | url | metadesc |
15
+ | http://tweetphoto.com/14784358 | Earn PTZ when you watch |
@@ -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://tweetphoto.com/14784358 | http://plixi.com |
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://tweetphoto.com/14784358 | photo |
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://plixi.com/p/16044847 | http://www.youtube.com/,http://plixi.com |
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://tweetphoto.com/14784358 | 404, | error,photo |
91
- | http://tweetphoto.com/14784358,http://www.scribd.com/doc/asdfasdfasdf | ,404 | photo,error |
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
@@ -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]}?#{q params}"
104
+ path = "/#{opts[:version]}/#{opts[:action]}?#{QueryString.stringify(params)}"
103
105
 
104
106
  logger.debug { "calling #{endpoint}#{path}" }
105
107
 
106
- url = URI.parse(absurl(endpoint))
107
- response = Net::HTTP.start(url.host, url.port) do |http|
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
- url = URI.parse(absurl(endpoint))
143
- response = Net::HTTP.start(url.host, url.port) do |http|
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
- opts = args[0]
168
- opts[:action] = name
169
- opts[:version] = @api_version[name]
170
- apicall opts
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 absurl uri
175
- uri !~ %r{^https?://.*} ? "http://#{uri}" : uri
176
- end
177
-
178
- # Escapes url parameters
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
- prerelease: false
5
- segments:
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: cucumber
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
- requirement: &id001 !ruby/object:Gem::Requirement
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
- segments:
29
- - 0
30
- version: "0"
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
- requirement: &id002 !ruby/object:Gem::Requirement
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
- segments:
42
- - 0
43
- version: "0"
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
44
56
  type: :development
45
- version_requirements: *id002
46
- - !ruby/object:Gem::Dependency
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
- requirement: &id003 !ruby/object:Gem::Requirement
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
- segments:
55
- - 0
56
- version: "0"
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
57
78
  type: :development
58
- version_requirements: *id003
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
- segments:
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ segments:
103
125
  - 0
104
- version: "0"
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
- segments:
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.3.7
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
-