bijo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4aabcfbb2b8ed7f741401674e2b1b03075fee22d
4
+ data.tar.gz: 2cb0da2c18db02858ef1a0abcec82b1569659ff6
5
+ SHA512:
6
+ metadata.gz: c4d5f59bd0ee1900e0447b715aeb7894d5d1ae8c4b7cf0c25fb54cd407928d077eee91b723f73b4b17434737453c096cf456583af761ebc00b319ba31bb44399
7
+ data.tar.gz: 233efa9dd4077b67565218486e9fd4390e3bbaaff90ae7d07b9e9d84d3c188910e4eefdea2ae07cebdd43d0d721bab30658de4ac159daa511746a2202568a7b8
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bijo.gemspec
4
+ gemspec
@@ -0,0 +1,37 @@
1
+ # Bijo
2
+
3
+ Watch beauty woman from terminal.
4
+
5
+ !! NOTE: This gem is only to show image from tumblr search.
6
+
7
+ ## Usage
8
+ Only this.
9
+ ```
10
+ $ bijo <query>
11
+ ```
12
+
13
+ Watch 佐々木希
14
+ ```
15
+ $bijo 佐々木希
16
+ ```
17
+
18
+ ![佐々木希 - demo](https://raw.githubusercontent.com/karur4n/bijo/master/images/bijo.gif)
19
+
20
+ ## Installation
21
+ ```
22
+ $ gem install bijo
23
+ ```
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/karur4n/bijo/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bijo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bijo"
8
+ spec.version = Bijo::VERSION
9
+ spec.authors = ["karur4n"]
10
+ spec.email = ["karuran.f@gmail.com"]
11
+
12
+ spec.summary = 'Watch beauty woman image from terminal'
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "bin"
17
+ spec.executables = ['bijo']
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.8"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3
+ require 'bijo'
4
+
5
+ builder = Bijo::CommandBuilder.new(ARGV)
6
+ command = builder.build
7
+ command.execute
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bijo"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
Binary file
@@ -0,0 +1,2 @@
1
+ require 'bijo/version'
2
+ require 'bijo/command_builder'
@@ -0,0 +1,32 @@
1
+ module Bijo
2
+ class Arguments
3
+ def initialize(argv)
4
+ @argv = argv
5
+ end
6
+
7
+ def query
8
+ # スペース入りの query に対応する
9
+ query = ''
10
+ ARGV.each do |arg|
11
+ query += " #{arg}"
12
+ end
13
+ query.slice!(0)
14
+ query
15
+ end
16
+
17
+ def valid?
18
+ has_query?
19
+ end
20
+
21
+ def request_service
22
+ # 後々、リクエスト先サービスを切り替える際にちゃんと実装する
23
+ 'tumblr'
24
+ end
25
+
26
+ private
27
+
28
+ def has_query?
29
+ !@argv.empty?
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,41 @@
1
+ require 'bijo/image'
2
+
3
+ require 'json'
4
+ require 'open-uri'
5
+ require 'tempfile'
6
+
7
+ module Bijo
8
+ module Client
9
+ class Base
10
+ def initialize(query)
11
+ @query = query
12
+ @image = Image.new(choose_image)
13
+ end
14
+
15
+ def get
16
+ content = @image.content
17
+
18
+ file = Tempfile.new(['bijo', @image.extension])
19
+ file.print content
20
+ file.close
21
+ file
22
+ end
23
+
24
+ private
25
+
26
+ def raw_search_results
27
+ open(search_uri).read
28
+ end
29
+
30
+ def json_parsed_search_results
31
+ JSON.parse(raw_search_results)
32
+ end
33
+
34
+ # return image url
35
+ # Ex) http://example.com/hoge.jpg
36
+ def choose_image
37
+ search_results[rand(search_results.size)]
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,14 @@
1
+ require 'bijo/client/base'
2
+
3
+ module Bijo
4
+ module Client
5
+ class Google < Base
6
+ BASE_URI = 'http://ajax.googleapis.com/ajax/services/search/images?v=1.0&hl=ja'
7
+
8
+ def search_results
9
+ json_parsed_search_results['responseData']['results']
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+
2
+ module Bijo
3
+ module Client
4
+ class Tumblr < Base
5
+ BASE_URI = 'https://tumblr-img-api.herokuapp.com/search/photo'
6
+
7
+ def search_results
8
+ json_parsed_search_results
9
+ end
10
+
11
+ def search_uri
12
+ URI.escape("#{BASE_URI}?q=#{@query}")
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ require 'bijo/client/google'
2
+ require 'bijo/client/tumblr'
3
+
4
+ module Bijo
5
+ class Command
6
+
7
+ def initialize(arguments)
8
+ @arguments = arguments
9
+ end
10
+
11
+ def execute
12
+ image = client.get
13
+ system "qlmanage -p #{image.path}"
14
+ end
15
+
16
+ private
17
+
18
+ def client(request_service: @arguments.request_service)
19
+ if request_service == 'tumblr'
20
+ Client::Tumblr.new(@arguments.query)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'bijo/command'
2
+ require 'bijo/arguments'
3
+
4
+ module Bijo
5
+ class CommandBuilder
6
+ def initialize(argv)
7
+ @argv = argv
8
+ end
9
+
10
+ def build
11
+ if arguments.valid?
12
+ Command.new(arguments)
13
+ else
14
+ fail ArgumentError, 'arguments is invalid'
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def arguments
21
+ Arguments.new(@argv)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ require 'open-uri'
2
+
3
+ module Bijo
4
+ class Image
5
+ def initialize(image_url)
6
+ @image_url = image_url
7
+ end
8
+
9
+ def extension
10
+ extension_regexp = /(.*)(?:(\.[^.]+$))/
11
+ @image_url.match(extension_regexp)[2]
12
+ end
13
+
14
+ def content
15
+ open(@image_url).read
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Bijo
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bijo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - karur4n
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - karuran.f@gmail.com
44
+ executables:
45
+ - bijo
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - README.md
52
+ - Rakefile
53
+ - bijo.gemspec
54
+ - bin/bijo
55
+ - bin/console
56
+ - bin/setup
57
+ - images/bijo.gif
58
+ - lib/bijo.rb
59
+ - lib/bijo/arguments.rb
60
+ - lib/bijo/client/base.rb
61
+ - lib/bijo/client/google.rb
62
+ - lib/bijo/client/tumblr.rb
63
+ - lib/bijo/command.rb
64
+ - lib/bijo/command_builder.rb
65
+ - lib/bijo/image.rb
66
+ - lib/bijo/version.rb
67
+ homepage:
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.4.5
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Watch beauty woman image from terminal
91
+ test_files: []