added rake command

This commit is contained in:
Tyrel Souza 2014-02-13 15:44:56 -05:00
parent 5a8fd39e6b
commit f251500aa4
7 changed files with 67 additions and 12 deletions

View File

@ -6,6 +6,7 @@ gem "meta_search", '>= 1.1.0.pre'
gem "rails_config" gem "rails_config"
gem "savon", "~> 2.0" gem "savon", "~> 2.0"
gem "gyoku", "~> 1.0" gem "gyoku", "~> 1.0"
gem "pry"
group :assets do group :assets do
gem "coffee-rails", "~> 3.2.1" gem "coffee-rails", "~> 3.2.1"

View File

@ -39,6 +39,7 @@ GEM
railties (>= 3.0) railties (>= 3.0)
sass-rails (>= 3.2) sass-rails (>= 3.2)
chunky_png (1.3.0) chunky_png (1.3.0)
coderay (1.1.0)
coffee-rails (3.2.2) coffee-rails (3.2.2)
coffee-script (>= 2.2.0) coffee-script (>= 2.2.0)
railties (~> 3.2.0) railties (~> 3.2.0)
@ -81,6 +82,7 @@ GEM
activerecord (~> 3.1) activerecord (~> 3.1)
activesupport (~> 3.1) activesupport (~> 3.1)
polyamorous (~> 0.5.0) polyamorous (~> 0.5.0)
method_source (0.8.2)
mime-types (1.25.1) mime-types (1.25.1)
mini_portile (0.5.2) mini_portile (0.5.2)
multi_json (1.8.4) multi_json (1.8.4)
@ -90,6 +92,10 @@ GEM
polyamorous (0.5.0) polyamorous (0.5.0)
activerecord (~> 3.0) activerecord (~> 3.0)
polyglot (0.3.3) polyglot (0.3.3)
pry (0.9.12.6)
coderay (~> 1.0)
method_source (~> 0.8)
slop (~> 3.4)
rack (1.4.5) rack (1.4.5)
rack-cache (1.2) rack-cache (1.2)
rack (>= 0.4) rack (>= 0.4)
@ -131,6 +137,7 @@ GEM
nokogiri (>= 1.4.0) nokogiri (>= 1.4.0)
nori (~> 2.3.0) nori (~> 2.3.0)
wasabi (~> 3.2.2) wasabi (~> 3.2.2)
slop (3.4.7)
sprockets (2.2.2) sprockets (2.2.2)
hike (~> 1.2) hike (~> 1.2)
multi_json (~> 1.0) multi_json (~> 1.0)
@ -167,6 +174,7 @@ DEPENDENCIES
jquery-rails (= 2.3.0) jquery-rails (= 2.3.0)
maskedinput-rails maskedinput-rails
meta_search (>= 1.1.0.pre) meta_search (>= 1.1.0.pre)
pry
rails (= 3.2.12) rails (= 3.2.12)
rails_config rails_config
sass-rails (~> 3.2.3) sass-rails (~> 3.2.3)

View File

@ -15,11 +15,5 @@
//= require twitter/bootstrap //= require twitter/bootstrap
//= require maskedinput //= require maskedinput
//= require chosen-jquery //= require chosen-jquery
//= require handlebars
//= require ember
//= require ember-data
//= require_self
//= require listpush
//= require_tree . //= require_tree .
ListPushApp = Ember.Application.create();

View File

@ -0,0 +1,31 @@
body { background-color: #5f7395; color: #333; }
body, p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}
pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}
a { color: #000; }
a:visited { color: #666; }
a:hover { color: #fff; background-color:#000; }
#main {
background-color: #fff;
border: solid #000 1px;
margin: 5em;
height: 30em;
padding: 1em;
}
#notice {
background-color: #e1facf;
border: solid #97C36d 1px;
padding: 0.5em;
}

View File

@ -1,4 +1,10 @@
class LocalezeCategory < ActiveRecord::Base class LocalezeCategory < ActiveRecord::Base
attr_accessible :name attr_accessible :name
has_and_belongs_to_many :list_entries has_and_belongs_to_many :list_entries
def self.find_or_create_by_name(name, &block)
obj = self.find_or_create_by_name( name ) || self.new(:name => name)
yield obj
obj.save
end
end end

View File

@ -9,7 +9,7 @@ class LocalezeClient
def check(listing) def check(listing)
value = record_to_xml(listing, true) value = record_to_xml(listing, true)
query = @client.call(:query, message: message(:add, value, :check)) query = @client.call(:query, message: message(:add, value, :check))
result = get_deep_value(query) result = get_deep_value(query)['Response']
check_successful?(result['ErrorCode']) ? true : result['ErrorMessage'] check_successful?(result['ErrorCode']) ? true : result['ErrorMessage']
end end
@ -17,7 +17,7 @@ class LocalezeClient
def create(listing) def create(listing)
value = record_to_xml(listing, true) value = record_to_xml(listing, true)
query = @client.call(:query, message: message(:add, value, :create)) query = @client.call(:query, message: message(:add, value, :create))
result = get_deep_value(query) result = get_deep_value(query)['Response']
status = create_successful?(result) status = create_successful?(result)
handle_status(status) handle_status(status)
end end
@ -32,8 +32,7 @@ class LocalezeClient
# make a call to localeze to get a list of all the categories available # make a call to localeze to get a list of all the categories available
def categories! def categories!
query = @client.call(:query, message: message(:query, 'ACTIVEHEADINGS', :category)) query = @client.call(:query, message: message(:query, 'ACTIVEHEADINGS', :category))
headings = get_heading(query) headings = get_deep_value(query)['ActiveHeadings']['Heading']
headings['ActiveHeadings']['Heading']
end end
# Not sure why, but Localeze returns either an ErrorMessage or a Validator with a Resolution if there's an error. # Not sure why, but Localeze returns either an ErrorMessage or a Validator with a Resolution if there's an error.
@ -49,7 +48,7 @@ class LocalezeClient
# The value that localeze gives us is very deep, this method # The value that localeze gives us is very deep, this method
# cleans that up a little in the implementation depending on the element # cleans that up a little in the implementation depending on the element
def get_deep_value(query) def get_deep_value(query)
Hash.from_xml(query.to_hash[:query_response][:response][:result][:element][:value].to_s)['Response'] Hash.from_xml(query.to_hash[:query_response][:response][:result][:element][:value].to_s)
end end
# This is a helper method to generate the giant dictionary you send as a message. # This is a helper method to generate the giant dictionary you send as a message.

View File

@ -0,0 +1,16 @@
namespace :localeze do
desc "Update and Get new LocalezeCategories"
task :import => :environment do
before = LocalezeCategory.count
categories = LocalezeClient.new.categories
ActiveRecord::Base.transaction do
categories.each do |cat|
category = LocalezeCategory.where(name: cat).first_or_create!
end
if before < LocalezeCategory.count
puts "Imported #{LocalezeCategory.count - before} categories."
end
end
end
end