Permalink
Browse files

first commit for version 2.0

  • Loading branch information...
0 parents commit 47a4eed8eaca86f923d9fea77a07277ae4745ebb ruedap committed Mar 9, 2011
@@ -0,0 +1,6 @@
+.DS_Store
+/.bundle
+/log
+/materials
+/secret
+/vendor
13 Gemfile
@@ -0,0 +1,13 @@
+source :rubygems
+gem 'sinatra', '1.2.0'
+gem 'sinatra-r18n', '0.4.9'
+gem 'sinatra-iphone-views', '1.0.0'
+gem 'r18n-core', '0.4.9'
+gem 'json', '1.4.6'
+gem 'slim', '0.9.0'
+gem 'haml', '3.0.25'
+
+group :development do
+ gem 'shotgun'
+end
+
@@ -0,0 +1,36 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ haml (3.0.25)
+ json (1.4.6)
+ json (1.4.6-x86-mingw32)
+ r18n-core (0.4.9)
+ rack (1.2.1)
+ shotgun (0.9)
+ rack (>= 1.0)
+ sinatra (1.2.0)
+ rack (~> 1.1)
+ tilt (>= 1.2.2, < 2.0)
+ sinatra-iphone-views (1.0.0)
+ sinatra (>= 1.0.a)
+ sinatra-r18n (0.4.9)
+ r18n-core (= 0.4.9)
+ slim (0.9.0)
+ temple (~> 0.1.7)
+ tilt (~> 1.2)
+ temple (0.1.7)
+ tilt (1.2.2)
+
+PLATFORMS
+ ruby
+ x86-mingw32
+
+DEPENDENCIES
+ haml (= 3.0.25)
+ json (= 1.4.6)
+ r18n-core (= 0.4.9)
+ shotgun
+ sinatra (= 1.2.0)
+ sinatra-iphone-views (= 1.0.0)
+ sinatra-r18n (= 0.4.9)
+ slim (= 0.9.0)
23 LICENSE
@@ -0,0 +1,23 @@
+Nekostagram
+
+The MIT License
+
+Copyright (c) 2011 ruedap
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -0,0 +1,26 @@
+## Nekostagram / Inustagram
+
+
+### これは何?
+
+ねこ大好き専用/いぬ大好き専用のインスタグラムビューアー。
+[http://nekostagram.heroku.com/](http://nekostagram.heroku.com/)
+[http://inustagram.heroku.com/](http://inustagram.heroku.com/)
+上記URLで動作しているHeroku用Webアプリのソースコード。
+
+---
+
+### コード内で使用しているHeroku環境変数
+
+ ENV['INSTAGRAM_TARGET_TAG'] = 'Instagram APIで検索するタグの文字列'
+ ENV['INSTAGRAM_ACCESS_TOKEN'] = 'Instagram APIのアクセストークン'
+ ENV['GOOGLE_ANALYTICS_ID'] = 'Google AnalyticsのID'
+ ENV['STAGING_BASIC_AUTH_USERNAME'] = 'ステージング環境のBasic認証用ユーザーネーム'
+ ENV['STAGING_BASIC_AUTH_PASSWORD'] = 'ステージング環境のBasic認証用パスワード'
+
+---
+
+### Copyright
+
+Copyright &copy; 2011 ruedap. See LICENSE for details.
+
164 app.rb
@@ -0,0 +1,164 @@
+require 'open-uri'
+require 'uri'
+require 'pp'
+
+require 'rubygems'
+require 'json'
+require 'sinatra'
+require 'sinatra/r18n'
+require 'sinatra/iphone_views'
+require 'slim'
+require 'sass'
+
+configure :development do
+ require 'secret/env.rb'
+end
+
+configure :development, :staging do
+ Slim::Engine.set_default_options :pretty => true
+end
+
+configure :staging do
+ use Rack::Auth::Basic do |username, password|
+ username == ENV['STAGING_BASIC_AUTH_USERNAME'] && password == ENV['STAGING_BASIC_AUTH_PASSWORD']
+ end
+end
+
+configure :production do
+ set :sass, { :style => :compressed }
+end
+
+before do
+ @google_analytics_id = ENV['GOOGLE_ANALYTICS_ID']
+
+ @target_tag = ENV['INSTAGRAM_TARGET_TAG'] || 'cat'
+ @target_path = "/#{@target_tag}"
+ @target_url = "https://api.instagram.com/v1/tags#{@target_path}/media/recent?access_token="
+ @base_url = @target_url + ENV['INSTAGRAM_ACCESS_TOKEN']
+ @data = []
+ @error = false
+
+ # sinatra-r18n
+ set :translations, "./i18n/#{@target_tag}/"
+
+ cat_block_list_id = %w(
+ 619782f2ea01462aacc92aa4d9586618
+ b9d6177b64b54632ae21dd23c4177174
+ ef2e316e043d42b49a463a93b97b7401
+ 40776424c8754a069ce17fed2e10f9b6
+ 481471f95a124d3c9ef27436926201b9
+ 0d3e982cbb8b494ca06bcf94c841fdcf
+ db9334ea105840a883ebafd5af1c4256
+ 9c10b2f52889489c8e04060fb1dbb4c1
+ 9958b12e5b30491489f7dc107dac082d
+ 732bb8c2b21a4ecbb58f00d3b180a075
+ )
+
+ dog_block_list_id = %w(
+ 791f744c227a41acb461f98f0c0195ca
+ d7321ff3214a4af2a93c0d54b508c68e
+ b619fb4b326f434da139b320f802a696
+ 60d047a75eeb49d085dd8ee586d20e53
+ b4d685fd605d4dd9a20151ac31f5cee6
+ e988aec1260b4c828af8c0b6f370bbfa
+ e29866169d18434fa341c913e7ed8f0a
+ )
+
+ @block_list_id = cat_block_list_id | dog_block_list_id
+end
+
+get '/' do
+ create_data
+ slim :index
+end
+
+put '/' do
+ create_data(params[:max_id])
+ slim :index
+end
+
+get '/error' do
+ @error = true
+ slim :error
+end
+
+get '/style.css' do
+ sass "style_#{@target_tag}".to_sym
+end
+
+private
+def create_data(max_id = nil)
+ json = parse_json(create_max_id_url(max_id))
+
+ redirect '/error' unless json['meta']['code'] && json['meta']['code'] == 200
+
+ @data = extract_data(json['data'])
+ @max_id = check_id(json['pagination']['next_max_id'])
+end
+
+def create_max_id_url(max_id = nil)
+ return @base_url unless max_id
+ @base_url + "&max_id=#{max_id}"
+end
+
+def check_id(max_id)
+ return nil unless max_id
+ begin
+ return max_id if max_id == max_id.to_i.to_s
+ rescue
+ redirect '/error' #TODO
+ end
+ nil
+end
+
+def parse_json(url)
+ begin
+ str = open(url) do |data|
+ data.read
+ end
+ rescue
+ redirect '/error' #TODO
+ end
+
+ begin
+ json = JSON.parse(str)
+ rescue
+ redirect '/error' #TODO
+ end
+ json
+end
+
+def extract_data(data)
+ redirect '/error' if data.empty? #TODO
+
+ result = []
+ data.each do |v|
+ hash = {}
+ hash['thumbnail'] = v['images']['thumbnail']['url']
+ hash['low'] = v['images']['low_resolution']['url']
+ hash['standard'] = v['images']['standard_resolution']['url']
+ hash['created_time'] = v['created_time']
+ hash['link'] = v['link']
+ hash['likes'] = v['likes']
+ hash['location'] = v['location']
+ hash['caption'] = v['caption'] ? v['caption']['text'] : nil
+
+ if check_block_list(hash)
+ hash['low'] = "#{@target_path}/images/oops.gif"
+ hash['caption'] = nil
+ hash['link'] = nil
+ end
+
+ result.push hash
+ end
+ result
+end
+
+def check_block_list(hash)
+ return false if @block_list_id.empty?
+ @block_list_id.each do |bl|
+ return true if hash['low'].include?(bl)
+ end
+ false
+end
+
@@ -0,0 +1,2 @@
+require 'app.rb'
+run Sinatra::Application
@@ -0,0 +1,13 @@
+site:
+ title: 'Nekostagram - Cat Lovers Instagram Viewer'
+ also:
+ text: 'Do you also like dogs?'
+ url: 'http://inustagram.heroku.com/'
+html:
+ error:
+ splash: !!html
+ <br>Oh My Cat!!<br>
+ description: !!html
+ <br>Sorry, could not display the page.<br><br>
+tweet:
+ text: 'Love Cats #nekostagram'
@@ -0,0 +1,13 @@
+site:
+ title: 'Nekostagram - ねこ大好き専用Instagram'
+ also:
+ text: 'いぬも好き?'
+ url: 'http://inustagram.heroku.com/'
+html:
+ error:
+ splash: !!html
+ <br>Oh My Cat!!<br>
+ description: !!html
+ <br>ご迷惑をおかけして申し訳ございません。<br>現在、APIリクエスト数の上限に達したか、アクセス数の過多か、もしくはニャン事無き理由で、かわいいネコ画像を表示できない状態です。<br>制限が解除もしくは原因が解決され次第、何食わぬ顔で再開しますので、お手数ですが時間を置いて再度Nekostagramに訪れていただければ幸いです。<br>単にブラウザの更新ボタンを押すだけで、普通に見られるようになることも時々あります。<br><br>
+tweet:
+ text: 'ねこ大好き #nekostagram'
@@ -0,0 +1,14 @@
+site:
+ title: 'Inustagram - Dog Lovers Instagram Viewer'
+ also:
+ text: 'Do you also like cats?'
+ url: 'http://nekostagram.heroku.com/'
+html:
+ error:
+ splash: !!html
+ <br>Oh My Dog!!<br>
+ description: !!html
+ <br>Sorry, could not display the page.<br><br>
+tweet:
+ text: 'Love Dogs #inustagram'
+
@@ -0,0 +1,14 @@
+site:
+ title: 'Inustagram - いぬ大好き専用Instagram'
+ also:
+ text: 'ねこも好き?'
+ url: 'http://nekostagram.heroku.com/'
+html:
+ error:
+ splash: !!html
+ <br>Oh My Dog!!<br>
+ description: !!html
+ <br>ご迷惑をおかけして申し訳ございません。<br>現在、APIリクエスト数の上限に達したか、アクセス数の過多か、もしくはワン事無き理由で、かわいいイヌ画像を表示できない状態です。<br>制限が解除もしくは原因が解決され次第、何食わぬ顔で再開しますので、お手数ですが時間を置いて再度Inustagramに訪れていただければ幸いです。<br>単にブラウザの更新ボタンを押すだけで、普通に見られるようになることも時々あります。<br><br>
+tweet:
+ text: 'いぬ大好き #inustagram'
+
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 47a4eed

Please sign in to comment.