diff --git a/app/controllers/admin/module_store_controller.rb b/app/controllers/admin/module_store_controller.rb index 7eda752..c07f9ec 100644 --- a/app/controllers/admin/module_store_controller.rb +++ b/app/controllers/admin/module_store_controller.rb @@ -1,5 +1,5 @@ class Admin::ModuleStoreController < OrbitBackendController - before_filter :check_central_server_connection + before_filter :check_central_server_connection, :only => [:get_extensions] @@store = STORE_CONFIG[:store_settings]["url"] def index @@ -85,7 +85,7 @@ class Admin::ModuleStoreController < OrbitBackendController protected def get_extensions - extensions = JSON.parse(open("#{@@store}/extensions").read) + extensions = store_session.extensions exist_exts = [] ext_file = File.new("#{Rails.root}/downloaded_extensions.rb", "r") @@ -112,7 +112,7 @@ class Admin::ModuleStoreController < OrbitBackendController end def get_extension(id) - JSON.parse(open("#{@@store}/extensions/#{id}").read) + store_session.get_extension(id) end def get_downloaded_extension @@ -142,4 +142,10 @@ class Admin::ModuleStoreController < OrbitBackendController end end + private + + def get_site + @site ||= Site.first + end + end \ No newline at end of file diff --git a/app/controllers/admin/template_store_controller.rb b/app/controllers/admin/template_store_controller.rb index 5f2344c..e001bce 100644 --- a/app/controllers/admin/template_store_controller.rb +++ b/app/controllers/admin/template_store_controller.rb @@ -3,20 +3,20 @@ require 'uri' require 'fileutils' require 'zip/zip' class Admin::TemplateStoreController < OrbitBackendController - + before_filter :check_central_server_connection, :only => [:get_extensions] @@store_domain = STORE_CONFIG[:store_settings]["url"] def index - @store = @@store_domain + @store_url = @@store_domain @design_ids = Design.all.map{|d| d.template_store_id} - @templates = JSON.parse(get_templates) + @templates = get_templates.parsed_response render :layout => false end def show @store = @@store_domain @design_ids = Design.all.map{|d| d.template_store_id} - @template = JSON.parse(get_template(params[:id])) rescue nil + @template = get_template(params[:id]).parsed_response rescue nil end def download_theme @@ -92,19 +92,21 @@ class Admin::TemplateStoreController < OrbitBackendController end def get_template(id) - uri = URI.parse("#{@@store_domain}/api/templates/#{id}") - http = Net::HTTP.new(uri.host, uri.port) - request = Net::HTTP::Get.new(uri.request_uri) - response = http.request(request) - response.body + store_session.get_template(id) + # uri = URI.parse("#{@@store_domain}/api/templates/#{id}") + # http = Net::HTTP.new(uri.host, uri.port) + # request = Net::HTTP::Get.new(uri.request_uri) + # response = http.request(request) + # response.body end def get_templates - uri = URI.parse("#{@@store_domain}/api/templates") - http = Net::HTTP.new(uri.host, uri.port) - request = Net::HTTP::Get.new(uri.request_uri) - response = http.request(request) - response.body + extensions = store_session.templates + # uri = URI.parse("#{@@store_domain}/api/templates") + # http = Net::HTTP.new(uri.host, uri.port) + # request = Net::HTTP::Get.new(uri.request_uri) + # response = http.request(request) + # response.body end end \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9f5fa92..98618ef 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -488,4 +488,9 @@ class ApplicationController < ActionController::Base end end + def store_session + api_key = STORE_CONFIG[:store_settings]["api_key"] + @store = Store.new(@site.id.to_s,@site.site_token,api_key) if @site.site_token + end + end diff --git a/app/views/admin/module_store/index.html.erb b/app/views/admin/module_store/index.html.erb index 2272c26..d9d10eb 100644 --- a/app/views/admin/module_store/index.html.erb +++ b/app/views/admin/module_store/index.html.erb @@ -184,7 +184,6 @@
<%= t(:module_store) %>
- diff --git a/app/views/admin/template_store/_template.html.erb b/app/views/admin/template_store/_template.html.erb index 970e138..bbeaa25 100644 --- a/app/views/admin/template_store/_template.html.erb +++ b/app/views/admin/template_store/_template.html.erb @@ -1,7 +1,7 @@ + <%= render :partial => 'template', :collection => @templates %> diff --git a/app/views/admin/template_store/show.html.erb b/app/views/admin/template_store/show.html.erb index c730b85..fd13d80 100644 --- a/app/views/admin/template_store/show.html.erb +++ b/app/views/admin/template_store/show.html.erb @@ -6,7 +6,7 @@
- <%= image_tag "#{@store}#{@template['preview']['preview']['thumb']['url']}", :class => "item-thumb" %> + <%= image_tag "#{@store_url}/#{@template['preview']['preview']['thumb']['url']}", :class => "item-thumb" %>

<%= @template['title'] %>

<% if @design_ids.include?(@template["_id"]["$oid"]) %> <%= link_to "Installed", "javascript:void(0);", "data-url" => @template['template']['template']['url'], :class=> 'btn btn-success download-link', "disabled"=>"disabled", "data-name"=>@template['title'], "data-slug"=>@template["_slugs"][0], "data-id"=>@template["_id"]["$oid"] %> diff --git a/config/store_config.yml b/config/store_config.yml index f591dc0..e086195 100644 --- a/config/store_config.yml +++ b/config/store_config.yml @@ -1,3 +1,4 @@ store_settings: - url: "http://store.tp.rulingcom.com/api" + url: "http://store.tp.rulingcom.com" + api_url: "http://store.tp.rulingcom.com/api" api_key: 'Token token="2870f77e59168dbe3fbdffba466c7c8d"' diff --git a/lib/store.rb b/lib/store.rb index a7db8b7..3d8e400 100644 --- a/lib/store.rb +++ b/lib/store.rb @@ -3,7 +3,7 @@ class Store include HTTParty format :json - base_uri STORE_CONFIG[:store_settings]["url"] + base_uri STORE_CONFIG[:store_settings]["api_url"] def initialize(site_id,site_token,api_key) @options_for_get = { @@ -30,11 +30,21 @@ class Store self.class.get('/templates', options) end + def get_template(id) + options = @options_for_get + self.class.get("/templates/#{id}", options) + end + def extensions(options={}) options = @options_for_get self.class.get('/extensions', options) end + def get_extension(id) + options = @options_for_get + self.class.get("/extensions/#{id}", options) + end + def post_client(site_id,site_token,site_name) options = @options_for_client.merge({ :body => {:site_name => site_name, :site_id => site_id, :site_token => site_token}.to_json }) self.class.post('/clients', options )
"> - + diff --git a/app/views/admin/template_store/index.html.erb b/app/views/admin/template_store/index.html.erb index e4c8a61..fd462ec 100644 --- a/app/views/admin/template_store/index.html.erb +++ b/app/views/admin/template_store/index.html.erb @@ -5,5 +5,6 @@ Status