tinyembedly 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ bin/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tinyembedly.gemspec
4
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT LICENSE
2
+
3
+ Copyright (c) 2010 Sven Fuchs <svenfuchs@artweb-design.de>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
data/README.md ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ Bundler.setup(:default, :development)
4
+
5
+
6
+ desc "Run all RSpec tests"
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :default => :spec
@@ -0,0 +1,47 @@
1
+ module Tinyembedly
2
+ class Oembed
3
+ include HTTParty
4
+ base_uri 'api.embed.ly'
5
+
6
+ attr_reader :response, :api_key, :url
7
+ @@api_key = nil
8
+
9
+ def self.api_key=(value)
10
+ @@api_key = value
11
+ end
12
+
13
+ def self.to_hash(url)
14
+ oembed = Oembed.new(:url => url)
15
+ oembed.to_hash
16
+ end
17
+
18
+ def initialize(options = {})
19
+ @api_key = options[:api_key] || @@api_key
20
+ @url = options[:url]
21
+ end
22
+
23
+ def to_hash
24
+ response = get_oembed
25
+ case response.code
26
+ when 200
27
+ response.parsed_response
28
+ else
29
+ raise ResponseError.new(response)
30
+ end
31
+ end
32
+
33
+ def get_oembed
34
+ self.class.get(endpoint, :query => params)
35
+ end
36
+
37
+ def params
38
+ { :url => @url, :key => @api_key }
39
+ end
40
+
41
+ protected
42
+
43
+ def endpoint
44
+ "/1/oembed"
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,13 @@
1
+ module Tinyembedly
2
+ class ResponseError < StandardError
3
+ attr_reader :response
4
+
5
+ def initialize(response)
6
+ @response = response
7
+ end
8
+
9
+ def to_s
10
+ @response.inspect
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Tinyembedly
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'httparty'
2
+ require "tinyembedly/version"
3
+ require "tinyembedly/response_error"
4
+ require "tinyembedly/oembed"
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tinyembedly::Oembed do
4
+ describe "params" do
5
+ it "returns a hash containing the url and api key in the format Embedly expects" do
6
+ oembed = Tinyembedly::Oembed.new(:url => 'url_placeholder', :api_key => 'fish')
7
+ oembed.params[:url].should eq('url_placeholder')
8
+ oembed.params[:key].should eq('fish')
9
+ end
10
+ end
11
+
12
+ describe "get_oembed" do
13
+ it "will call HTTParty's get method with the correct params" do
14
+ oembed = Tinyembedly::Oembed.new
15
+ oembed.stubs(:endpoint).returns('/endpoint')
16
+ oembed.stubs(:params).returns('params_placeholder')
17
+ Tinyembedly::Oembed.expects(:get).with('/endpoint', :query => 'params_placeholder')
18
+
19
+ oembed.get_oembed
20
+ end
21
+ end
22
+
23
+ describe "Oembed.api_key=" do
24
+ it "will set the default Oembed API key" do
25
+ Tinyembedly::Oembed.api_key = 'fish'
26
+ oembed = Tinyembedly::Oembed.new
27
+ oembed.api_key.should eq('fish')
28
+ end
29
+ end
30
+
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
+ end
@@ -0,0 +1,14 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ require "tinyembedly"
7
+ #
8
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
9
+ RSpec.configure do |config|
10
+ config.mock_with :mocha
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "tinyembedly/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "tinyembedly"
7
+ s.version = Tinyembedly::VERSION
8
+ s.authors = ["Andrew Donaldson"]
9
+ s.email = ["andrew@desto.net"]
10
+ s.homepage = "https://github.com/dies-el/tinyembedly"
11
+ s.summary = %q{Fetch Embedly oEmbed data}
12
+ s.description = %q{A super tiny Embedly oEmbed library, using HTTParty}
13
+
14
+ s.rubyforge_project = "tinyembedly"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency "httparty", ">= 0.5.0"
22
+ s.add_development_dependency "rspec-core"
23
+ s.add_development_dependency "rspec-expectations"
24
+ s.add_development_dependency "mocha"
25
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tinyembedly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Donaldson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-12 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &70141083007480 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.5.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70141083007480
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec-core
27
+ requirement: &70141083006500 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70141083006500
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec-expectations
38
+ requirement: &70141083002400 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70141083002400
47
+ - !ruby/object:Gem::Dependency
48
+ name: mocha
49
+ requirement: &70141083000940 !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: *70141083000940
58
+ description: A super tiny Embedly oEmbed library, using HTTParty
59
+ email:
60
+ - andrew@desto.net
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - .rspec
67
+ - Gemfile
68
+ - MIT-LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - lib/tinyembedly.rb
72
+ - lib/tinyembedly/oembed.rb
73
+ - lib/tinyembedly/response_error.rb
74
+ - lib/tinyembedly/version.rb
75
+ - spec/oembed_spec.rb
76
+ - spec/spec_helper.rb
77
+ - tinyembedly.gemspec
78
+ homepage: https://github.com/dies-el/tinyembedly
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ segments:
91
+ - 0
92
+ hash: 500005298147007422
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ segments:
100
+ - 0
101
+ hash: 500005298147007422
102
+ requirements: []
103
+ rubyforge_project: tinyembedly
104
+ rubygems_version: 1.8.10
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Fetch Embedly oEmbed data
108
+ test_files:
109
+ - spec/oembed_spec.rb
110
+ - spec/spec_helper.rb