fireeagle 0.0.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,67 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'redcloth'
5
- require 'syntax/convertors/html'
6
- require 'erb'
7
- require File.dirname(__FILE__) + '/../lib/fireeagle/version.rb'
8
-
9
- version = FireEagle::VERSION::STRING
10
- download = 'http://rubyforge.org/projects/fireeagle'
11
-
12
- class Fixnum
13
- def ordinal
14
- # teens
15
- return 'th' if (10..19).include?(self % 100)
16
- # others
17
- case self % 10
18
- when 1: return 'st'
19
- when 2: return 'nd'
20
- when 3: return 'rd'
21
- else return 'th'
22
- end
23
- end
24
- end
25
-
26
- class Time
27
- def pretty
28
- return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
29
- end
30
- end
31
-
32
- def convert_syntax(syntax, source)
33
- return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
34
- end
35
-
36
- if ARGV.length >= 1
37
- src, template = ARGV
38
- template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
39
-
40
- else
41
- puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
42
- exit!
43
- end
44
-
45
- template = ERB.new(File.open(template).read)
46
-
47
- title = nil
48
- body = nil
49
- File.open(src) do |fsrc|
50
- title_text = fsrc.readline
51
- body_text = fsrc.read
52
- syntax_items = []
53
- body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</>!m){
54
- ident = syntax_items.length
55
- element, syntax, source = $1, $2, $3
56
- syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
57
- "syntax-temp-#{ident}"
58
- }
59
- title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
60
- body = RedCloth.new(body_text).to_html
61
- body.gsub!(%r!(?:<pre><code>)?syntax-temp-(d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
62
- end
63
- stat = File.stat(src)
64
- created = stat.ctime
65
- modified = stat.mtime
66
-
67
- $stdout << template.result(binding)
@@ -1,30 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- context "The FireEagle class" do
4
-
5
- setup do
6
- @f = FireEagle::Base.new(:token => "foo", :secret => "bar")
7
- end
8
-
9
- specify "should require a secret and a token" do
10
- lambda { FireEagle::Base.new }.should.raise(FireEagle::ArgumentError)
11
- lambda { FireEagle::Base.new(:token => "foo") }.should.raise(FireEagle::ArgumentError)
12
- lambda { FireEagle::Base.new(:secret => "bar") }.should.raise(FireEagle::ArgumentError)
13
- lambda { FireEagle::Base.new(:token => "foo", :secret => "bar") }.should.not.raise(FireEagle::ArgumentError)
14
- end
15
-
16
- specify "should have token and secret readers" do
17
- @f.token.should.equal "foo"
18
- @f.secret.should.equal "bar"
19
- end
20
-
21
- specify "should contain FireEagle::Application class accessor" do
22
- @f.application.class.should.equal FireEagle::Application
23
- end
24
-
25
- specify "is able to stub itself (learning experience here)" do
26
- FireEagle::Base.stubs(:foo).returns("bar")
27
- FireEagle::Base.foo.should.equal "bar"
28
- end
29
-
30
- end
@@ -1,46 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- context "The FireEagle::Application class" do
4
-
5
- setup do
6
- @f = FireEagle::Base.new(:token => "foo", :secret => "bar")
7
- @application = @f.application
8
- @response = MockSuccess.new
9
- @error_response = <<-RESPONSE
10
- <ResultSet version="1.0">
11
- <Error>1</Error>
12
- <ErrorMessage>Something bad happened</ErrorMessage>
13
- </ResultSet>
14
- RESPONSE
15
- @token_response = <<-RESPONSE
16
- <rsp stat="ok">
17
- <token>1234</token>
18
- </rsp>
19
- RESPONSE
20
- end
21
-
22
- specify "should require a token for token exchange" do
23
- lambda { user = @application.exchange_token }.should.raise FireEagle::ArgumentError
24
- end
25
-
26
- specify "should return a FireEagle::User object when asked for a token exchange" do
27
- @response.expects(:body).returns(@token_response)
28
- Net::HTTP.expects(:get_response).returns(@response)
29
- user = @application.exchange_token(1234)
30
- user.should.be.an.instance_of FireEagle::User
31
- end
32
-
33
- specify "should raise an Exception for a bad token" do
34
- @response.expects(:body).returns(@error_response)
35
- Net::HTTP.expects(:get_response).returns(@response)
36
- lambda { user = @application.exchange_token(666) }.should.raise FireEagle::FireEagleException
37
- end
38
-
39
- specify "should provide a authorization url" do
40
- @application.authorize_url.should.equal "http://#{FireEagle::API_DOMAIN}/authorize.php?appid=foo&callback="
41
- end
42
-
43
- specify "should escape the callback url provided to authorize_url" do
44
- @application.authorize_url("one two").should.equal "http://#{FireEagle::API_DOMAIN}/authorize.php?appid=foo&callback=one+two"
45
- end
46
- end
@@ -1,97 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- context "The FireEagle::Location class" do
4
-
5
- setup do
6
- @location_response = <<-RESPONSE
7
- <ResultSet version="1.0">
8
- <Error>0</Error>
9
- <ErrorMessage>No error</ErrorMessage>
10
- <Locale>us_US</Locale>
11
- <Quality>0</Quality>
12
- <Found>1</Found>
13
- <Result>
14
- <updatetime> 2007-06-14T22:43:29Z</updatetime>
15
- <quality>60</quality>
16
- <latitude>37.872236</latitude>
17
- <longitude>-122.244972</longitude>
18
- <offsetlat>37.872238</offsetlat>
19
- <offsetlon>-122.218628</offsetlon>
20
- <radius>3200</radius>
21
- <boundingbox>
22
- <north>37.884701</north>
23
- <south>37.859772</south>
24
- <east>-122.216743</east>
25
- <west>-122.273201</west>
26
- </boundingbox>
27
- <name/>
28
- <line1/>
29
- <line2>Berkeley, CA 94704</line2>
30
- <line3/>
31
- <line4>United States</line4>
32
- <house/>
33
- <street/>
34
- <xstreet/>
35
- <unittype/>
36
- <unit/>
37
- <postal>94704</postal>
38
- <neighborhood/>
39
- <city>Berkeley</city>
40
- <county>Alameda County</county>
41
- <state>California</state>
42
- <country>United States</country>
43
- <countrycode>US</countrycode>
44
- <statecode>CA</statecode>
45
- <countycode/>
46
- <timezone>America/Los_Angeles</timezone>
47
- </Result>
48
- </ResultSet>
49
- RESPONSE
50
- @error_response = <<-RESPONSE
51
- <ResultSet version="1.0">
52
- <Error>1</Error>
53
- <ErrorMessage>Something bad happened</ErrorMessage>
54
- </ResultSet>
55
- RESPONSE
56
- end
57
-
58
- specify "Requires all or none of :lat, :long" do
59
- lambda { FireEagle::Location.new(:lat => 1) }.should.raise FireEagle::ArgumentError
60
- lambda { FireEagle::Location.new(:lat => 1, :long => 2) }.should.not.raise FireEagle::ArgumentError
61
- end
62
-
63
- specify "Requires all or none of :mnc, :mcc, :lac, :cellid" do
64
- lambda { FireEagle::Location.new(:mcc => 123, :lac => "whatever", :cellid => true) }.should.raise FireEagle::ArgumentError
65
- lambda { FireEagle::Location.new(:mcc => 123, :mnc => 123123, :lac => "whatever", :cellid => true) }.should.not.raise FireEagle::ArgumentError
66
- end
67
-
68
- specify "Requires all or none of :street1, :street2" do
69
- lambda { FireEagle::Location.new(:street1 => "easy street") }.should.raise FireEagle::ArgumentError
70
- end
71
-
72
- specify "Requires :postal or :city with :street1 and :street2" do
73
- lambda { FireEagle::Location.new(:street1 => "easy street", :street2 => "lazy lane") }.should.raise FireEagle::ArgumentError
74
- lambda { FireEagle::Location.new(:street1 => "easy street", :street2 => "lazy lane", :city => "anytown", :country => "US") }.should.not.raise FireEagle::ArgumentError
75
- lambda { FireEagle::Location.new(:street1 => "easy street", :street2 => "lazy lane", :postal => 12345) }.should.not.raise FireEagle::ArgumentError
76
- end
77
-
78
- specify "Requires :city or :postal with :addr" do
79
- lambda { FireEagle::Location.new(:addr => "1 easy street") }.should.raise FireEagle::ArgumentError
80
- lambda { FireEagle::Location.new(:addr => "1 easy street", :city => "anytown", :country => "US") }.should.not.raise FireEagle::ArgumentError
81
- lambda { FireEagle::Location.new(:addr => "1 easy street", :postal => 12345) }.should.not.raise FireEagle::ArgumentError
82
- end
83
-
84
- specify "Requires :state, :country, or :postal with :city" do
85
- lambda { FireEagle::Location.new(:city => "armuchee") }.should.raise FireEagle::ArgumentError
86
- lambda { FireEagle::Location.new(:city => "armuchee", :state => "GA") }.should.not.raise FireEagle::ArgumentError
87
- lambda { FireEagle::Location.new(:city => "armuchee", :postal => 12345) }.should.not.raise FireEagle::ArgumentError
88
- lambda { FireEagle::Location.new(:city => "armuchee", :country => "US") }.should.not.raise FireEagle::ArgumentError
89
- end
90
-
91
- specify "Requires :country with :postal if not in US" do
92
- lambda { FireEagle::Location.new(:postal => "a49", :country => "Armenia") }.should.raise FireEagle::ArgumentError
93
- lambda { FireEagle::Location.new(:postal => 30605, :country => "US") }.should.not.raise FireEagle::ArgumentError
94
- lambda { FireEagle::Location.new(:postal => 30605) }.should.not.raise FireEagle::ArgumentError
95
- end
96
-
97
- end
@@ -1,103 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- context "The FireEagle::User class" do
4
-
5
- setup do
6
- @f = FireEagle::Base.new(:token => "foo", :secret => "bar")
7
- @error_response = <<-RESPONSE
8
- <ResultSet version="1.0">
9
- <Error>1</Error>
10
- <ErrorMessage>Something bad happened</ErrorMessage>
11
- </ResultSet>
12
- RESPONSE
13
- @token_response = <<-RESPONSE
14
- <rsp stat="ok">
15
- <token>1234</token>
16
- </rsp>
17
- RESPONSE
18
- @location_response = <<-RESPONSE
19
- <ResultSet version="1.0">
20
- <Error>0</Error>
21
- <ErrorMessage>No error</ErrorMessage>
22
- <Locale>us_US</Locale>
23
- <Quality>0</Quality>
24
- <Found>1</Found>
25
- <Result>
26
- <updatetime> 2007-06-14T22:43:29Z</updatetime>
27
- <quality>60</quality>
28
- <latitude>37.872236</latitude>
29
- <longitude>-122.244972</longitude>
30
- <offsetlat>37.872238</offsetlat>
31
- <offsetlon>-122.218628</offsetlon>
32
- <radius>3200</radius>
33
- <boundingbox>
34
- <north>37.884701</north>
35
- <south>37.859772</south>
36
- <east>-122.216743</east>
37
- <west>-122.273201</west>
38
- </boundingbox>
39
- <name/>
40
- <line1/>
41
- <line2>Berkeley, CA 94704</line2>
42
- <line3/>
43
- <line4>United States</line4>
44
- <house/>
45
- <street/>
46
- <xstreet/>
47
- <unittype/>
48
- <unit/>
49
- <postal>94704</postal>
50
- <neighborhood/>
51
- <city>Berkeley</city>
52
- <county>Alameda County</county>
53
- <state>California</state>
54
- <country>United States</country>
55
- <countrycode>US</countrycode>
56
- <statecode>CA</statecode>
57
- <countycode/>
58
- <timezone>America/Los_Angeles</timezone>
59
- </Result>
60
- </ResultSet>
61
- RESPONSE
62
- @update_response = <<-RESPONSE
63
- <ResultSet version="1.0">
64
- <Error>0</Error>
65
- <ErrorMessage>No error</ErrorMessage>
66
- </ResultSet>
67
- RESPONSE
68
- @response = MockSuccess.new
69
- @response.expects(:body).returns(@token_response)
70
- Net::HTTP.expects(:get_response).returns(@response)
71
- @user = @f.application.exchange_token(1234)
72
- end
73
-
74
- specify "should have a token accessor" do
75
- @user.should.be.an.instance_of FireEagle::User
76
- @user.token.should.equal "1234"
77
- end
78
-
79
- specify "should be able to create a new user with a token" do
80
- @newuser = FireEagle::User.new(@f, 1234)
81
- @newuser.token.should.be.equal "1234"
82
- end
83
-
84
-
85
- specify "should return a FireEagle::Location class when asked for a location" do
86
- #get the location
87
- @response.expects(:body).returns(@location_response)
88
- Net::HTTP.expects(:get_response).returns(@response)
89
- @user.location.should.be.an.instance_of FireEagle::Location
90
- end
91
-
92
-
93
- specify "should be able to set a location" do
94
- #set the location
95
- @response.expects(:body).returns(@update_response)
96
- Net::HTTP.expects(:get_response).returns(@response)
97
- @l = FireEagle::Location.new(:country => "Belize")
98
- @set_location = (@user.location = @l)
99
- @set_location.should.be.an.instance_of FireEagle::Location
100
- @set_location.should.be.equal @l
101
- end
102
-
103
- end
@@ -1,14 +0,0 @@
1
- %w[ test/unit rubygems test/spec mocha hpricot ].each { |f|
2
- begin
3
- require f
4
- rescue LoadError
5
- abort "Unable to load required gem for test: #{f}"
6
- end
7
- }
8
-
9
- require File.dirname(__FILE__) + '/../lib/fireeagle'
10
-
11
- class MockSuccess < Net::HTTPSuccess #:nodoc: all
12
- def initialize
13
- end
14
- end