lumiere 0.1.8 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,44 @@
1
+ require_relative 'src'
2
+ require_relative 'html_object_properties'
3
+
4
+ module Lumiere
5
+ module EmbedCode
6
+ extend self
7
+
8
+ def embed_code(opts = {})
9
+ src = generate_src(opts)
10
+ object_properties = generate_object_properties(opts)
11
+
12
+ generate_iframe(src, object_properties)
13
+ end
14
+
15
+ private
16
+
17
+ def generate_src(opts = {})
18
+ url_attributes = opts.fetch(:url_attributes, {})
19
+ default_url_attributes = default_attributes.fetch(:url_attributes, {})
20
+ url_properties = default_url_attributes.merge(url_attributes)
21
+ src_encoder.(embed_url, url_properties)
22
+ end
23
+
24
+ def src_encoder
25
+ SRC
26
+ end
27
+
28
+ def generate_object_properties(opts = {})
29
+ iframe_attributes = opts.fetch(:iframe_attributes, {})
30
+ default_iframe_attributes = default_attributes.fetch(:iframe_attributes, {})
31
+ default_iframe_attributes.merge(iframe_attributes)
32
+ end
33
+
34
+ def generate_iframe(src, opts)
35
+ opts = {src: src}.merge(opts)
36
+ html_options = html_object_properties.(opts)
37
+ "<iframe #{html_options}></iframe>"
38
+ end
39
+
40
+ def html_object_properties
41
+ HTMLObjectProperties
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,22 @@
1
+ module Lumiere
2
+ module HTMLObjectProperties
3
+ extend self
4
+
5
+ def generate(opts={})
6
+ opts.map do |key, value|
7
+ generate_object_property(key, value)
8
+ end.join(' ')
9
+ end
10
+ alias_method :call, :generate
11
+
12
+ private
13
+
14
+ def generate_object_property(key, value)
15
+ if value.is_a?(TrueClass)
16
+ key #set as 'option' rather than 'option=true'
17
+ else
18
+ "#{key}=\"#{value}\""
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ require 'open-uri'
2
+
3
+ module Lumiere
4
+ module SRC
5
+ extend self
6
+
7
+ def encode(src, opts={})
8
+ src += www_form(opts) unless opts.empty?
9
+ src
10
+ end
11
+ alias_method :call, :encode
12
+
13
+ private
14
+
15
+ def www_form(opts)
16
+ "?" + uri.encode_www_form(opts)
17
+ end
18
+
19
+ def uri
20
+ URI
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,5 @@
1
+ require 'open-uri'
2
+
1
3
  module Lumiere
2
4
  module URISchemeless
3
5
  def self.parse(url)
@@ -1,33 +1,24 @@
1
1
  require 'open-uri'
2
2
 
3
3
  module Lumiere
4
- class Fetcher
4
+ module Fetcher
5
+ extend self
5
6
 
6
- def initialize(context)
7
- @api_url = context.api_url
8
- @unpack_into = context.unpack_into
9
- end
10
-
11
- def remote_attributes
12
- unless request_hash[@api_url]
13
- request_hash[@api_url] = unpack
7
+ def remote_attributes(api_url, unpack_into)
8
+ body = scrape(api_url)
9
+ unpack(body, unpack_into)
14
10
  end
15
- request_hash[@api_url]
16
- end
17
11
 
18
- private
12
+ private
19
13
 
20
- def request_hash
21
- @request_hash ||= {}
22
- end
14
+ def unpack(body, unpack_into)
15
+ unpack_into.from_json(body)
16
+ end
23
17
 
24
- def unpack
25
- @unpack_into.from_json(raw_response)
26
- end
18
+ def scrape(url)
19
+ body = open(url).read
20
+ body
21
+ end
27
22
 
28
- def raw_response
29
- open(@api_url).read
30
23
  end
31
-
32
- end
33
24
  end
@@ -1,12 +1,5 @@
1
1
  require "lumiere/version"
2
- require 'open-uri'
3
2
  require 'forwardable'
4
- require 'net/http'
5
- require 'json'
6
- require 'representable'
7
- require 'representable/coercion'
8
- require 'representable/json'
9
- require 'representable/json/collection'
10
3
 
11
4
  require_relative 'provider'
12
5
 
@@ -1,3 +1,3 @@
1
1
  module Lumiere
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.10"
3
3
  end
@@ -1,7 +1,9 @@
1
+ require 'net/http'
2
+
1
3
  require_relative 'extended_uri'
2
4
  require_relative 'playlist'
3
5
  require_relative 'fetcher'
4
- require_relative 'embed_code'
6
+ require_relative 'embed_code/embed_code'
5
7
 
6
8
  module Lumiere
7
9
  class Provider
@@ -9,7 +11,6 @@ module Lumiere
9
11
  PROVIDERS = %w(YouTubePlaylist VimeoPlaylist YouTube Vimeo Dailymotion)
10
12
  PROVIDERS.each do |provider|
11
13
  require_relative "provider/#{provider.downcase}/#{provider.downcase}"
12
- require_relative "provider/#{provider.downcase}/representer"
13
14
  end
14
15
 
15
16
  def self.delegate(url)
@@ -1,3 +1,6 @@
1
+ require_relative 'representer'
2
+ require_relative '../../provider'
3
+
1
4
  module Lumiere
2
5
  class Dailymotion < Provider
3
6
  attr_accessor :url
@@ -75,7 +78,7 @@ class Dailymotion < Provider
75
78
  private
76
79
 
77
80
  def fetch
78
- @fetch ||= Fetcher.new(self).remote_attributes
81
+ @fetch ||= Fetcher.remote_attributes(api_url, unpack_into)
79
82
  end
80
83
 
81
84
  def calculate_video_id
@@ -1,3 +1,7 @@
1
+ require 'representable'
2
+ require 'representable/coercion'
3
+ require 'representable/json'
4
+
1
5
  module Lumiere
2
6
  module DailymotionVideoRepresenter
3
7
  include Representable::JSON
@@ -1,3 +1,8 @@
1
+ require 'representable'
2
+ require 'representable/coercion'
3
+ require 'representable/json'
4
+ require 'representable/json/collection'
5
+
1
6
  module Lumiere
2
7
  module VimeoVideoRepresenter
3
8
  include Representable::JSON
@@ -1,3 +1,6 @@
1
+ require_relative 'representer'
2
+ require_relative '../../provider'
3
+
1
4
  module Lumiere
2
5
  class Vimeo < Provider
3
6
  attr_accessor :url
@@ -82,7 +85,7 @@ class Vimeo < Provider
82
85
  private
83
86
 
84
87
  def fetch
85
- @fetch ||= Fetcher.new(self).remote_attributes[0]
88
+ @fetch ||= Fetcher.remote_attributes(api_url, unpack_into)[0]
86
89
  end
87
90
 
88
91
  def calculate_video_id
@@ -1,3 +1,7 @@
1
+ require 'representable'
2
+ require 'representable/coercion'
3
+ require 'representable/json'
4
+
1
5
  module Lumiere
2
6
  module VimeoPlaylistRepresenter
3
7
  include Representable::JSON
@@ -1,3 +1,6 @@
1
+ require_relative 'representer'
2
+ require_relative '../../provider'
3
+
1
4
  module Lumiere
2
5
  class VimeoPlaylist < Provider
3
6
  attr_accessor :url
@@ -80,7 +83,7 @@ class VimeoPlaylist < Provider
80
83
  private
81
84
 
82
85
  def fetch
83
- @fetch ||= Fetcher.new(self).remote_attributes
86
+ @fetch ||= Fetcher.remote_attributes(api_url, unpack_into)
84
87
  end
85
88
 
86
89
  def calculate_playlist_id
@@ -128,7 +131,7 @@ class VimeoPlaylist < Provider
128
131
  end
129
132
 
130
133
  def fetch
131
- Fetcher.new(self).remote_attributes
134
+ Fetcher.remote_attributes(api_url, unpack_into)
132
135
  end
133
136
 
134
137
  def page_count
@@ -1,3 +1,8 @@
1
+ require 'representable'
2
+ require 'representable/coercion'
3
+ require 'representable/json'
4
+ require 'representable/json/collection'
5
+
1
6
  module Lumiere
2
7
  module YouTubeVideoRepresenter
3
8
  include Representable::JSON
@@ -1,3 +1,6 @@
1
+ require_relative 'representer'
2
+ require_relative '../../provider'
3
+
1
4
  module Lumiere
2
5
  class YouTube < Provider
3
6
  attr_accessor :url
@@ -80,7 +83,7 @@ class YouTube < Provider
80
83
  private
81
84
 
82
85
  def fetch
83
- @fetch ||= Fetcher.new(self).remote_attributes
86
+ @fetch ||= Fetcher.remote_attributes(api_url, unpack_into)
84
87
  end
85
88
 
86
89
  def calculate_video_id
@@ -1,3 +1,8 @@
1
+ require 'representable'
2
+ require 'representable/coercion'
3
+ require 'representable/json'
4
+ require 'representable/json/collection'
5
+
1
6
  require_relative '../youtube/youtube'
2
7
  require_relative '../youtube/representer'
3
8
 
@@ -1,3 +1,6 @@
1
+ require_relative 'representer'
2
+ require_relative '../../provider'
3
+
1
4
  module Lumiere
2
5
  class YouTubePlaylist < Provider
3
6
  attr_accessor :url
@@ -104,7 +107,7 @@ class YouTubePlaylist < Provider
104
107
  end
105
108
 
106
109
  def fetch!
107
- Fetcher.new(self).remote_attributes
110
+ Fetcher.remote_attributes(api_url, unpack_into)
108
111
  end
109
112
 
110
113
  def calculate_playlist_id
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lumiere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-07 00:00:00.000000000 Z
12
+ date: 2014-06-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: representable
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.8.0
21
+ version: 1.8.5
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 1.8.0
29
+ version: 1.8.5
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: virtus
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -64,33 +64,33 @@ dependencies:
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - ! '>='
67
+ - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: 10.3.1
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ! '>='
75
+ - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: '0'
77
+ version: 10.3.1
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: rspec
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
- - - ! '>='
83
+ - - ~>
84
84
  - !ruby/object:Gem::Version
85
- version: '0'
85
+ version: 3.0.0
86
86
  type: :development
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
- - - ! '>='
91
+ - - ~>
92
92
  - !ruby/object:Gem::Version
93
- version: '0'
93
+ version: 3.0.0
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: webmock
96
96
  requirement: !ruby/object:Gem::Requirement
@@ -146,7 +146,9 @@ extensions: []
146
146
  extra_rdoc_files: []
147
147
  files:
148
148
  - LICENSE.txt
149
- - lib/embed_code.rb
149
+ - lib/embed_code/embed_code.rb
150
+ - lib/embed_code/html_object_properties.rb
151
+ - lib/embed_code/src.rb
150
152
  - lib/extended_uri.rb
151
153
  - lib/fetcher.rb
152
154
  - lib/lumiere/version.rb
@@ -1,55 +0,0 @@
1
- require 'open-uri'
2
-
3
- module Lumiere
4
- module EmbedCode
5
- extend self
6
-
7
- def embed_code(opts = {})
8
- iframe_attributes = opts.fetch(:iframe_attributes, {})
9
- url_attributes = opts.fetch(:url_attributes, {})
10
-
11
- default_iframe_attributes = default_attributes.fetch(:iframe_attributes, {})
12
- default_url_attributes = default_attributes.fetch(:url_attributes, {})
13
-
14
- object_properties = default_iframe_attributes.merge(iframe_attributes)
15
- url_properties = default_url_attributes.merge(url_attributes)
16
-
17
- generate(embed_url, url_properties, object_properties)
18
- end
19
-
20
- private
21
-
22
- def generate(src, url_properties={}, object_properties={})
23
- src = generate_src(src, url_properties)
24
- object_properties = {src: src}.merge(object_properties)
25
- generate_html_object('iframe', object_properties)
26
- end
27
-
28
- def generate_src(src, url_properties)
29
- if !url_properties.empty?
30
- src += "?" + URI.encode_www_form(url_properties)
31
- else
32
- src
33
- end
34
- end
35
-
36
- def generate_html_object(object_name, opts)
37
- html_options = generate_object_properties(opts)
38
- "<#{object_name} #{html_options}></#{object_name}>"
39
- end
40
-
41
- def generate_object_properties(opts={})
42
- opts.map do |key, value|
43
- generate_object_property(key, value)
44
- end.join(' ')
45
- end
46
-
47
- def generate_object_property(key, value)
48
- if value.is_a?(TrueClass)
49
- key #set as 'option' rather than 'option=true'
50
- else
51
- "#{key}=\"#{value}\""
52
- end
53
- end
54
- end
55
- end