about_p 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4411c9d887a7a0f6c8780216aecb41980d9fd181
4
+ data.tar.gz: 552025c94bfa2b2459360c351dedadd184514267
5
+ SHA512:
6
+ metadata.gz: e9b962c2ce0608e79a843682d45cf3e0e71b8b99775c7aa1993a25d225d57d14b557ae9274e4f130792ce59acafbb8b34623b152540bae8f7f4c822bd9f82d07
7
+ data.tar.gz: 997d361a0f994403dcf5c34f50f586efaef4631140e2a842ddc485eaebe2faf5528b06d3e6b622b6f4a7d5cb82f10f62c220c42823e6430ae90a16078afe7c57
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in about_p.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Keisuke KITA
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # CLI tool for about p
2
+
3
+ Fuzzy string searching at about p
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'about_p'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install about_p
18
+
19
+ ## Usage
20
+
21
+ ```
22
+ aboutp query
23
+ ```
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/about_p.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'about_p/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "about_p"
8
+ spec.version = AboutP::VERSION
9
+ spec.authors = ["Keisuke KITA"]
10
+ spec.email = ["kei.kita2501@gmail.com"]
11
+ spec.description = %q{Fuzzy string searching at about p}
12
+ spec.summary = %q{Fuzzy string searching at about p}
13
+ spec.homepage = "https://github.com/kitak/about_p_cli"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "thor"
22
+ spec.add_runtime_dependency "pit"
23
+ spec.add_runtime_dependency "highline"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "webmock"
29
+ end
data/bin/aboutp ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'about_p'
4
+
5
+ AboutP::Command.start(ARGV)
@@ -0,0 +1,30 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'open-uri'
4
+ require 'pit'
5
+ require 'uri'
6
+
7
+ module AboutP
8
+ module API
9
+ BASE_URI = "about-p-kitak.sqale.jp"
10
+
11
+ def self.search(key, query)
12
+ client = Net::HTTP.new(BASE_URI, 443)
13
+ client.use_ssl = true
14
+ client.verify_mode = OpenSSL::SSL::VERIFY_NONE
15
+ client.start do |http|
16
+ response = http.get("/users/search.json?query=#{URI.encode(query)}", {'X-AboutP-API-Key' => key})
17
+ case response.code.to_i
18
+ when 200
19
+ JSON.parse(response.body)
20
+ when 403
21
+ puts "403: Invalid API key"
22
+ exit 1
23
+ else
24
+ puts "#{response.code}: Something to wrong"
25
+ exit 1
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,50 @@
1
+ require 'thor'
2
+ require 'highline'
3
+ require 'pit'
4
+
5
+ module AboutP
6
+ class Command < Thor
7
+ desc :search, %(Fuzzy string searching at about p)
8
+ def search(query)
9
+ key = get_key || set_key
10
+ result = API.search(key, query)
11
+ result.each do |user|
12
+ extend_size = user.keys.map { |column| column.size }.max
13
+ user.each do |key, value|
14
+ puts "#{padding(key, extend_size)}: #{value}"
15
+ end
16
+ puts "-"*30
17
+ end
18
+ end
19
+
20
+ desc :set_key, %(Setting API key)
21
+ def set_key
22
+ key = HighLine.new.ask("Enter API key:") { |q| q.echo = "*" }
23
+ key = key.to_s
24
+ Pit.set("about_p", :data => {
25
+ "api_key" => key
26
+ })
27
+ key
28
+ end
29
+
30
+ private
31
+ def get_key
32
+ Pit.get("about_p")["api_key"]
33
+ end
34
+
35
+ def padding(value, extend_size)
36
+ padding_size = extend_size - value.size
37
+ value if padding_size < 0
38
+ value + (" " * padding_size)
39
+ end
40
+
41
+ class << self
42
+ # default_command で指定しても「aboutp クエリ」とかで呼び出すと
43
+ # クエリがコマンドだと認識されるので、
44
+ # handle_no_command_errorをハンドリングする
45
+ def handle_no_command_error(command, has_namespace = $thor_runner)
46
+ Command.new.search(command)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module AboutP
2
+ VERSION = "0.0.1"
3
+ end
data/lib/about_p.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "about_p/version"
2
+ require "about_p/command"
3
+ require "about_p/api"
4
+
5
+ module AboutP
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe AboutP do
4
+ describe "API" do
5
+ it "与えたAPIキーがヘッダーとして呼び出される" do
6
+ stub_request(:get, "https://about-p-kitak.sqale.jp/users/search.json?query=kitak").with(:headers => {"X-AboutP-API-Key" => '12345'}).to_return(:body => '[]')
7
+ AboutP::API.search('12345', 'kitak')
8
+ end
9
+ end
10
+
11
+ describe "Command" do
12
+
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'about_p'
3
+ require 'webmock/rspec'
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: about_p
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Keisuke KITA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: highline
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Fuzzy string searching at about p
112
+ email:
113
+ - kei.kita2501@gmail.com
114
+ executables:
115
+ - aboutp
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - .rspec
121
+ - .travis.yml
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - about_p.gemspec
127
+ - bin/aboutp
128
+ - lib/about_p.rb
129
+ - lib/about_p/api.rb
130
+ - lib/about_p/command.rb
131
+ - lib/about_p/version.rb
132
+ - spec/about_p_spec.rb
133
+ - spec/spec_helper.rb
134
+ homepage: https://github.com/kitak/about_p_cli
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.0.0
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Fuzzy string searching at about p
158
+ test_files:
159
+ - spec/about_p_spec.rb
160
+ - spec/spec_helper.rb