get_github_pub_keys 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: ffba8e61b651473d2887207d6b884579718a327e
4
+ data.tar.gz: 3363a00f33b108742c4a20e5e4361ead5da0b8dd
5
+ SHA512:
6
+ metadata.gz: cda479570bba6520a1c9a1099195a4592cf70b066f06bd4f8a9a687c747bca3fe52376d3e8225e607d89f4da7ba1ef56113f5731928db53f6d11dd338e447455
7
+ data.tar.gz: 0cca76d5479e594603fca6f83ce3fadce24b04dfac3d279cf60388ad1d1f9b53e371bf7855794df7f7b9404fcb5290babee148c8ec5b22cd42758c8c7fef2d18
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'GetGithubPubKeys'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ require 'rake/testtask'
23
+
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+
32
+ task default: :test
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+
3
+ module GetGithubPubKeys
4
+
5
+ class Client
6
+ include Connection
7
+ include GetGithubPubKeys::Files
8
+ attr_accessor :path
9
+
10
+ def initialize(user=nil)
11
+ @user = user
12
+ end
13
+
14
+ # confirm .ssh directory
15
+ def confirm
16
+ ssh_create unless ssh_exists?
17
+ rescue
18
+ raise ".ssh don't exists."
19
+ end
20
+
21
+ def find_and_create( options = {} )
22
+ response = Connection.new(options).get("users/#{@user}/keys")
23
+ public_keys = response.body
24
+
25
+ # FIXME:response.raise_errorが正しく動作するのかを確認する
26
+ # 登録されていないUserだとfile_nameがとれない
27
+ if public_keys.is_a? Array
28
+ public_keys.each do |public_key|
29
+ GetGithubPubKeys::Files.create public_key["id"], public_key["key"]
30
+ end
31
+ else
32
+ GetGithubPubKeys::Files.create public_keys["id"], public_keys["key"]
33
+ end
34
+ end
35
+ end
36
+ end
37
+
@@ -0,0 +1,18 @@
1
+ # coding: utf-8
2
+ require 'faraday'
3
+ require 'faraday_middleware'
4
+
5
+ module GetGithubPubKeys
6
+ module Connection
7
+ def self.new( options = {} )
8
+ Faraday.new( url: 'https://api.github.com' ) do |faraday|
9
+ faraday.request :url_encoded
10
+ faraday.request :json
11
+ faraday.response :json, :content_type => /\bjson$/
12
+ faraday.response :logger
13
+ faraday.adapter Faraday.default_adapter
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ require 'logger'
3
+
4
+ module GetGithubPubKeys
5
+ module Files
6
+ DEFAULT_SSH_DIRECTORY = "/#{ENV["HOME"]}/.ssh".freeze
7
+ DEFAULT_IDENTIFY = '.pub'.freeze
8
+ attr_accessor :path
9
+ #
10
+ # This method confirm exists .ssh directory.
11
+ def ssh_exists?
12
+ File.exists(DEFAULT_SSH_DIRECTORY)
13
+ end
14
+ #
15
+ # create /HOME_DIRECOTY/.ssh directory
16
+ def ssh_create
17
+ Dir.mkdir("#{ENV["HOME"]}/#{DEFAULT_SSH_DIRECTORY}")
18
+ end
19
+
20
+ # public_keys file create to .ssh directory.
21
+ def self.create(file_name, body)
22
+ file_name = file_name.to_s
23
+ file_name = File.basename(file_name)
24
+ file_name = file_name + "_" + Time.now.strftime("%Y%0m%0d%0H%0M%0S") + DEFAULT_IDENTIFY
25
+ body = body.gsub("\n","")
26
+ File.open(DEFAULT_SSH_DIRECTORY + "/" + file_name, "w") do |file|
27
+ file.puts body
28
+ end
29
+ puts "Create public_key file: #{file_name}."
30
+ rescue => e
31
+ puts e.message
32
+ nil
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,43 @@
1
+ # coding: utf-8
2
+
3
+ require 'faraday'
4
+
5
+ module GetGithubPubKeys
6
+ module Response
7
+ class RaiseError < Faraday::Response::Middleware
8
+ def on_complete(env)
9
+ case env[:status].to_i
10
+ when 400
11
+ raise GetGithubPubKeys::BadRequest, error_message(env)
12
+ when 401
13
+ raise GetGithubPubKeys::NotAuthorized, error_message(env)
14
+ when 403
15
+ raise GetGithubPubKyes::Forbidden, error_message(env)
16
+ when 404
17
+ raise GetGithubPubKeys::NotFound, error_message(env)
18
+ when 400...500
19
+ raise GetGithubPubKeys::ClientError, error_message(env)
20
+ when 500
21
+ raise GetGithubPubKeys::InternalServerError, error_message(env)
22
+ when 503
23
+ raise GetGithubPubKeys::ServiceUnavailable, error_message(env)
24
+ when 500...600
25
+ raise GetGithubPubKeys::ServiceUnavailable, error_message(env)
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def error_message(env)
32
+ body = env[:body]
33
+ if body.nil?
34
+ nil
35
+ elsif body['error'] && body['error']['message']
36
+ body['error']['message']
37
+ elsif body['fault'] && body['fault']['faultstring']
38
+ body['fault']['faultstring']
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,8 @@
1
+ # coding: utf-8
2
+
3
+ require 'faraday'
4
+ require 'get_github_pub_keys/response/raise_error'
5
+
6
+ Faraday.register_middleware :response,
7
+ raise_error: -> { GetGithubPubKeys::Response::RaiseError }
8
+
@@ -0,0 +1,3 @@
1
+ module GetGithubPubKeys
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,14 @@
1
+ # coding: utf-8
2
+
3
+ # FIXME: module, classの区別とrequire, include, extendを区別する
4
+ require 'get_github_pub_keys/connection'
5
+ require 'get_github_pub_keys/files'
6
+ require 'get_github_pub_keys/client'
7
+
8
+ module GetGithubPubKeys
9
+ # Fixme:instance.classが
10
+ def self.new(user = nil)
11
+ return if user.nil?
12
+ Client.new(user)
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :get_github_pub_keys do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class GetGithubPubKeysTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, GetGithubPubKeys
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Load support files
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
+
12
+ # Load fixtures from the engine
13
+ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
14
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
15
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: get_github_pub_keys
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kazuyuki Ikeda
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.9
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.9
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday_middleware
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
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
+ description: This gem get publick_keys from registered of github.
84
+ email:
85
+ - gankai1104@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - lib/get_github_pub_keys/client.rb
91
+ - lib/get_github_pub_keys/connection.rb
92
+ - lib/get_github_pub_keys/files.rb
93
+ - lib/get_github_pub_keys/response/raise_error.rb
94
+ - lib/get_github_pub_keys/response.rb
95
+ - lib/get_github_pub_keys/version.rb
96
+ - lib/get_github_pub_keys.rb
97
+ - lib/tasks/get_github_pub_keys_tasks.rake
98
+ - MIT-LICENSE
99
+ - Rakefile
100
+ - test/get_github_pub_keys_test.rb
101
+ - test/test_helper.rb
102
+ homepage: https://github.com/kikeda1104/get_github_pub_keys
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.1.3
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: The gem get public_keys from github
126
+ test_files:
127
+ - test/get_github_pub_keys_test.rb
128
+ - test/test_helper.rb