benschwarz-smoke 0.3.10 → 0.3.11

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -69,15 +69,10 @@ Integrity [is running for smoke](http://integrity.ffolio.net/smoke)
69
69
 
70
70
 
71
71
  ### TODO (working on, just mental notes)
72
-
73
- * Secrets
74
- * Checkout experimental fakeweb version to stub out the yql specs
75
-
76
72
  #### Later / maybe
77
73
  * YQL w/oAuth
78
74
  * YQL Subqueries?
79
75
  * Implement basic auth for sources
80
- * Allow for sources to explicitly set the content type being returned for those stupid content providers
81
76
 
82
77
 
83
78
  #### For wiki pages (docs, later)
@@ -90,7 +85,7 @@ Integrity [is running for smoke](http://integrity.ffolio.net/smoke)
90
85
  * Sort, Reverse
91
86
  * Keep, Discard
92
87
  * Truncate
93
-
88
+ * Manually setting the content type for a url
94
89
 
95
90
  ### Copyright
96
91
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 10
3
- :major: 0
4
2
  :minor: 3
3
+ :patch: 11
4
+ :major: 0
data/lib/smoke/request.rb CHANGED
@@ -12,7 +12,7 @@ module Smoke
12
12
  SUPPORTED_TYPES = %w(json xml javascript)
13
13
  attr_reader :uri, :content_type, :body, :type
14
14
 
15
- def initialize(uri, *options)
15
+ def initialize(uri, options = {})
16
16
  @uri, @options = uri, options
17
17
  dispatch
18
18
  end
@@ -29,7 +29,7 @@ module Smoke
29
29
  @body = request
30
30
  }.join
31
31
 
32
- present! unless @options.include?(:raw_response)
32
+ present! unless @options[:raw_response]
33
33
 
34
34
  rescue RestClient::Exception => e
35
35
  Failure.new(@uri, e)
@@ -41,7 +41,7 @@ module Smoke
41
41
  end
42
42
 
43
43
  def set_type
44
- @type = (SUPPORTED_TYPES.detect{|t| @content_type =~ /#{t}/ } || "unknown").to_sym
44
+ @type = @options[:type] || (SUPPORTED_TYPES.detect{|t| @content_type =~ /#{t}/ } || "unknown").to_sym
45
45
  end
46
46
 
47
47
  def parse!
@@ -20,14 +20,18 @@ module Smoke
20
20
  # end
21
21
  class Data < Origin
22
22
  attr_reader :request
23
-
24
- def url(source_url)
25
- @url = source_url
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
26
30
  end
27
31
 
28
32
  protected
29
- def dispatch
30
- @request = Smoke::Request.new(@url)
33
+ def dispatch
34
+ @request = Smoke::Request.new(@url, @options)
31
35
  self.items = @request.body
32
36
  end
33
37
  end
@@ -16,7 +16,7 @@ module Smoke
16
16
 
17
17
  protected
18
18
  def dispatch
19
- @requests = @feeds.map{|f| Smoke::Request.new(f, :raw_response) }
19
+ @requests = @feeds.map{|f| Smoke::Request.new(f, {:raw_response => true}) }
20
20
  self.items = @requests.map{|r| ::SimpleRSS.parse(r.body).items }.flatten
21
21
  end
22
22
  end
@@ -23,7 +23,6 @@ module Smoke
23
23
  def select(what = :all)
24
24
  @select = what.join(",") and return if what.is_a? Array
25
25
  @select = "*" and return if what == :all
26
- @select = what.to_s
27
26
  end
28
27
 
29
28
  # from corresponds to the from fragment of the YQL query
@@ -146,7 +146,7 @@ describe Smoke::Origin do
146
146
 
147
147
  Smoke.data :feed_preperation_call_order do
148
148
  prepare do
149
- url "http://domain.tld/#{username}/feed"
149
+ url "http://domain.tld/#{username}/feed", :type => :json
150
150
  end
151
151
 
152
152
  path :photos, :photo
@@ -13,11 +13,11 @@ describe Smoke::Request do
13
13
  end
14
14
 
15
15
  it "should have a content type" do
16
- @request.content_type.should =~ /text\/json/
16
+ @request.content_type.should == "text/plain; charset=utf-8"
17
17
  end
18
18
 
19
19
  it "should be a raw string response" do
20
- request = Smoke::Request.new(@url, :raw_response)
20
+ request = Smoke::Request.new(@url, :raw_response => true)
21
21
  request.body.should == "{\"photos\":{\"page\":1, \"pages\":1, \"perpage\":100, \"total\":\"2\", \"photo\":[{\"id\":\"3443335843\", \"owner\":\"36821533@N00\", \"secret\":\"5a15f0bfb9\", \"server\":\"3305\", \"farm\":4, \"title\":\"How I roll\", \"ispublic\":1, \"isfriend\":0, \"isfamily\":0}, {\"id\":\"3345220961\", \"owner\":\"36821533@N00\", \"secret\":\"a1dd2b9eca\", \"server\":\"3581\", \"farm\":4, \"title\":\"My desk\", \"ispublic\":1, \"isfriend\":0, \"isfamily\":0}]}, \"stat\":\"ok\"}"
22
22
  end
23
23
 
@@ -34,4 +34,16 @@ describe Smoke::Request do
34
34
  request.body.should == "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n\t\"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n\t<head>\n\t\t<title>New street represent</title>\n\t\t<style type=\"text/css\" media=\"screen\">\n\t\t\tbody {\n\t\t\t\tfont-family: helvetica, arial, sans-serif;\n\t\t\t\tfont-size: 2em;\n\t\t\t\tbackground-color: black;\n\t\t\t\tletter-spacing: -3px;\n\t\t\t\tmargin: 0 auto;\n\t\t\t}\n\t\t\th1 {\n\t\t\t\tposition: absolute;\n\t\t\t\tright: 0;\n\t\t\t\tbackground-color: #666;\n\t\t\t\twidth: 4em;\n\t\t\t}\n\t\t</style>\n\t</head>\n\t<body>\n\t\t<h1>Massive</h1>\n\t</body>\n</html>"
35
35
  end
36
36
  end
37
+
38
+ describe "format returns" do
39
+ it "should have a content type of :manual" do
40
+ request = Smoke::Request.new(@url, :type => :manual)
41
+ request.type.should == :manual
42
+ end
43
+
44
+ it "should have a content type of unknown" do
45
+ request = Smoke::Request.new(@url)
46
+ request.type.should == :unknown
47
+ end
48
+ end
37
49
  end
@@ -5,7 +5,7 @@ describe "'Data' source" do
5
5
  FakeWeb.register_uri("http://photos.tld/index.json", :response => File.join(SPEC_DIR, 'supports', 'flickr-photo.json'))
6
6
 
7
7
  @source = Smoke.data(:photos) do
8
- url "http://photos.tld/index.json"
8
+ url "http://photos.tld/index.json", :type => :json
9
9
 
10
10
  path :photos, :photo
11
11
  end
@@ -40,4 +40,26 @@ describe "'Data' source" do
40
40
  end
41
41
  end
42
42
  end
43
+
44
+ describe "making a request to a web service without a correctly set content-type in return" do
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")
47
+ end
48
+
49
+ it "should fail" do
50
+ @source = Smoke.data(:flickr) do
51
+ url "http://photos.tld/no-format"
52
+ path :photos, :photo
53
+ end
54
+ lambda { @source.output }.should raise_error
55
+ end
56
+
57
+ it "should not fail" do
58
+ @source = Smoke.data(:flickr) do
59
+ url "http://photos.tld/no-format", :type => :json
60
+ path :photos, :photo
61
+ end
62
+ lambda { @source.output }.should_not raise_error
63
+ end
64
+ end
43
65
  end
@@ -2,6 +2,6 @@ HTTP/1.1 200 OK
2
2
  Date: Mon, 1 Jan 2000 01:00:00 GMT
3
3
  Vary: Accept-Encoding
4
4
  Connection: close
5
- Content-Type: text/json; charset=utf-8
5
+ Content-Type: text/plain; charset=utf-8
6
6
 
7
7
  {"photos":{"page":1, "pages":1, "perpage":100, "total":"2", "photo":[{"id":"3443335843", "owner":"36821533@N00", "secret":"5a15f0bfb9", "server":"3305", "farm":4, "title":"How I roll", "ispublic":1, "isfriend":0, "isfamily":0}, {"id":"3345220961", "owner":"36821533@N00", "secret":"a1dd2b9eca", "server":"3581", "farm":4, "title":"My desk", "ispublic":1, "isfriend":0, "isfamily":0}]}, "stat":"ok"}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benschwarz-smoke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.10
4
+ version: 0.3.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Schwarz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-25 00:00:00 -07:00
12
+ date: 2009-07-31 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -90,6 +90,7 @@ files:
90
90
  - LICENSE
91
91
  has_rdoc: true
92
92
  homepage: http://github.com/benschwarz/smoke
93
+ licenses:
93
94
  post_install_message:
94
95
  rdoc_options:
95
96
  - --inline-source
@@ -111,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
112
  requirements: []
112
113
 
113
114
  rubyforge_project:
114
- rubygems_version: 1.2.0
115
+ rubygems_version: 1.3.5
115
116
  signing_key:
116
117
  specification_version: 3
117
118
  summary: smoke is a DSL that allows you to take data from YQL, RSS / Atom