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 +1 -6
- data/VERSION.yml +2 -2
- data/lib/smoke/request.rb +3 -3
- data/lib/smoke/source/data.rb +9 -5
- data/lib/smoke/source/feed.rb +1 -1
- data/lib/smoke/source/yql.rb +0 -1
- data/spec/smoke/origin_spec.rb +1 -1
- data/spec/smoke/request_spec.rb +14 -2
- data/spec/smoke/source/data_spec.rb +23 -1
- data/spec/supports/flickr-photo.json +1 -1
- metadata +4 -3
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
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,
|
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
|
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!
|
data/lib/smoke/source/data.rb
CHANGED
@@ -20,14 +20,18 @@ module Smoke
|
|
20
20
|
# end
|
21
21
|
class Data < Origin
|
22
22
|
attr_reader :request
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
data/lib/smoke/source/feed.rb
CHANGED
@@ -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
|
data/lib/smoke/source/yql.rb
CHANGED
data/spec/smoke/origin_spec.rb
CHANGED
data/spec/smoke/request_spec.rb
CHANGED
@@ -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
|
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/
|
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.
|
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-
|
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.
|
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
|