tinyembedly 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby
7
+ - ree
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in tinyembedly.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem 'rake'
8
+ end
data/README.md CHANGED
@@ -0,0 +1,41 @@
1
+ # Tinyembedly [![Build Status](https://secure.travis-ci.org/dies-el/tinyembedly.png)](http://travis-ci.org/dies-el/tinyembedly)
2
+
3
+ A super tiny Embedly oEmbed library, using HTTParty. It makes a GET request to Embed.ly and returns the response in the form of a hash.
4
+
5
+ Extracted from [Elementalise](http://elementalise.com).
6
+
7
+ # Installation
8
+
9
+ ```ruby
10
+ get install tinyembedly
11
+ ```
12
+
13
+ or, add it to your Gemfile
14
+
15
+ ```ruby
16
+ gem 'tinyembedly'
17
+ ```
18
+
19
+ # Prereqs
20
+
21
+ You don't _need_ an Embed.ly API key, but you should really get one. [Sign up for an Embed.ly account](http://embed.ly/pricing) (they have a free plan).
22
+
23
+ # Getting started
24
+
25
+ ```ruby
26
+ response = Tinyembedly::Oembed.to_hash("http://youtu.be/12jmp4KVRPM")
27
+ ```
28
+
29
+ Which calls [this endpoint](http://api.embed.ly/1/oembed?url=http://youtu.be/12jmp4KVRPM) and converts it to a hash.
30
+
31
+ Thats it.
32
+
33
+ # Contributors
34
+
35
+ - Ebony Charlton
36
+
37
+ Noone else. Could you help? Go on. Goooo on. Goooooooo on!
38
+
39
+ # License
40
+
41
+ This code is free to use under the terms of the MIT license.
@@ -1,4 +1,6 @@
1
1
  require 'httparty'
2
2
  require "tinyembedly/version"
3
+ require "tinyembedly/base_uri"
3
4
  require "tinyembedly/response_error"
4
5
  require "tinyembedly/oembed"
6
+ require "tinyembedly/service"
@@ -0,0 +1,3 @@
1
+ module Tinyembedly
2
+ BASE_URI = 'api.embed.ly'
3
+ end
@@ -1,7 +1,7 @@
1
1
  module Tinyembedly
2
2
  class Oembed
3
3
  include HTTParty
4
- base_uri 'api.embed.ly'
4
+ base_uri BASE_URI
5
5
 
6
6
  attr_reader :response, :api_key, :url
7
7
  @@api_key = nil
@@ -0,0 +1,26 @@
1
+ module Tinyembedly
2
+ class Service
3
+ include HTTParty
4
+
5
+ def self.services
6
+ if !defined?(@@services) || @@services.nil?
7
+ res = get("http://#{BASE_URI}/1/services/ruby")
8
+ @@services = res.code == 200 ? res.parsed_response : nil
9
+ end
10
+ @@services
11
+ end
12
+
13
+ def self.services_regex
14
+ if services.is_a?(Array)
15
+ r = services.collect { |service| service['regex'].join('|') }.join('|')
16
+ Regexp.new("^(#{r})$")
17
+ end
18
+ end
19
+
20
+ protected
21
+
22
+ def self.endpoint
23
+ '/1/services/ruby'
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module Tinyembedly
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,6 +1,34 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Tinyembedly::Oembed do
4
+ describe "to_hash" do
5
+ it "when successful, will return the response as a hash" do
6
+ response = mock(:code => 200, :parsed_response => 'response_hash')
7
+
8
+ oembed = Tinyembedly::Oembed.new
9
+ oembed.expects(:get_oembed).once.returns(response)
10
+
11
+ oembed.to_hash.should eq('response_hash')
12
+ end
13
+
14
+ it "when an HTTP error occurs, will raise a Tinyembedly::ResponseError" do
15
+ response = mock(:code => 401)
16
+
17
+ oembed = Tinyembedly::Oembed.new
18
+ oembed.expects(:get_oembed).once.returns(response)
19
+
20
+ lambda { oembed.to_hash }.should raise_error(Tinyembedly::ResponseError)
21
+ end
22
+ end
23
+
24
+ describe "self.to_hash" do
25
+ it "will instantiate the Oembed with the passed in url and call #to_hash" do
26
+ oembed = mock(:to_hash => 'response_hash')
27
+ Tinyembedly::Oembed.expects(:new).with({ :url => 'url_placeholder' }).returns(oembed)
28
+ Tinyembedly::Oembed.to_hash('url_placeholder').should eq('response_hash')
29
+ end
30
+ end
31
+
4
32
  describe "params" do
5
33
  it "returns a hash containing the url and api key in the format Embedly expects" do
6
34
  oembed = Tinyembedly::Oembed.new(:url => 'url_placeholder', :api_key => 'fish')
@@ -28,31 +56,4 @@ describe Tinyembedly::Oembed do
28
56
  end
29
57
  end
30
58
 
31
- describe "to_hash" do
32
- it "when successful, will return a the response as a hash" do
33
- response = mock(:code => 200, :parsed_response => 'response_hash')
34
-
35
- oembed = Tinyembedly::Oembed.new
36
- oembed.expects(:get_oembed).once.returns(response)
37
-
38
- oembed.to_hash.should eq('response_hash')
39
- end
40
-
41
- it "when an HTTP error occurs, will raise a Tinyembedly::ResponseError" do
42
- response = mock(:code => 401)
43
-
44
- oembed = Tinyembedly::Oembed.new
45
- oembed.expects(:get_oembed).once.returns(response)
46
-
47
- lambda { oembed.to_hash }.should raise_error(Tinyembedly::ResponseError)
48
- end
49
- end
50
-
51
- describe "self.to_hash" do
52
- it "will instantiate the Oembed with the passed in url and call #to_hash" do
53
- oembed = mock(:to_hash => 'response_hash')
54
- Tinyembedly::Oembed.expects(:new).with({ :url => 'url_placeholder' }).returns(oembed)
55
- Tinyembedly::Oembed.to_hash('url_placeholder').should eq('response_hash')
56
- end
57
- end
58
59
  end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tinyembedly::Service do
4
+ before(:each) do
5
+ @base = Tinyembedly::Service
6
+ end
7
+
8
+ describe "list of services" do
9
+ it "fetches list of services" do
10
+ @base.expects(:get).with('http://api.embed.ly/1/services/ruby').returns(mock(:code => 0))
11
+ @base.services
12
+ end
13
+
14
+ it "stores response" do
15
+ services = [{'name' => 'youtube','regex' => []}]
16
+ response = mock(:code => 200, :parsed_response => services)
17
+ @base.expects(:get).returns(response)
18
+ @base.services.size.should == 1
19
+ @base.services.first['name'].should == 'youtube'
20
+ end
21
+ end
22
+
23
+ describe "service regexes" do
24
+ it "creates a regex" do
25
+ @base.stubs(:services).returns([{'regex' => []}])
26
+ @base.services_regex.should be_kind_of(Regexp)
27
+ end
28
+
29
+ it "returns nil when services missing" do
30
+ @base.stubs(:services).returns(nil)
31
+ @base.services_regex.should be_nil
32
+ end
33
+
34
+ it "collects regexes" do
35
+ @base.stubs(:services).returns([
36
+ {'regex' => ["http:\\/\\/.*youtube\\.com\\/watch.*","http:\\/\\/youtu\\.be\\/.*"]},
37
+ {'regex' => ["http:\\/\\/military\\.discovery\\.com\\/videos\\/.*"]}])
38
+ @base.services_regex.should == /^(http:\/\/.*youtube\.com\/watch.*|http:\/\/youtu\.be\/.*|http:\/\/military\.discovery\.com\/videos\/.*)$/
39
+ end
40
+ end
41
+
42
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinyembedly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-12 00:00:00.000000000Z
12
+ date: 2012-02-13 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &70141083007480 !ruby/object:Gem::Requirement
16
+ requirement: &70218979854880 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.5.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70141083007480
24
+ version_requirements: *70218979854880
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec-core
27
- requirement: &70141083006500 !ruby/object:Gem::Requirement
27
+ requirement: &70218979854160 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70141083006500
35
+ version_requirements: *70218979854160
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec-expectations
38
- requirement: &70141083002400 !ruby/object:Gem::Requirement
38
+ requirement: &70218979853180 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70141083002400
46
+ version_requirements: *70218979853180
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: mocha
49
- requirement: &70141083000940 !ruby/object:Gem::Requirement
49
+ requirement: &70218979852240 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70141083000940
57
+ version_requirements: *70218979852240
58
58
  description: A super tiny Embedly oEmbed library, using HTTParty
59
59
  email:
60
60
  - andrew@desto.net
@@ -64,15 +64,19 @@ extra_rdoc_files: []
64
64
  files:
65
65
  - .gitignore
66
66
  - .rspec
67
+ - .travis.yml
67
68
  - Gemfile
68
69
  - MIT-LICENSE
69
70
  - README.md
70
71
  - Rakefile
71
72
  - lib/tinyembedly.rb
73
+ - lib/tinyembedly/base_uri.rb
72
74
  - lib/tinyembedly/oembed.rb
73
75
  - lib/tinyembedly/response_error.rb
76
+ - lib/tinyembedly/service.rb
74
77
  - lib/tinyembedly/version.rb
75
78
  - spec/oembed_spec.rb
79
+ - spec/service_spec.rb
76
80
  - spec/spec_helper.rb
77
81
  - tinyembedly.gemspec
78
82
  homepage: https://github.com/dies-el/tinyembedly
@@ -89,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
93
  version: '0'
90
94
  segments:
91
95
  - 0
92
- hash: 500005298147007422
96
+ hash: -102373094893876629
93
97
  required_rubygems_version: !ruby/object:Gem::Requirement
94
98
  none: false
95
99
  requirements:
@@ -98,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
102
  version: '0'
99
103
  segments:
100
104
  - 0
101
- hash: 500005298147007422
105
+ hash: -102373094893876629
102
106
  requirements: []
103
107
  rubyforge_project: tinyembedly
104
108
  rubygems_version: 1.8.10
@@ -107,4 +111,5 @@ specification_version: 3
107
111
  summary: Fetch Embedly oEmbed data
108
112
  test_files:
109
113
  - spec/oembed_spec.rb
114
+ - spec/service_spec.rb
110
115
  - spec/spec_helper.rb