smoke 0.5.16 → 0.5.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,6 +18,10 @@ Then you can output as a plain ruby object or one of your other favourites (JSON
18
18
  * Early [screencast](http://vimeo.com/4272804) to get developer / peer feedback
19
19
 
20
20
 
21
+ ## Install
22
+
23
+ gem install smoke -s http://gemcutter.org
24
+
21
25
  ## The concept
22
26
 
23
27
  The concept comes from using [Yahoo Pipes](http://pipes.yahoo.com) to make web based mash ups: Get a list of tv shows for my torrent client, compile a recipe book or make tools to give me a list of albums that artists in my music library are about to be released.
@@ -69,7 +73,7 @@ Source definition:
69
73
 
70
74
  Execution:
71
75
 
72
- Smoke[:delicious].username("bschwarz").output
76
+ Smoke.delicious.username("bschwarz").output
73
77
 
74
78
 
75
79
  ### TODO (working on, just mental notes)
data/Rakefile CHANGED
@@ -11,9 +11,9 @@ begin
11
11
  gem.homepage = "http://github.com/benschwarz/smoke"
12
12
  gem.authors = ["Ben Schwarz"]
13
13
  gem.files = FileList['lib/**/*.rb', 'rdoc/**/*', '[A-Z]*', 'spec/**/*', 'vendor/**/*'].to_a
14
+ gem.add_development_dependency("fakeweb", ">= 1.2.5")
14
15
  gem.add_dependency("simple-rss", "1.2")
15
16
  gem.add_dependency("json", ">= 1.1.3")
16
- gem.add_dependency("fakeweb", "1.2.5")
17
17
  gem.add_dependency("crack", ">= 0.1.1")
18
18
  gem.add_dependency("moneta", "0.6.0")
19
19
  gem.add_dependency("rest-client", "1.0.3")
@@ -1,4 +1,5 @@
1
1
  ---
2
- :patch: 16
2
+ :patch: 17
3
3
  :major: 0
4
+ :build:
4
5
  :minor: 5
@@ -28,7 +28,7 @@ module Smoke
28
28
  # Smoke.yql(:ruby) do ....
29
29
  # Then access it:
30
30
  # Smoke[:ruby]
31
- # => #<Smoke::Source::YQL::0x18428d4...
31
+ # => #<Smoke::YQL::0x18428d4...
32
32
  def [](source)
33
33
  active_sources[source]
34
34
  end
@@ -54,8 +54,16 @@ module Smoke
54
54
  end
55
55
 
56
56
  # Returns all activated smoke sources
57
- def active_sources
58
- @@active_sources
57
+ def active_sources; @@active_sources; end
58
+
59
+ # Returns all exposed sources
60
+ def exposed_sources
61
+ active_sources.reject{|k,v| !v.exposed? }
62
+ end
63
+
64
+ # Returns all concealed sources
65
+ def concealed_sources
66
+ active_sources.reject{|k,v| !v.concealed? }
59
67
  end
60
68
 
61
69
  # Rename a source
@@ -95,9 +103,9 @@ module Smoke
95
103
  @@config
96
104
  end
97
105
 
98
- def yql(name, &block); Smoke::Source::YQL.new(name, &block); end
99
- def data(name, &block); Smoke::Source::Data.new(name, &block); end
100
- def feed(name, &block); Smoke::Source::Feed.new(name, &block); end
106
+ def yql(name, &block); Smoke::YQL.new(name, &block); end
107
+ def data(name, &block); Smoke::Data.new(name, &block); end
108
+ def feed(name, &block); Smoke::Feed.new(name, &block); end
101
109
 
102
110
  # Join multiple sources together into a single feed
103
111
  # Usage:
@@ -105,12 +113,17 @@ module Smoke
105
113
  # name :stream
106
114
  # path :photos, :photo
107
115
  # end
108
- def join(*names, &block); Smoke::Source::Join.new(names, &block); end
116
+ def join(*names, &block); Smoke::Join.new(names, &block); end
109
117
  end
110
118
  end
111
119
 
112
120
  %w(core_ext/hash core_ext/string smoke/cache smoke/request smoke/origin smoke/output/xml).each {|r| require File.join(File.dirname(__FILE__), r)}
113
121
 
122
+ # Autoload the source classes
123
+ %w(YQL Data Feed Join).each do |r|
124
+ Smoke.autoload(r.to_sym, File.join(File.dirname(__FILE__), "smoke", "source", r.downcase))
125
+ end
126
+
114
127
  class Object # :nodoc:
115
128
  include Smoke
116
129
  end
@@ -1,11 +1,12 @@
1
1
  module Smoke
2
2
  class Origin
3
- attr_reader :items, :requirements
3
+ attr_reader :items, :requirements, :exposed
4
4
  attr_accessor :name
5
5
 
6
6
  def initialize(name, &block)
7
7
  raise StandardError, "Sources must have a name" unless name
8
8
  @name = name
9
+ @exposed = true
9
10
  @items, @prepare, @requirements, @transformation = [], [], [], []
10
11
 
11
12
  activate!
@@ -237,6 +238,14 @@ module Smoke
237
238
  @items = @items[0..(length - 1)]
238
239
  end
239
240
 
241
+ # Expose and conceal, this is stictly a feature of rack/smoke.
242
+ # concealed sources will not be "available"
243
+ # Simply marking off sources, more than anything else
244
+ def expose; @exposed = true; end
245
+ def conceal; @exposed = false; end
246
+ def exposed?; @exposed; end
247
+ def concealed?; !@exposed; end
248
+
240
249
  private
241
250
  def prepare!
242
251
  @prepare.each{|block| block.call} unless @prepare.empty?
@@ -247,6 +256,8 @@ module Smoke
247
256
  end
248
257
 
249
258
  def symbolize_keys!
259
+ # If its an array, we flatten it and symbolise the keys.
260
+ # Otherwise, we leave it as is.
250
261
  @items = items.flatten.map{|i| i.symbolize_keys! } if items.respond_to? :flatten
251
262
  end
252
263
 
@@ -260,6 +271,4 @@ module Smoke
260
271
  Smoke.activate(@name, self)
261
272
  end
262
273
  end
263
- end
264
-
265
- Dir["#{File.dirname(__FILE__)}/source/*.rb"].each &method(:require)
274
+ end
@@ -9,10 +9,10 @@ module Smoke
9
9
  end
10
10
  end
11
11
 
12
- SUPPORTED_TYPES = %w(json xml javascript)
12
+ SUPPORTED_TYPES = %w(json xml javascript excel)
13
13
  @@request_options = {
14
14
  :user_agent => Smoke.config[:user_agent],
15
- :accept_encoding => "gzip"
15
+ :accept_encoding => "gzip, deflate"
16
16
  }
17
17
 
18
18
  attr_reader :uri, :content_type, :body
@@ -44,6 +44,10 @@ module Smoke
44
44
  @body = ::Crack::JSON.parse(@body).symbolize_keys!
45
45
  when :xml
46
46
  @body = ::Crack::XML.parse(@body).symbolize_keys!
47
+ when :excel
48
+ # Convert the excel document into an XML document
49
+ doc = @body
50
+ ::Crack::XML.parse().symbolize_keys!
47
51
  when :unknown
48
52
  Smoke.log.warn "Smoke Request: Format unknown for #{@uri} (#{@content_type})"
49
53
  end
@@ -1,39 +1,37 @@
1
1
  module Smoke
2
- module Source # :nodoc:
3
- # The "Data" source allows you to query
4
- # datasources that are "complete" urls
5
- # and rely on the automagic object parsing
6
- # that smoke provides.
7
- #
8
- # For example, you may use this source
9
- # to query a complete restful api call
10
- # unpackage the xml response and get a
11
- # clean ruby object.
12
- #
13
- # Data can take as many urls as you'd like
14
- # to throw at it.
15
- #
16
- # Usage:
17
- # Smoke.data(:ruby) do
18
- # url "http://api.flickr.com/services/rest/?user_id=36821533%40N00&tags=benschwarz-site&nojsoncallback=1&method=flickr.photos.search&format=json&api_key=your_api_key_here
19
- # path :photos, :photo
20
- # end
21
- class Data < Origin
22
- attr_reader :request
23
-
24
- # The URL that you'd like smoke to source its data from
25
- # You can also set the type for silly servers that don't set a correct content-type (Flickr!)
26
- # Example:
27
- # url "http://site.com/resource.json", :type => :json
28
- def url(source_url, options = {})
29
- @url, @options = source_url, options
30
- end
31
-
32
- protected
33
- def dispatch
34
- @request = Smoke::Request.new(@url, @options)
35
- self.items = @request.body
36
- end
2
+ # The "Data" source allows you to query
3
+ # datasources that are "complete" urls
4
+ # and rely on the automagic object parsing
5
+ # that smoke provides.
6
+ #
7
+ # For example, you may use this source
8
+ # to query a complete restful api call
9
+ # unpackage the xml response and get a
10
+ # clean ruby object.
11
+ #
12
+ # Data can take as many urls as you'd like
13
+ # to throw at it.
14
+ #
15
+ # Usage:
16
+ # Smoke.data(:ruby) do
17
+ # url "http://api.flickr.com/services/rest/?user_id=36821533%40N00&tags=benschwarz-site&nojsoncallback=1&method=flickr.photos.search&format=json&api_key=your_api_key_here
18
+ # path :photos, :photo
19
+ # end
20
+ class Data < Origin
21
+ attr_reader :request
22
+
23
+ # The URL that you'd like smoke to source its data from
24
+ # You can also set the type for silly servers that don't set a correct content-type (Flickr!)
25
+ # Example:
26
+ # url "http://site.com/resource.json", :type => :json
27
+ def url(source_url, options = {})
28
+ @url, @options = source_url, options
29
+ end
30
+
31
+ protected
32
+ def dispatch
33
+ @request = Smoke::Request.new(@url, @options)
34
+ self.items = @request.body
37
35
  end
38
36
  end
39
37
  end
@@ -1,24 +1,22 @@
1
1
  module Smoke
2
- module Source # :nodoc:
3
- # Feed can take multiple rss or atom feeds and munge them up together.
4
- #
5
- # Usage:
6
- # Smoke.feed(:ruby) do
7
- # url "domain.tld/rss"
8
- # url "site.tld/atom"
9
- # end
10
- class Feed < Origin
11
- attr_reader :requests
12
-
13
- def url(feed_uri)
14
- (@feeds ||= [] ) << feed_uri
15
- end
16
-
17
- protected
18
- def dispatch
19
- @requests = @feeds.map{|f| Smoke::Request.new(f, {:raw_response => true}) }
20
- self.items = @requests.map{|r| ::SimpleRSS.parse(r.body).items }.flatten
21
- end
2
+ # Feed can take multiple rss or atom feeds and munge them up together.
3
+ #
4
+ # Usage:
5
+ # Smoke.feed(:ruby) do
6
+ # url "domain.tld/rss"
7
+ # url "site.tld/atom"
8
+ # end
9
+ class Feed < Origin
10
+ attr_reader :requests
11
+
12
+ def url(feed_uri)
13
+ (@feeds ||= [] ) << feed_uri
14
+ end
15
+
16
+ protected
17
+ def dispatch
18
+ @requests = @feeds.map{|f| Smoke::Request.new(f, {:raw_response => true}) }
19
+ self.items = @requests.map{|r| ::SimpleRSS.parse(r.body).items }.flatten
22
20
  end
23
21
  end
24
22
  end
@@ -1,56 +1,54 @@
1
1
  module Smoke
2
- module Source # :nodoc:
3
- # The "Joiner" source is a special source
4
- # that can be used to join multiple sources together
5
- # and proxy call dispatch for each source
6
- #
2
+ # The "Joiner" source is a special source
3
+ # that can be used to join multiple sources together
4
+ # and proxy call dispatch for each source
5
+ #
6
+ # Usage:
7
+ # Smoke.join(:delicious, :twitter, :flickr) do
8
+ # path :photos, :photo
9
+ # end
10
+ class Join < Origin # :nodoc:
11
+ def initialize(names, &block)
12
+ @names = names
13
+ super((names << "joined").join("_").to_sym, &block)
14
+ end
15
+
16
+ # Rename sources immediately after they've been joined together
7
17
  # Usage:
8
18
  # Smoke.join(:delicious, :twitter, :flickr) do
9
- # path :photos, :photo
19
+ # name :web_stream
10
20
  # end
11
- class Join < Origin # :nodoc:
12
- def initialize(names, &block)
13
- @names = names
14
- super((names << "joined").join("_").to_sym, &block)
15
- end
16
-
17
- # Rename sources immediately after they've been joined together
18
- # Usage:
19
- # Smoke.join(:delicious, :twitter, :flickr) do
20
- # name :web_stream
21
- # end
22
- def name(rename = nil)
23
- return @name if rename.nil?
24
- Smoke.rename(@name => rename)
25
- end
26
-
27
- def method_missing(symbol, *args, &block)
28
- ivar = "@#{symbol}"
21
+ def name(rename = nil)
22
+ return @name if rename.nil?
23
+ Smoke.rename(@name => rename)
24
+ end
25
+
26
+ def method_missing(symbol, *args, &block)
27
+ ivar = "@#{symbol}"
29
28
 
30
- unless args.empty?
31
- sources.each do |source|
32
- source.last.instance_variable_set(ivar, args.last)
33
- end
29
+ unless args.empty?
30
+ sources.each do |source|
31
+ source.last.instance_variable_set(ivar, args.last)
34
32
  end
35
-
36
- return self
37
33
  end
38
-
39
- protected
40
- def sources
41
- Smoke.active_sources.find_all{|k, v| @names.include?(k) }
34
+
35
+ return self
36
+ end
37
+
38
+ protected
39
+ def sources
40
+ Smoke.active_sources.find_all{|k, v| @names.include?(k) }
41
+ end
42
+
43
+ def dispatch
44
+ # Recall dispatch
45
+ sources.each do |source|
46
+ source.last.send(:prepare!)
47
+ source.last.send(:dispatch) if source.last.respond_to?(:dispatch)
42
48
  end
43
49
 
44
- def dispatch
45
- # Recall dispatch
46
- sources.each do |source|
47
- source.last.send(:prepare!)
48
- source.last.send(:dispatch) if source.last.respond_to?(:dispatch)
49
- end
50
-
51
- # Re-map items
52
- @items = sources.map {|source| source.last.items }.flatten
53
- end
50
+ # Re-map items
51
+ @items = sources.map {|source| source.last.items }.flatten
54
52
  end
55
53
  end
56
54
  end
@@ -1,85 +1,83 @@
1
1
  module Smoke
2
- module Source # :nodoc:
3
- # YQL will call to Yahoo YQL services
2
+ # YQL will call to Yahoo YQL services
3
+ #
4
+ # Usage:
5
+ # Smoke.yql(:ruby) do
6
+ # select :all
7
+ # from "search.web"
8
+ # where :query, "ruby"
9
+ # end
10
+ class YQL < Origin
11
+ API_BASE = "http://query.yahooapis.com/v1/public/yql"
12
+ attr_reader :request
13
+
14
+ # Select indicates what YQL will be selecting
15
+ # Usage:
16
+ # select :all
17
+ # => "SELECT *"
18
+ # select :title
19
+ # => "SELECT title"
20
+ # select :title, :description
21
+ # => "SELECT title, description"
22
+ def select(what = :all)
23
+ @select = what.join(",") and return if what.is_a? Array
24
+ @select = "*" and return if what == :all
25
+ @select = what and return
26
+ end
27
+
28
+ # from corresponds to the from fragment of the YQL query
29
+ # Usage:
30
+ # from "search.web"
31
+ # or
32
+ # from :html
33
+ def from(source)
34
+ @from = source.join(',') and return if source.is_a? Array
35
+ @from = source.to_s
36
+ end
37
+
38
+ # where is a straight up match, no fancy matchers
39
+ # are currently supported
40
+ # Usage:
41
+ # where :xpath, "//div/div/a"
42
+ # or
43
+ # where :query, "python"
44
+ def where(column, value)
45
+ @where = @where || []
46
+ @where << "#{column.to_s} = '#{value}'"
47
+ end
48
+
49
+ # `use` can be used to set the url location of the data-table
50
+ # that you want YQL to search upon
4
51
  #
5
52
  # Usage:
6
- # Smoke.yql(:ruby) do
7
- # select :all
8
- # from "search.web"
9
- # where :query, "ruby"
10
- # end
11
- class YQL < Origin
12
- API_BASE = "http://query.yahooapis.com/v1/public/yql"
13
- attr_reader :request
14
-
15
- # Select indicates what YQL will be selecting
16
- # Usage:
17
- # select :all
18
- # => "SELECT *"
19
- # select :title
20
- # => "SELECT title"
21
- # select :title, :description
22
- # => "SELECT title, description"
23
- def select(what = :all)
24
- @select = what.join(",") and return if what.is_a? Array
25
- @select = "*" and return if what == :all
26
- @select = what and return
27
- end
28
-
29
- # from corresponds to the from fragment of the YQL query
30
- # Usage:
31
- # from "search.web"
32
- # or
33
- # from :html
34
- def from(source)
35
- @from = source.join(',') and return if source.is_a? Array
36
- @from = source.to_s
37
- end
38
-
39
- # where is a straight up match, no fancy matchers
40
- # are currently supported
41
- # Usage:
42
- # where :xpath, "//div/div/a"
43
- # or
44
- # where :query, "python"
45
- def where(column, value)
46
- @where = @where || []
47
- @where << "#{column.to_s} = '#{value}'"
48
- end
49
-
50
- # `use` can be used to set the url location of the data-table
51
- # that you want YQL to search upon
52
- #
53
- # Usage:
54
- # use "http://datatables.org/alltables.env"
55
- def use(url)
56
- params.merge!({:env => url})
57
- end
58
-
59
- protected
60
- def params
61
- @params || @params = {}
62
- end
63
-
64
- def dispatch
65
- @request = Smoke::Request.new(build_uri)
66
- self.items = @request.body
67
- end
68
-
69
- private
70
- def build_uri
71
- chunks = []
72
- default_opts = {
73
- :q => build_query,
74
- :format => "json"
75
- }.merge(params).each {|k,v| chunks << "#{k}=#{v}" }
76
-
77
- return URI.encode(API_BASE + "?" + chunks.join("&"))
78
- end
53
+ # use "http://datatables.org/alltables.env"
54
+ def use(url)
55
+ params.merge!({:env => url})
56
+ end
57
+
58
+ protected
59
+ def params
60
+ @params || @params = {}
61
+ end
62
+
63
+ def dispatch
64
+ @request = Smoke::Request.new(build_uri)
65
+ self.items = @request.body
66
+ end
67
+
68
+ private
69
+ def build_uri
70
+ chunks = []
71
+ default_opts = {
72
+ :q => build_query,
73
+ :format => "json"
74
+ }.merge(params).each {|k,v| chunks << "#{k}=#{v}" }
79
75
 
80
- def build_query
81
- "SELECT #{@select} FROM #{@from} WHERE #{@where.join(" AND ")}"
82
- end
76
+ return URI.encode(API_BASE + "?" + chunks.join("&"))
77
+ end
78
+
79
+ def build_query
80
+ "SELECT #{@select} FROM #{@from} WHERE #{@where.join(" AND ")}"
83
81
  end
84
82
  end
85
83
  end
@@ -53,7 +53,7 @@ describe Smoke::Cache do
53
53
  end
54
54
 
55
55
  @url = "http://memory.tld/store"
56
- FakeWeb.register_uri(@url, :file => File.join(SPEC_DIR, 'supports', 'slashdot.xml'))
56
+ FakeWeb.register_uri(:get, @url, :body => File.join(SPEC_DIR, 'supports', 'slashdot.xml'))
57
57
 
58
58
  require 'moneta/memory'
59
59
  @store = Moneta::Memory.new
@@ -0,0 +1,15 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper.rb")
2
+
3
+ describe "parsing excel" do
4
+ before :all do
5
+ @url = "http://fake.tld/canned/xls"
6
+ @web_search = File.join(SPEC_DIR, 'supports', 'gov_act_toliets.xls')
7
+ FakeWeb.register_uri(:get, @url, :response => @web_search)
8
+
9
+ @request = Smoke::Request.new(@url, {:type => :excel})
10
+ end
11
+
12
+ it "should automagically parse it" do
13
+ puts @request.body.keys
14
+ end
15
+ end
@@ -111,7 +111,7 @@ describe Smoke::Origin do
111
111
  describe "call order" do
112
112
  before :all do
113
113
  @url = "http://domain.tld/benschwarz/feed"
114
- FakeWeb.register_uri(@url, :response => File.join(SPEC_DIR, 'supports', 'flickr-photo.json'))
114
+ FakeWeb.register_uri(:get, @url, :response => File.join(SPEC_DIR, 'supports', 'flickr-photo.json'))
115
115
 
116
116
  Smoke.data :feed_preperation_call_order do
117
117
  prepare do
@@ -144,7 +144,7 @@ describe Smoke::Origin do
144
144
  end
145
145
 
146
146
  it "should chain the source when setting a property" do
147
- Smoke.feed_preperation_call_order.abstract(:value).should be_an_instance_of(Smoke::Source::Data)
147
+ Smoke.feed_preperation_call_order.abstract(:value).should be_an_instance_of(Smoke::Data)
148
148
  end
149
149
  end
150
150
 
@@ -29,7 +29,7 @@ end
29
29
  describe "Smoke XML output with real data" do
30
30
  before :all do
31
31
  @url = "http://domain.tld/feed.json"
32
- FakeWeb.register_uri(@url, :response => File.join(SPEC_DIR, 'supports', 'flickr-photo.json'))
32
+ FakeWeb.register_uri(:get, @url, :response => File.join(SPEC_DIR, 'supports', 'flickr-photo.json'))
33
33
 
34
34
  Smoke.data :real_xml_output do
35
35
  url "http://domain.tld/feed.json", :type => :json
@@ -4,7 +4,7 @@ describe Smoke::Request do
4
4
  before do
5
5
  @url = "http://fake.tld/canned/"
6
6
  @web_search = File.join(SPEC_DIR, 'supports', 'flickr-photo.json')
7
- FakeWeb.register_uri(@url, :response => @web_search)
7
+ FakeWeb.register_uri(:get, @url, :response => @web_search)
8
8
  @request = Smoke::Request.new(@url)
9
9
  end
10
10
 
@@ -26,7 +26,7 @@ describe Smoke::Request do
26
26
  # Gzip response should come out exactly the same as the plain text response
27
27
  @gzip_response = File.join(SPEC_DIR, 'supports', 'gzip_response.txt')
28
28
  @url = "http://fake.tld/gzip"
29
- FakeWeb.register_uri(@url, :response => @gzip_response, :content_encoding => "gzip")
29
+ FakeWeb.register_uri(:get, @url, :response => @gzip_response, :content_encoding => "gzip")
30
30
  end
31
31
 
32
32
  it "should transparently handle a gzipped response" do
@@ -137,7 +137,7 @@ shared_examples_for "all sources" do
137
137
  describe "call order" do
138
138
  before :all do
139
139
  @url = "http://domain.tld/benschwarz/feed"
140
- FakeWeb.register_uri(@url, :response => File.join(SPEC_DIR, 'supports', 'flickr-photo.json'))
140
+ FakeWeb.register_uri(:get, @url, :response => File.join(SPEC_DIR, 'supports', 'flickr-photo.json'))
141
141
 
142
142
  Smoke.data :feed_preperation_call_order do
143
143
  prepare do
@@ -165,7 +165,7 @@ shared_examples_for "all sources" do
165
165
  end
166
166
 
167
167
  it "should chain the source when setting a property" do
168
- @source.abstract(:value).should be_an_instance_of(Smoke::Source::Data)
168
+ @source.abstract(:value).should be_an_instance_of(Smoke::Data)
169
169
  end
170
170
  end
171
171
 
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper.rb")
2
2
 
3
3
  describe "'Data' source" do
4
4
  before :all do
5
- FakeWeb.register_uri("http://photos.tld/index.json", :response => File.join(SPEC_DIR, 'supports', 'flickr-photo.json'))
5
+ FakeWeb.register_uri(:get, "http://photos.tld/index.json", :response => File.join(SPEC_DIR, 'supports', 'flickr-photo.json'))
6
6
 
7
7
  @source = Smoke.data(:photos) do
8
8
  url "http://photos.tld/index.json", :type => :json
@@ -14,7 +14,7 @@ describe "'Data' source" do
14
14
  # it_should_behave_like "all sources"
15
15
 
16
16
  it "should have been activated" do
17
- Smoke[:photos].should(be_an_instance_of(Smoke::Source::Data))
17
+ Smoke[:photos].should(be_an_instance_of(Smoke::Data))
18
18
  end
19
19
 
20
20
  it "should be a list of things" do
@@ -43,7 +43,7 @@ describe "'Data' source" do
43
43
 
44
44
  describe "making a request to a web service without a correctly set content-type in return" do
45
45
  before :each do
46
- FakeWeb.register_uri("http://photos.tld/no-format", :response => File.join(SPEC_DIR, 'supports', 'flickr-photo.json'), :content_type => "text/plain")
46
+ FakeWeb.register_uri(:get, "http://photos.tld/no-format", :response => File.join(SPEC_DIR, 'supports', 'flickr-photo.json'), :content_type => "text/plain")
47
47
  end
48
48
 
49
49
  it "should fail" do
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper.rb")
2
2
 
3
3
  describe "Feed" do
4
4
  before :all do
5
- FakeWeb.register_uri("http://slashdot.org/index.rdf", :file => File.join(SPEC_DIR, 'supports', 'slashdot.xml'))
5
+ FakeWeb.register_uri(:get, "http://slashdot.org/index.rdf", :body => File.join(SPEC_DIR, 'supports', 'slashdot.xml'))
6
6
 
7
7
  @source = Smoke.feed(:slashdot) do
8
8
  url "http://slashdot.org/index.rdf"
@@ -17,7 +17,7 @@ describe "Feed" do
17
17
  # it_should_behave_like "all sources"
18
18
 
19
19
  it "should have been activated" do
20
- Smoke[:slashdot].should(be_an_instance_of(Smoke::Source::Feed))
20
+ Smoke[:slashdot].should(be_an_instance_of(Smoke::Feed))
21
21
  end
22
22
 
23
23
  it "should be a list of things" do
@@ -13,7 +13,7 @@ describe "Join" do
13
13
  end
14
14
 
15
15
  it "should be named in a_b_joined" do
16
- Smoke[:a_b_joined].should be_an_instance_of(Smoke::Source::Join)
16
+ Smoke[:a_b_joined].should be_an_instance_of(Smoke::Join)
17
17
  end
18
18
 
19
19
  it "should contain items from sources a and b" do
@@ -49,7 +49,7 @@ describe "Join" do
49
49
 
50
50
  describe "dispatching" do
51
51
  before :all do
52
- FakeWeb.register_uri("http://photos.tld", :response => File.join(SPEC_DIR, 'supports', 'flickr-photo.json'))
52
+ FakeWeb.register_uri(:get, "http://photos.tld", :response => File.join(SPEC_DIR, 'supports', 'flickr-photo.json'))
53
53
 
54
54
  Smoke.data(:should_dispatch) do
55
55
  url "http://photos.tld"
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper.rb")
2
2
 
3
3
  describe "YQL" do
4
4
  before :all do
5
- FakeWeb.register_uri("http://query.yahooapis.com:80/v1/public/yql?q=SELECT%20*%20FROM%20search.web%20WHERE%20query%20=%20'ruby'&format=json", :response => File.join(SPEC_DIR, 'supports', 'search-web.json.yql'))
5
+ FakeWeb.register_uri(:get, "http://query.yahooapis.com:80/v1/public/yql?q=SELECT%20*%20FROM%20search.web%20WHERE%20query%20=%20'ruby'&format=json", :response => File.join(SPEC_DIR, 'supports', 'search-web.json.yql'))
6
6
 
7
7
  @source = Smoke.yql(:search) do
8
8
  select :all
@@ -19,7 +19,7 @@ describe "YQL" do
19
19
  # it_should_behave_like "all sources"
20
20
 
21
21
  it "should have been activated" do
22
- Smoke[:search].should(be_an_instance_of(Smoke::Source::YQL))
22
+ Smoke[:search].should(be_an_instance_of(Smoke::YQL))
23
23
  end
24
24
 
25
25
  it "should be a list of things" do
@@ -28,7 +28,7 @@ describe "YQL" do
28
28
 
29
29
  describe "select" do
30
30
  before do
31
- FakeWeb.register_uri("http://query.yahooapis.com:80/v1/public/yql?q=SELECT%20url%20FROM%20search.images%20WHERE%20query%20=%20'amc%20pacer'&format=json", :response => File.join(SPEC_DIR, 'supports', 'amc_pacer.json.yql'))
31
+ FakeWeb.register_uri(:get, "http://query.yahooapis.com:80/v1/public/yql?q=SELECT%20url%20FROM%20search.images%20WHERE%20query%20=%20'amc%20pacer'&format=json", :response => File.join(SPEC_DIR, 'supports', 'amc_pacer.json.yql'))
32
32
 
33
33
  Smoke.yql(:pacer) do
34
34
  select :url
@@ -81,7 +81,7 @@ describe "YQL" do
81
81
 
82
82
  describe "yql definitions" do
83
83
  before do
84
- FakeWeb.register_uri("http://query.yahooapis.com:80/v1/public/yql?q=SELECT%20*%20FROM%20github.repo%20WHERE%20id%20=%20'benschwarz'%20AND%20repo%20=%20'smoke'&format=json&env=http://datatables.org/alltables.env", :response => File.join(SPEC_DIR, 'supports', 'datatables.yql'))
84
+ FakeWeb.register_uri(:get, "http://query.yahooapis.com:80/v1/public/yql?q=SELECT%20*%20FROM%20github.repo%20WHERE%20id%20=%20'benschwarz'%20AND%20repo%20=%20'smoke'&format=json&env=http://datatables.org/alltables.env", :response => File.join(SPEC_DIR, 'supports', 'datatables.yql'))
85
85
 
86
86
  Smoke.yql(:smoke) do
87
87
  use "http://datatables.org/alltables.env"
@@ -11,6 +11,15 @@ describe Smoke do
11
11
  Smoke[:a].should == @source_a
12
12
  end
13
13
 
14
+ it "should be a hash" do
15
+ Smoke.active_sources.should be_an_instance_of(Hash)
16
+ end
17
+
18
+ it "should have its name as the hash key" do
19
+ key = Smoke.active_sources.keys.first
20
+ Smoke.active_sources[key].name.should == key
21
+ end
22
+
14
23
  describe "accessing via method call" do
15
24
  it "should allow access to the sources via a method call" do
16
25
  Smoke.a.should == @source_a
@@ -58,4 +67,38 @@ describe Smoke do
58
67
  end
59
68
  end
60
69
  end
70
+
71
+ describe "exposed and concealed" do
72
+ before :all do
73
+ TestSource.source :exposed_by_default
74
+
75
+ TestSource.source :exposed do
76
+ expose
77
+ end
78
+
79
+ TestSource.source :concealed do
80
+ conceal
81
+ end
82
+ end
83
+
84
+ describe "exposed_sources" do
85
+ it "should be a hash" do
86
+ Smoke.exposed_sources.should be_an_instance_of(Hash)
87
+ end
88
+
89
+ it "should be exposed sources only" do
90
+ Smoke.exposed_sources.values.should_not include(Smoke.concealed)
91
+ end
92
+ end
93
+
94
+ describe "concealed_sources" do
95
+ it "should be a hash" do
96
+ Smoke.concealed_sources.should be_an_instance_of(Hash)
97
+ end
98
+
99
+ it "should be concealed sources only" do
100
+ Smoke.concealed_sources.values.should_not include(Smoke.exposed)
101
+ end
102
+ end
103
+ end
61
104
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smoke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.16
4
+ version: 0.5.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Schwarz
@@ -9,38 +9,38 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-29 00:00:00 +10:00
12
+ date: 2009-10-29 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: simple-rss
17
- type: :runtime
16
+ name: fakeweb
17
+ type: :development
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - "="
21
+ - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: "1.2"
23
+ version: 1.2.5
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
- name: json
26
+ name: simple-rss
27
27
  type: :runtime
28
28
  version_requirement:
29
29
  version_requirements: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.1.3
33
+ version: "1.2"
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
- name: fakeweb
36
+ name: json
37
37
  type: :runtime
38
38
  version_requirement:
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - "="
41
+ - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 1.2.5
43
+ version: 1.1.3
44
44
  version:
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: crack
@@ -129,6 +129,7 @@ files:
129
129
  - rdoc/rdoc-style.css
130
130
  - spec/core_ext/hash_spec.rb
131
131
  - spec/smoke/cache_spec.rb
132
+ - spec/smoke/input/xls_spec.rb
132
133
  - spec/smoke/origin_spec.rb
133
134
  - spec/smoke/output/xml_spec.rb
134
135
  - spec/smoke/request_spec.rb
@@ -143,6 +144,7 @@ files:
143
144
  - spec/supports/amc_pacer.json.yql
144
145
  - spec/supports/datatables.yql
145
146
  - spec/supports/flickr-photo.json
147
+ - spec/supports/gov_act_toliets.xls
146
148
  - spec/supports/gzip_response.txt
147
149
  - spec/supports/search-web.json.yql
148
150
  - spec/supports/search-web.xml.yql
@@ -179,6 +181,7 @@ summary: smoke is a Ruby based DSL that allows you to query web services such as
179
181
  test_files:
180
182
  - spec/core_ext/hash_spec.rb
181
183
  - spec/smoke/cache_spec.rb
184
+ - spec/smoke/input/xls_spec.rb
182
185
  - spec/smoke/origin_spec.rb
183
186
  - spec/smoke/output/xml_spec.rb
184
187
  - spec/smoke/request_spec.rb