Permalink
Browse files

Setup #deals_for_region

  • Loading branch information...
1 parent f3a58eb commit 1664d369f7a2b7e9eb52ce32a243042bf3bd46a3 @nitsujw nitsujw committed Nov 11, 2013
Showing with 39 additions and 27 deletions.
  1. +2 −0 content_service.gemspec
  2. +37 −27 lib/content_service.rb
View
2 content_service.gemspec
@@ -23,5 +23,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rspec"
spec.add_dependency "stomp", "~> 1.2.16"
+ spec.add_dependency "rest-client", "~> 1.6.7"
+ spec.add_dependency "json", "~> 1.8.1"
end
View
64 lib/content_service.rb
@@ -20,43 +20,53 @@ def self.set_password(new_pwd)
def self.set_topic_name(new_topic_name)
@@topic = new_topic_name
end
- def self.publish(obj)
+ def self.publish(obj)
_pub(obj.class.name.downcase, obj.id,'publish')
end
def self.delete(type,id)
_pub(type.downcase,id,'delete')
end
def self._pub(type, id, action)
- begin
- transfer_obj = {:object_name=>type,:action=>action,:id=>id}
+ begin
+ transfer_obj = {:object_name=>type,:action=>action,:id=>id}
- connect().publish("/topic/weedmaps." + @@topic, transfer_obj.to_json, { 'amq-msg-type'=>'text'})
+ connect().publish("/topic/weedmaps." + @@topic, transfer_obj.to_json, { 'amq-msg-type'=>'text'})
- rescue Exception => e
- p e
- end
- end
-
- protected
- def self.connect
- if @@connection == nil
- @@connection = Stomp::Client.new(create_config)
- end
- @@connection
+ rescue Exception => e
+ p e
end
- def self.create_config
- # Work to create configs that don't slow processing...
- # If activemq is acting up, just move on.
- hash = {
- :hosts => [ {
- :login => @@login,
- :passcode => @@pwd,
- :host => @@host,
- :port => 61613,
- :ssl => false } ] }
+ end
+
+ def self.deals_for_region(region_id)
+ begin
+ data = RestClient.get("http://content.bleedmaps.com/Query?id=b6517bf9-b168-4325-b7eb-adebfa3c9da0&regionId=#{region_id}&pg=1")
+ data = JSON.parse data
+ rescue => e
+ Rails.logger.warn e
end
- def self.create_url
- "stomp://" + @@login + ":" + @@pwd + "@" + @@host
+ end
+
+
+ protected
+ def self.connect
+ if @@connection == nil
+ @@connection = Stomp::Client.new(create_config)
end
+ @@connection
+ end
+ def self.create_config
+ # Work to create configs that don't slow processing...
+ # If activemq is acting up, just move on.
+ hash = {
+ :hosts => [ {
+ :login => @@login,
+ :passcode => @@pwd,
+ :host => @@host,
+ :port => 61613,
+ :ssl => false } ] }
+ end
+ def self.create_url
+ "stomp://" + @@login + ":" + @@pwd + "@" + @@host
+ end
end

0 comments on commit 1664d36

Please sign in to comment.