[Groonga-commit] groonga/heroku-sample-rroonga-blog at 12e3cc0 [master] Post to application instead of local update

Back to archive index

Kouhei Sutou null+****@clear*****
Sun May 25 19:04:00 JST 2014


Kouhei Sutou	2014-05-25 19:04:00 +0900 (Sun, 25 May 2014)

  New Revision: 12e3cc0276bc2b6a983de36bf6fecc3564f587af
  https://github.com/groonga/heroku-sample-rroonga-blog/commit/12e3cc0276bc2b6a983de36bf6fecc3564f587af

  Message:
    Post to application instead of local update

  Modified files:
    Gemfile
    Gemfile.lock
    lib/tasks/import.rake

  Modified: Gemfile (+2 -0)
===================================================================
--- Gemfile    2014-05-25 18:24:10 +0900 (e701dad)
+++ Gemfile    2014-05-25 19:04:00 +0900 (2decd7b)
@@ -42,3 +42,5 @@ gem 'spring',        group: :development
 gem 'rails_12factor', group: :production
 
 gem 'rroonga'
+
+gem 'mechanize', group: :development

  Modified: Gemfile.lock (+24 -0)
===================================================================
--- Gemfile.lock    2014-05-25 18:24:10 +0900 (76ece3f)
+++ Gemfile.lock    2014-05-25 19:04:00 +0900 (5a16661)
@@ -38,6 +38,8 @@ GEM
       coffee-script-source
       execjs
     coffee-script-source (1.7.0)
+    domain_name (0.5.18)
+      unf (>= 0.0.5, < 1.0.0)
     erubis (2.7.0)
     execjs (2.0.2)
     gqtp (1.0.6)
@@ -47,6 +49,8 @@ GEM
     groonga-command (1.0.7)
       json
     hike (1.2.3)
+    http-cookie (1.0.2)
+      domain_name (~> 0.5)
     i18n (0.6.9)
     io-like (0.3.0)
     jbuilder (2.0.7)
@@ -59,9 +63,24 @@ GEM
     mail (2.5.4)
       mime-types (~> 1.16)
       treetop (~> 1.4.8)
+    mechanize (2.7.2)
+      domain_name (~> 0.5, >= 0.5.1)
+      http-cookie (~> 1.0.0)
+      mime-types (~> 1.17, >= 1.17.2)
+      net-http-digest_auth (~> 1.1, >= 1.1.1)
+      net-http-persistent (~> 2.5, >= 2.5.2)
+      nokogiri (~> 1.4)
+      ntlm-http (~> 0.1, >= 0.1.1)
+      webrobots (>= 0.0.9, < 0.2)
     mime-types (1.25.1)
+    mini_portile (0.6.0)
     minitest (5.3.4)
     multi_json (1.10.1)
+    net-http-digest_auth (1.4)
+    net-http-persistent (2.9.4)
+    nokogiri (1.6.2.1)
+      mini_portile (= 0.6.0)
+    ntlm-http (0.1.1)
     pg (0.17.1)
     pkg-config (1.1.5)
     polyglot (0.3.4)
@@ -128,6 +147,10 @@ GEM
     uglifier (2.5.0)
       execjs (>= 0.3.0)
       json (>= 1.8.0)
+    unf (0.1.4)
+      unf_ext
+    unf_ext (0.0.6)
+    webrobots (0.1.1)
 
 PLATFORMS
   ruby
@@ -136,6 +159,7 @@ DEPENDENCIES
   coffee-rails (~> 4.0.0)
   jbuilder (~> 2.0)
   jquery-rails
+  mechanize
   pg
   rails (= 4.1.1)
   rails_12factor

  Modified: lib/tasks/import.rake (+19 -3)
===================================================================
--- lib/tasks/import.rake    2014-05-25 18:24:10 +0900 (c88601a)
+++ lib/tasks/import.rake    2014-05-25 19:04:00 +0900 (03fee2c)
@@ -1,15 +1,31 @@
 require 'rss'
+require 'mechanize'
 
 def import_rss(url)
+  uri = URI(ENV['APP_URL'])
+  uri.path = '/posts/new'
+  agent = Mechanize.new
+
   rss = RSS::Parser.parse(url)
   rss.items.each do |item|
-    Post.create(title:   item.title,
-                content: item.description)
+    new_post_page = agent.get(uri.to_s)
+    form = new_post_page.forms.first
+    form['post[title]']   = item.title
+    form['post[content]'] = item.description
+    form.submit
   end
 end
 
 namespace :import do
-  task prepare: :environment
+  task prepare: :environment do
+    if ENV['APP_URL'].nil?
+      message = <<-MESSAGE
+Must set APP_URL environment variable
+e.g.: rake import APP_URL=http://localhost:3000
+      MESSAGE
+      raise message
+    end
+  end
 
   namespace :blogroonga do
     desc 'Import blogroonga entries in English'
-------------- next part --------------
HTML����������������������������...
下載 



More information about the Groonga-commit mailing list
Back to archive index