Class: GData::Client::AppEngine
- Inherits:
-
Base
- Object
- Base
- GData::Client::AppEngine
- Defined in:
- lib/googletastic/app_engine.rb
Overview
Client class to wrap working with the TBD App Engine API.
Instance Method Summary collapse
-
#get(url) ⇒ Object
override so we can get cookie.
- #get_cookie(url) ⇒ Object
-
#initialize(options = {}) ⇒ AppEngine
constructor
A new instance of AppEngine.
- #new_cookie(url) ⇒ Object
-
#push(username, password, options = {}) ⇒ Object
globally push to google app engine, using the python library pushes files to gae required options: folder => where the python command executes username, password.
- #set_cookie(url) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ AppEngine
Returns a new instance of AppEngine.
7 8 9 10 |
# File 'lib/googletastic/app_engine.rb', line 7 def initialize( = {}) [:clientlogin_service] = 'ah' super() end |
Instance Method Details
#get(url) ⇒ Object
override so we can get cookie
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/googletastic/app_engine.rb', line 13 def get(url) (url) response = self.make_request(:get, url) if response.status_code == 302 # if it's redirecting us, we need to get the cookie (url) # now we can make the request again response = self.make_request(:get, url) end response end |
#get_cookie(url) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/googletastic/app_engine.rb', line 44 def (url) uri = URI.parse(url) = "#{uri.scheme}://#{uri.host}/_ah/login?continue=#{url}&auth=#{auth_handler.token}" response = self.make_request(:get, ) = response.headers["set-cookie"].split('; ',2)[0] end |
#new_cookie(url) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/googletastic/app_engine.rb', line 25 def (url) = (url) headers["Cookie"] = Googletastic.credentials[:cookie] = # save the cookie to a file since we're # not in the browser! storage = Googletastic.keys.has_key?(:storage) ? Googletastic.keys[:storage] : :filesystem # heroku can't store anything on filesystem if storage == :filesystem File.open("config/gdata.yml", 'w') do |file| file.write Googletastic.credentials.to_yaml end elsif storage == :environment ENV["GOOGLETASTIC_GAE_COOKIE"] = end end |
#push(username, password, options = {}) ⇒ Object
globally push to google app engine, using the python library pushes files to gae required options:
folder => where the python command executes
username, password
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/googletastic/app_engine.rb', line 66 def push(username, password, = {}) .symbolize_keys! raise "Please define local GAE Folder" unless [:folder] and File.exists?([:folder]) sleep 0.5 # update GAE puts "Pushing to GAE..." cmd = "appcfg.py update #{[:folder]}" original_values = [STDOUT.sync, STDERR.sync, $expect_verbose] STDOUT.sync = true STDERR.sync = true $expect_verbose = true PTY.spawn("#{cmd} 2>&1") do | input, output, pid | begin input.expect("Email:") do output.puts("#{username}\n") end input.expect("Password") do output.write("#{password}\n") end while ((str = input.gets) != nil) if str =~ /Checking if new version is ready to serve/ end puts str end rescue Exception => e puts "GAE Error... #{e.inspect}" end end STDOUT.sync = original_values[0] STDERR.sync = original_values[1] $expect_verbose = original_values[2] sleep 0.5 end |
#set_cookie(url) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/googletastic/app_engine.rb', line 52 def (url) if Googletastic.credentials[:cookie] headers["Cookie"] = Googletastic.credentials[:cookie] return headers["Cookie"] else (url) end end |