Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: cf-samples-attic/summer-jobs
base: redis
...
head fork: cf-samples-attic/summer-jobs
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 8 commits
  • 6 files changed
  • 0 commit comments
  • 3 contributors
View
2  README.md
@@ -26,6 +26,8 @@ This template uses:
## To deploy on Cloud Foundry
+You can get an account at [https://my.cloudfoundry.com/signup/summerjobs](https://my.cloudfoundry.com/signup/summerjobs) if you don't have one
+
First fork the project. Then run:
``` bash
View
2  jobs.rb
@@ -75,7 +75,7 @@ def get_jobs(query='vmware')
@jobs = get_jobs()
@full_url = url_for("/", :full)
- @image = url_for("/images/me.png", :full)
+ @image = url_for("/images/summerjobs.png", :full)
@title = "Summer Jobs+ 2012"
haml :index
end
View
61 lib/DOLDataSDK.rb
@@ -38,7 +38,7 @@ def initialize context
@active_requests = []
end
- # This method consturcts and submits the data request.
+ # This method constructs and submits the data request.
# It calls the passed block when it completes, returning both a result and an error.
# If error is not nil, there was an error during processing.
# The request is submitted in another thread, so call #wait_until_finished to ensure
@@ -72,46 +72,51 @@ def call_api method, arguments = {}, &block
end
unless clean
- request = Net::HTTP::Get.new [url.path, url.query].join '?'
- header = get_header(url,timestamp)
- request.add_field 'Authorization', header
- request.add_field 'Accept', 'application/json'
+ begin
+ request = Net::HTTP::Get.new [url.path, url.query].join '?'
+ header = get_header(url,timestamp)
+ request.add_field 'Authorization', header
+ request.add_field 'Accept', 'application/json'
+
+ result = Net::HTTP.start(url.host, url.port) do |http|
+ http.request request
+ end
- result = Net::HTTP.start(url.host, url.port) do |http|
- http.request request
- end
+ if result.is_a? Net::HTTPSuccess
+ clean = result.body.gsub(/\\+"/, '"')
+ clean = clean.gsub /\\+n/, ""
+ clean = clean.gsub /\"\"\{/, "{"
+ clean = clean.gsub /}\"\"/, "}"
+ #clean = clean.gsub /\\\\u/, "\u"
+ #puts clean
- if result.is_a? Net::HTTPSuccess
- clean = result.body.gsub(/\\+"/, '"')
- clean = clean.gsub /\\+n/, ""
- clean = clean.gsub /\"\"\{/, "{"
- clean = clean.gsub /}\"\"/, "}"
- #clean = clean.gsub /\\\\u/, "\u"
- #puts clean
+ cache_response = true
- if @redis
- @redis.set(redis_key, clean)
- @redis.expire(redis_key, 60 * 15)
+ else
+ clean = nil
+ AppConfig.logger.error("Error in API response #{result.message}")
+ block.call nil, "Error: #{result.message}"
end
-
- else
- clean = nil
- AppConfig.logger.error(result.inspect)
- block.call nil, "Error: #{result.message}"
+ rescue Exception => ex
+ AppConfig.logger.error("Error making API call due to #{ex}")
end
end
- result = []
+ results = []
begin
if clean
- result = JSON.parse(clean)
- result = result['d']['getJobsListing']['items']
+ results = JSON.parse(clean)
+ results = results['d']['getJobsListing']['items']
+ results ||= []
+ if cache_response and @redis
+ @redis.set(redis_key, clean)
+ @redis.expire(redis_key, 60 * 30)
+ end
end
rescue Exception => ex
AppConfig.logger.error("Invalid format for #{clean} got error parsing it #{ex}")
- @redis.delete(redis_key) if @redis
end
- block.call result, nil
+ block.call results, nil
@mutex.synchronize do
@active_requests.delete Thread.current
View
BIN  public/images/me.jpg
Deleted file not rendered
View
BIN  public/images/summerjobs.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
18 views/layout.haml
@@ -7,18 +7,18 @@
%meta{:property => 'og:image', :content => @image}
%meta{:property => 'og:url', :content => @full_url}
%meta{:property => 'og:description', :content => @description}
- %meta{:prefix=>"fb: http://ogp.me/ns/fb#", :property => "fb:app_id", :content=> @appid}
+ %meta{:prefix=>"fb:http://ogp.me/ns/fb#", :property => "fb:app_id", :content=> @appid}
%link{:rel=>'stylesheet', :href=>'/stylesheets/style.css', :type => "text/css"}
%body
#fb-root
- :javascript
- (function(d, s, id) {
- var js, fjs = d.getElementsByTagName(s)[0];
- if (d.getElementById(id)) return;
- js = d.createElement(s); js.id = id;
- js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=#{@appid}";
- fjs.parentNode.insertBefore(js, fjs);
- }(document, 'script', 'facebook-jssdk'));
+ :javascript
+ (function(d, s, id) {
+ var js, fjs = d.getElementsByTagName(s)[0];
+ if (d.getElementById(id)) return;
+ js = d.createElement(s); js.id = id;
+ js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=#{@appid}";
+ fjs.parentNode.insertBefore(js, fjs);
+ }(document, 'script', 'facebook-jssdk'));
.container_12
%a{:href=>"http://cloudfoundry.com"}
%img{:style=>"position: absolute; top: 0; left: 50; border: 0;", :src=>"/images/badge_CF.png", :alt=>"Clone me on Cloud Foundry"}

No commit comments for this range

Something went wrong with that request. Please try again.