Module: Github::Key::Upload
- Defined in:
- lib/github-key-upload.rb,
lib/github-key-upload/version.rb
Constant Summary collapse
- VERSION =
"0.0.3"
Class Method Summary collapse
- .check(options) ⇒ Object
- .check_for_both(options) ⇒ Object
- .check_for_key(options) ⇒ Object
- .check_for_title(options) ⇒ Object
- .create_auth(options) ⇒ Object
- .upload(options) ⇒ Object
Class Method Details
.check(options) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/github-key-upload.rb', line 33 def self.check() github = create_auth() matching_key = nil search_key = [:search_key].to_s search_proc = [:search_proc] github.users.keys.all.each_page do |page| if page.map {|k| k[search_key]}.include?(search_proc.call()) matching_key = true break end end matching_key end |
.check_for_both(options) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/github-key-upload.rb', line 18 def self.check_for_both() github = create_auth() matching_key = nil github.users.keys.all.each_page do |page| if page.map {|k| [k["title"], k["key"]]}.include?( [[:title], File.read([:key]).split(" ")[0,2].join(" ")]) matching_key = true break end end matching_key end |
.check_for_key(options) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/github-key-upload.rb', line 49 def self.check_for_key() check(.merge({ :search_key => :key, :search_proc => Proc.new {|opts| File.read(opts[:key]).split(" ")[0,2].join(" ") } })) end |
.check_for_title(options) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/github-key-upload.rb', line 58 def self.check_for_title() check(.merge({ :search_key => :title, :search_proc => Proc.new {|opts| opts[:title]} })) end |
.create_auth(options) ⇒ Object
7 8 9 10 11 |
# File 'lib/github-key-upload.rb', line 7 def self.create_auth() github = Github.new :basic_auth => "#{[:user]}:#{[:password]}" github.oauth.create 'scopes' => ['user'] github end |
.upload(options) ⇒ Object
13 14 15 16 |
# File 'lib/github-key-upload.rb', line 13 def self.upload() github = create_auth() github.users.keys.create({:title => [:title], :key => File.read([:key])}) end |