appengine-apis 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -1
- data/lib/appengine-apis.rb +1 -1
- data/lib/appengine-apis/local_boot.rb +1 -0
- data/lib/appengine-apis/sdk.rb +2 -98
- data/lib/appengine-apis/testing.rb +15 -6
- data/lib/appengine-apis/urlfetch.rb +27 -28
- data/spec/urlfetch_spec.rb +4 -4
- metadata +80 -67
data/Rakefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
1
|
+
%w[rubygems rake rake/clean fileutils newgem rubigen hoe].each { |f| require f }
|
2
2
|
require File.dirname(__FILE__) + '/lib/appengine-apis'
|
3
3
|
|
4
4
|
# set up pretty rdoc if possible
|
@@ -21,6 +21,7 @@ $hoe = Hoe.new('appengine-apis', AppEngine::VERSION) do |p|
|
|
21
21
|
p.extra_dev_deps = [
|
22
22
|
['newgem', ">= #{::Newgem::VERSION}"]
|
23
23
|
]
|
24
|
+
p.readme_file = 'README.rdoc'
|
24
25
|
|
25
26
|
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
26
27
|
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
data/lib/appengine-apis.rb
CHANGED
data/lib/appengine-apis/sdk.rb
CHANGED
@@ -16,101 +16,5 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
module AppEngine
|
22
|
-
|
23
|
-
DEV_APPSERVER = 'com.google.appengine.tools.development.DevAppServerMain'
|
24
|
-
|
25
|
-
# Helper methods to locate the App Engine SDK and add it to the class path.
|
26
|
-
module SDK
|
27
|
-
class << self
|
28
|
-
|
29
|
-
# Tries to load the Kickstart class.
|
30
|
-
def load_kickstart
|
31
|
-
tools = %w{lib appengine-tools-api.jar}
|
32
|
-
cp = java.lang.System.get_property('java.class.path')
|
33
|
-
jar = sdk_path(*tools)
|
34
|
-
sep = java.io.File::pathSeparator
|
35
|
-
java.lang.System.set_property('java.class.path', "#{jar}#{sep}#{cp}")
|
36
|
-
with_jars(tools) do
|
37
|
-
return Java.ComGoogleAppengineTools.KickStart
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# Tries to load the ApiProxy class.
|
42
|
-
def load_apiproxy
|
43
|
-
with_jars(%w{lib impl appengine-api.jar}) do
|
44
|
-
return Java.ComGoogleApphostingApi.ApiProxy
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# Tries to load the ApiProxyLocalFactory class.
|
49
|
-
def load_local_apiproxy_factory
|
50
|
-
with_jars(%w{lib shared appengine-local-runtime-shared.jar},
|
51
|
-
%w{lib impl appengine-api-stubs.jar},
|
52
|
-
%w{lib impl appengine-local-runtime.jar}
|
53
|
-
) do
|
54
|
-
return Java.ComGoogleAppengineToolsDevelopment.ApiProxyLocalFactory
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def load_appcfg
|
59
|
-
with_jars(%w{lib appengine-tools-api.jar}) do
|
60
|
-
return Java.ComGoogleAppengineToolsAdmin.AppCfg
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def with_jars(*jars) # :nodoc:
|
65
|
-
begin
|
66
|
-
failed = false
|
67
|
-
yield
|
68
|
-
rescue NameError => ex
|
69
|
-
if failed
|
70
|
-
raise ex
|
71
|
-
else
|
72
|
-
failed = true
|
73
|
-
jars.each do |jar|
|
74
|
-
$CLASSPATH << sdk_path(*jar)
|
75
|
-
end
|
76
|
-
retry
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
# Tries to find the Google App Engine SDK for Java.
|
82
|
-
#
|
83
|
-
# Looks for appcfg.sh in these directories (in order):
|
84
|
-
# - ENV['APPENGINE_JAVA_SDK']/bin
|
85
|
-
# - each directory in ENV['PATH']
|
86
|
-
# - '/usr/local/appengine-java-sdk/bin'
|
87
|
-
# - 'c:\appengine-java-sdk\bin'
|
88
|
-
#
|
89
|
-
# Returns File.join(sdk_directory, *pieces)
|
90
|
-
#
|
91
|
-
def sdk_path(*pieces)
|
92
|
-
unless @sdk_path
|
93
|
-
begin
|
94
|
-
require 'reggae'
|
95
|
-
@sdk_path = AppEngine::Jars::Path
|
96
|
-
rescue Exception
|
97
|
-
base_path = File.join(ENV['APPENGINE_JAVA_SDK'] || '', 'bin')
|
98
|
-
exec_paths = ENV['PATH'].split(File::PATH_SEPARATOR)
|
99
|
-
exec_paths << '/usr/local/appengine-java-sdk/bin'
|
100
|
-
exec_paths << 'c:\appengine-java-sdk\bin'
|
101
|
-
|
102
|
-
while !exec_paths.empty?
|
103
|
-
if File.exist?(File.join(base_path, 'appcfg.sh'))
|
104
|
-
@sdk_path = File.dirname(base_path)
|
105
|
-
return File.join(@sdk_path, *pieces)
|
106
|
-
end
|
107
|
-
base_path = exec_paths.shift
|
108
|
-
end
|
109
|
-
raise "Unable to locate the Google App Engine SDK for Java."
|
110
|
-
end
|
111
|
-
end
|
112
|
-
File.join(@sdk_path, *pieces)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
19
|
+
$stderr.puts '"appengine-apis/sdk" is deprecated. Use "appengine-sdk"'
|
20
|
+
require 'appengine-sdk'
|
@@ -109,7 +109,13 @@ module AppEngine
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def factory # :nodoc:
|
112
|
-
|
112
|
+
puts caller(0).inspect
|
113
|
+
@factory = begin
|
114
|
+
Java.ComGoogleAppengineToolsDevelopment.ApiProxyLocalFactory.new
|
115
|
+
rescue
|
116
|
+
require 'appengine-sdk'
|
117
|
+
AppEngine::SDK.load_local_apiproxy_factory.new
|
118
|
+
end
|
113
119
|
end
|
114
120
|
|
115
121
|
# The application directory, or '.' if not set.
|
@@ -178,6 +184,10 @@ module AppEngine
|
|
178
184
|
# require 'appengine-apis/local_boot'
|
179
185
|
#
|
180
186
|
def boot(app_dir=nil)
|
187
|
+
if AppEngine::ApiProxy.current_environment &&
|
188
|
+
AppEngine::ApiProxy.delegate
|
189
|
+
return
|
190
|
+
end
|
181
191
|
app_dir ||= ENV['APPLICATION_ROOT'] || '.'
|
182
192
|
unless AppEngine::ApiProxy.current_environment
|
183
193
|
env = install_test_env
|
@@ -193,12 +203,11 @@ module AppEngine
|
|
193
203
|
# Looks for app.yaml or WEB-INF/appengine-web.xml in +app_dir+
|
194
204
|
# and parses the application id.
|
195
205
|
def get_app_id(app_dir)
|
206
|
+
require 'appengine-rack'
|
207
|
+
app_id = AppEngine::Rack.app.id
|
208
|
+
return app_id if app_id
|
196
209
|
aeweb_path = File.join(app_dir, 'WEB-INF', 'appengine-web.xml')
|
197
|
-
|
198
|
-
if File.exist?(app_yaml_path)
|
199
|
-
app_yaml = YAML.load(File.open(app_yaml_path))
|
200
|
-
return app_yaml['application']
|
201
|
-
elsif File.exist?(aeweb_path)
|
210
|
+
if File.exist?(aeweb_path)
|
202
211
|
require 'rexml/document'
|
203
212
|
aeweb = REXML::Document.new(File.new(aeweb_path))
|
204
213
|
return aeweb.root.elements['application'].text
|
@@ -172,38 +172,37 @@ module AppEngine
|
|
172
172
|
end
|
173
173
|
|
174
174
|
|
175
|
-
#
|
176
|
-
|
177
|
-
#
|
178
|
-
# To replace the standard implementation throughout your app you can do:
|
179
|
-
# require 'appengine-apis/urlfetch'
|
180
|
-
# Net::HTTP = AppEngine::URLFetch::HTTP
|
181
|
-
class HTTP < Net::HTTP
|
182
|
-
alias connect on_connect
|
183
|
-
|
184
|
-
def request(req, body=nil, &block)
|
185
|
-
begin
|
186
|
-
proto = use_ssl? ? 'https' : 'http'
|
187
|
-
url = "#{proto}://#{addr_port}#{req.path}"
|
188
|
-
options = {
|
189
|
-
:payload => body,
|
190
|
-
:follow_redirects => false,
|
191
|
-
:allow_truncated => true,
|
192
|
-
:method => req.method,
|
193
|
-
:headers => req
|
194
|
-
}
|
195
|
-
res = URLFetch.fetch(url, options)
|
196
|
-
end while res.kind_of?(Net::HTTPContinue)
|
197
|
-
res.reading_body(nil, req.response_body_permitted?) {
|
198
|
-
yield res if block_given?
|
199
|
-
}
|
200
|
-
return res
|
201
|
-
end
|
202
|
-
end
|
175
|
+
# Deprecated alias for Net::HTTP, for backwards compatibility.
|
176
|
+
HTTP = Net::HTTP
|
203
177
|
end
|
204
178
|
end
|
205
179
|
|
206
180
|
module Net # :nodoc:
|
181
|
+
# Monkey patch Net::HTTP to makes requests using Google App Engine's
|
182
|
+
# URLFetch Service.
|
183
|
+
class HTTP
|
184
|
+
alias connect on_connect
|
185
|
+
|
186
|
+
def request(req, body=nil, &block)
|
187
|
+
begin
|
188
|
+
proto = use_ssl? ? 'https' : 'http'
|
189
|
+
url = "#{proto}://#{addr_port}#{req.path}"
|
190
|
+
options = {
|
191
|
+
:payload => body,
|
192
|
+
:follow_redirects => false,
|
193
|
+
:allow_truncated => true,
|
194
|
+
:method => req.method,
|
195
|
+
:headers => req
|
196
|
+
}
|
197
|
+
res = AppEngine::URLFetch.fetch(url, options)
|
198
|
+
end while res.kind_of?(Net::HTTPContinue)
|
199
|
+
res.reading_body(nil, req.response_body_permitted?) {
|
200
|
+
yield res if block_given?
|
201
|
+
}
|
202
|
+
return res
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
207
206
|
class HTTPResponse # :nodoc:
|
208
207
|
alias stream_check_without_urlfetch stream_check
|
209
208
|
|
data/spec/urlfetch_spec.rb
CHANGED
@@ -104,7 +104,7 @@ describe AppEngine::URLFetch do
|
|
104
104
|
# TODO can't read fetch options, so there's no way to tell if they're set
|
105
105
|
end
|
106
106
|
|
107
|
-
describe
|
107
|
+
describe Net::HTTP do
|
108
108
|
HTTPRequest = com.google.appengine.api.urlfetch.HTTPRequest
|
109
109
|
|
110
110
|
before :each do
|
@@ -129,13 +129,13 @@ describe AppEngine::URLFetch::HTTP do
|
|
129
129
|
fetch_and_return(200) do |req|
|
130
130
|
req.url.to_string.should == @url
|
131
131
|
end
|
132
|
-
|
132
|
+
Net::HTTP.get URI.parse(@url)
|
133
133
|
end
|
134
134
|
|
135
135
|
|
136
136
|
it "should read body" do
|
137
137
|
fetch_and_return(200, 'foo')
|
138
|
-
|
138
|
+
Net::HTTP.get(URI.parse(@url)).should == 'foo'
|
139
139
|
end
|
140
140
|
|
141
141
|
it "should support https" do
|
@@ -145,7 +145,7 @@ describe AppEngine::URLFetch::HTTP do
|
|
145
145
|
end
|
146
146
|
|
147
147
|
uri = URI.parse(@url)
|
148
|
-
http =
|
148
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
149
149
|
http.use_ssl = true
|
150
150
|
http.get(uri.path).body.should == 'secure'
|
151
151
|
end
|
metadata
CHANGED
@@ -1,42 +1,68 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
name: appengine-apis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Brown
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-27 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: newgem
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.3.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hoe
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.11.0
|
34
|
+
version:
|
35
|
+
description: |-
|
36
|
+
APIs and utilities for using JRuby on Google App Engine.
|
37
|
+
|
38
|
+
To load the API stubs in IRB simply
|
39
|
+
require 'rubygems'
|
40
|
+
require 'appengine-apis/local_boot'
|
41
|
+
|
42
|
+
This will configure access to the same Datastore as running
|
43
|
+
|
44
|
+
$ dev_appserver.sh .
|
45
|
+
|
46
|
+
See these classes for an overview of each API:
|
47
|
+
- AppEngine::Logger
|
48
|
+
- AppEngine::Testing
|
49
|
+
- AppEngine::Users
|
50
|
+
- AppEngine::Mail
|
51
|
+
- AppEngine::Memcache
|
52
|
+
- AppEngine::URLFetch
|
53
|
+
- AppEngine::Datastore
|
54
|
+
|
55
|
+
Unless you're implementing your own ORM, you probably want to use the
|
56
|
+
DataMapper API instead of the lower level AppEngine::Datastore API.
|
8
57
|
email:
|
9
58
|
- ribrdb@gmail.com
|
10
|
-
|
59
|
+
executables: []
|
60
|
+
|
61
|
+
extensions: []
|
11
62
|
|
12
|
-
summary: APIs and utilities for using JRuby on Google App Engine
|
13
|
-
post_install_message:
|
14
63
|
extra_rdoc_files:
|
15
64
|
- History.txt
|
16
65
|
- Manifest.txt
|
17
|
-
- README.rdoc
|
18
|
-
homepage: http://code.google.com/p/appengine-jruby
|
19
|
-
signing_key:
|
20
|
-
name: appengine-apis
|
21
|
-
rdoc_options:
|
22
|
-
- --main
|
23
|
-
- README.rdoc
|
24
|
-
rubyforge_project: appengine-jruby
|
25
|
-
autorequire:
|
26
|
-
licenses: []
|
27
|
-
|
28
|
-
executables: []
|
29
|
-
|
30
|
-
description: "APIs and utilities for using JRuby on Google App Engine.\n\nTo load \
|
31
|
-
the API stubs in IRB simply\n require 'rubygems'\n require 'appengine-apis/local_boot'\n\
|
32
|
-
\nThis will configure access to the same Datastore as running\n\n $ dev_appserver.sh \
|
33
|
-
.\n\nSee these classes for an overview of each API:\n- AppEngine::Logger\n- AppEngine::Testing\n\
|
34
|
-
- AppEngine::Users\n- AppEngine::Mail\n- AppEngine::Memcache\n- AppEngine::URLFetch\n\
|
35
|
-
- AppEngine::Datastore\n\nUnless you're implementing your own ORM, you probably \
|
36
|
-
want to use the\nDataMapper API instead of the lower level AppEngine::Datastore \
|
37
|
-
API."
|
38
|
-
specification_version: 3
|
39
|
-
default_executable:
|
40
66
|
files:
|
41
67
|
- History.txt
|
42
68
|
- Manifest.txt
|
@@ -68,47 +94,34 @@ files:
|
|
68
94
|
- spec/urlfetch_spec.rb
|
69
95
|
- spec/users_spec.rb
|
70
96
|
- tasks/rspec.rake
|
97
|
+
has_rdoc: true
|
98
|
+
homepage: http://code.google.com/p/appengine-jruby
|
99
|
+
licenses: []
|
100
|
+
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options:
|
103
|
+
- --main
|
104
|
+
- README.rdoc
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: "0"
|
112
|
+
version:
|
71
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
114
|
requirements:
|
73
|
-
- -
|
115
|
+
- - ">="
|
74
116
|
- !ruby/object:Gem::Version
|
75
117
|
version: "0"
|
76
118
|
version:
|
77
|
-
extensions: []
|
78
|
-
|
79
|
-
rubygems_version: 1.3.3
|
80
119
|
requirements: []
|
81
120
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
121
|
+
rubyforge_project: appengine-jruby
|
122
|
+
rubygems_version: 1.3.5
|
123
|
+
signing_key:
|
124
|
+
specification_version: 3
|
125
|
+
summary: APIs and utilities for using JRuby on Google App Engine
|
86
126
|
test_files: []
|
87
127
|
|
88
|
-
version: !ruby/object:Gem::Version
|
89
|
-
version: 0.0.5
|
90
|
-
require_paths:
|
91
|
-
- lib
|
92
|
-
dependencies:
|
93
|
-
- !ruby/object:Gem::Dependency
|
94
|
-
version_requirements: !ruby/object:Gem::Requirement
|
95
|
-
requirements:
|
96
|
-
- - '>='
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
version: 1.3.0
|
99
|
-
version:
|
100
|
-
type: :development
|
101
|
-
version_requirement:
|
102
|
-
name: newgem
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
requirements:
|
106
|
-
- - '>='
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
version: 1.8.0
|
109
|
-
version:
|
110
|
-
type: :development
|
111
|
-
version_requirement:
|
112
|
-
name: hoe
|
113
|
-
bindir: bin
|
114
|
-
has_rdoc: true
|