gistrb 0.1.0 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a2aefb784623a1659b2bafd3eeeec8e050766df6
4
- data.tar.gz: fb813f490cf60efb217ea2b3f46d439ac52b4daf
2
+ SHA256:
3
+ metadata.gz: f57c0cc5c36dd8ef2baebaeb474fd3b0b4d91312869375f5fc9df0f1c5780cc5
4
+ data.tar.gz: 5a061644fd3aa98c3de9a64eccb65e9fd0d89cf87e7efed27f373ce5227bb6a2
5
5
  SHA512:
6
- metadata.gz: 98aca49aa436b184c517c61e5b7fdb8acffab6b900cbf279d7656e85696bf7ec7a6d2450547befeb8c63b1c04338a72fb585768a63df1975e202c1009414bdcf
7
- data.tar.gz: 1fb6927724c4cdef4f360fed6139fa9909b3980bee60503123034eaae08d8d43d018c0b04bbab615292b107c003651615e610e904f9ed446be8b1920e7d04d6a
6
+ metadata.gz: 1ca6612dd6b0846aaaeb2f511fc92fc2902c867e62e28586f45f1ebfcad02178f148ea93e381eaccc06cd345a209529ea694589a89062cd716060832d903db6e
7
+ data.tar.gz: 9daca6856b2667e75649a5126f13e0a2bc41d69d2bfbaff28b74eafb23025409cf21b8e24b9ba24654f0f05fe679c0a297c6ccd1247c4be0822439f44ab646f2
@@ -0,0 +1,5 @@
1
+ Metrics/MethodLength:
2
+ Enabled: false
3
+
4
+ Metrics/LineLength:
5
+ Enabled: false
@@ -1,8 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.2
4
- - jruby-19mode
5
- - rbx-2
6
4
  before_install: gem install bundler -v 1.15
7
5
  deploy:
8
6
  provider: rubygems
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017 Cameron Roe
3
+ Copyright (c) 2018 Cameron Roe
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -29,6 +29,7 @@ Option | Description
29
29
  -p | --public | Post the Gist as public (it posts as private by default)
30
30
  -d [DESC] | --description [DESC] | Use [DESC] as the description for the Gist
31
31
  -c | --clipboard | Automatically put the created Gist URL into your clipboard (beta)
32
+ -n | --netrc | Utilize .netrc file for storing/retrieving authorization token
32
33
 
33
34
  ## Installation:
34
35
  Using RubyGems, simply run this command:
@@ -45,4 +46,4 @@ sudo apt-get install xclip
45
46
  ## License
46
47
  MIT License
47
48
 
48
- Copyright © 2017 Cameron Roe
49
+ Copyright © 2018 Cameron Roe
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'bundler/gem_tasks'
2
2
 
3
3
  task :default do
4
- puts "Need to add tests"
4
+ puts 'Need to add tests'
5
5
  end
data/bin/gistrb CHANGED
@@ -13,6 +13,10 @@ OptionParser.new do |opts|
13
13
  options[:sign_in] = s
14
14
  end
15
15
 
16
+ opts.on('-n', '--netrc', 'Use information from netrc when signing in') do |n|
17
+ options[:netrc] = n
18
+ end
19
+
16
20
  opts.on('--sign-out', 'Clear out saved user') do |s|
17
21
  options[:sign_out] = s
18
22
  end
@@ -34,11 +38,6 @@ end.parse!
34
38
  files = ARGV.clone
35
39
  ARGV.clear
36
40
 
37
- # Get anything sent by STDIN to support cat and pasting.
38
- if !STDIN.tty? || files.empty? then
39
- stdin = STDIN.read
40
- end
41
-
42
41
  if options[:sign_out]
43
42
  File.delete(Gist::ACCESS_TOKEN_PATH) if File.exist?(Gist::ACCESS_TOKEN_PATH)
44
43
  exit
@@ -48,12 +47,16 @@ if options[:sign_in]
48
47
  print 'Username: '
49
48
  username = gets.chomp
50
49
  password = Gist::Helpers.get_password
51
- @user = Gist::User.new(username, password)
50
+ @user = Gist::User.new(username, password, options[:netrc])
52
51
  @user.authenticate
52
+ exit
53
53
  end
54
54
 
55
+ # Get anything sent by STDIN to support cat and pasting.
56
+ stdin = STDIN.read if !STDIN.tty? || files.empty?
57
+
55
58
  if options[:user]
56
- @user = Gist::User.new
59
+ @user = Gist::User.new(nil, nil, options[:netrc])
57
60
  @user.authenticate
58
61
  unless @user.access_token
59
62
  STDERR.puts 'ERROR: There is no user saved. You need to sign in.'
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency 'clipboard', '~> 1.1'
25
25
  spec.add_dependency 'ffi', '~> 1.9.18' if RUBY_PLATFORM =~ /win32/i
26
26
  spec.add_dependency 'highline', '~> 1.7'
27
+ spec.add_dependency 'netrc', '~> 0.11.0'
27
28
  end
@@ -2,6 +2,8 @@ require 'net/https'
2
2
  require 'highline/import'
3
3
  require 'json'
4
4
  require 'clipboard'
5
+ require 'netrc'
6
+ require 'socket'
5
7
 
6
8
  # Library requires
7
9
  require 'gist/user'
@@ -2,7 +2,7 @@ module Gist
2
2
  # Helper class for clipboard functions
3
3
  class Clipboard
4
4
  # Wraps clipboard functionality
5
- def self::copy(str)
5
+ def self.copy(str)
6
6
  Clipboard.clear
7
7
  Clipboard.copy(str)
8
8
  end
@@ -2,7 +2,7 @@ module Gist
2
2
  # Helper methods for getting input
3
3
  class Helpers
4
4
  # Method to wrap a highline call to hide a passworded input
5
- def self::get_password(prompt = 'Password: ')
5
+ def self.get_password(prompt = 'Password: ')
6
6
  ask(prompt) { |q| q.echo = false }
7
7
  end
8
8
  end
@@ -15,27 +15,23 @@ module Gist
15
15
  end
16
16
 
17
17
  def submit(stdin)
18
- unless stdin.nil? then
19
- @source_files['STDIN'] = {
20
- 'content' => stdin
21
- }
22
- end
18
+ unless stdin.nil?
19
+ @source_files['STDIN'] = {
20
+ 'content' => stdin
21
+ }
22
+ end
23
23
  body = {
24
24
  'files' => @source_files,
25
25
  'public' => @public,
26
26
  'description' => @description
27
27
  }.to_json
28
28
  headers ||= {}
29
- unless @user.nil?
30
- headers['Authorization'] = "token #{@user.access_token}"
31
- end
29
+ headers['Authorization'] = "token #{@user.access_token}" unless @user.nil?
32
30
  response = @http.post('/gists', body, headers)
33
31
  JSON.parse(response.body)['html_url']
34
32
  end
35
33
 
36
- private
37
-
38
- def load_code(filename)
34
+ private def load_code(filename)
39
35
  file = File.open(filename)
40
36
  file_str = ''
41
37
  file.each do |line|
@@ -6,9 +6,10 @@ module Gist
6
6
  attr_accessor :access_token # Personal access token
7
7
 
8
8
  # Create the GistUser instance
9
- def initialize(username = nil, password = nil)
10
- @username = username
11
- @password = password
9
+ def initialize(username = nil, password = nil, netrc = nil)
10
+ @username ||= username
11
+ @password ||= password
12
+ @netrc ||= netrc
12
13
  @http = Net::HTTP.new(Gist::API_URL, Gist::API_PORT)
13
14
  @http.use_ssl = true
14
15
  @access_token = load_token if saved?
@@ -42,20 +43,38 @@ module Gist
42
43
  end
43
44
 
44
45
  private def saved?
45
- File.exist?(Gist::ACCESS_TOKEN_PATH)
46
+ if @netrc.nil?
47
+ File.exist?(Gist::ACCESS_TOKEN_PATH)
48
+ else
49
+ netrc = Netrc.read
50
+ _username, token = netrc['api.github.com']
51
+ !token.nil?
52
+ end
46
53
  end
47
54
 
48
55
  private def save
49
- unless Dir.exist?(File.dirname(Gist::ACCESS_TOKEN_PATH))
50
- Dir.mkdir(File.dirname(Gist::ACCESS_TOKEN_PATH))
56
+ if @netrc.nil?
57
+ unless Dir.exist?(File.dirname(Gist::ACCESS_TOKEN_PATH))
58
+ Dir.mkdir(File.dirname(Gist::ACCESS_TOKEN_PATH))
59
+ end
60
+ token_file = File.new(Gist::ACCESS_TOKEN_PATH, 'w+')
61
+ token_file << @access_token
62
+ token_file.close
63
+ else
64
+ netrc = Netrc.read
65
+ netrc['api.github.com'] = @username, @access_token
66
+ netrc.save
51
67
  end
52
- token_file = File.new(Gist::ACCESS_TOKEN_PATH, 'w+')
53
- token_file << @access_token
54
- token_file.close
55
68
  end
56
69
 
57
70
  private def load_token
58
- File.readlines(Gist::ACCESS_TOKEN_PATH).first
71
+ if @netrc.nil?
72
+ File.readlines(Gist::ACCESS_TOKEN_PATH).first
73
+ else
74
+ netrc = Netrc.read
75
+ _username, token = netrc['api.github.com']
76
+ token
77
+ end
59
78
  end
60
79
 
61
80
  private def auth_obj
@@ -64,7 +83,7 @@ module Gist
64
83
  req['Content-Type'] = 'application/json'
65
84
  req.body = {
66
85
  scopes: ['gist'], # Only need Gist scope
67
- note: 'Gist access for GistRB client',
86
+ note: "Gist access for GistRB client on #{Socket.gethostname}",
68
87
  note_url: 'https://github.com/cameronbroe/gistrb'
69
88
  }.to_json
70
89
  req
@@ -1,3 +1,3 @@
1
1
  module Gist
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gistrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Roe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-16 00:00:00.000000000 Z
11
+ date: 2018-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: netrc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.11.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.11.0
69
83
  description:
70
84
  email:
71
85
  - cameron@cameronbroe.com
@@ -77,6 +91,7 @@ extensions: []
77
91
  extra_rdoc_files: []
78
92
  files:
79
93
  - ".gitignore"
94
+ - ".rubocop.yml"
80
95
  - ".travis.yml"
81
96
  - Gemfile
82
97
  - LICENSE
@@ -112,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
127
  version: '0'
113
128
  requirements: []
114
129
  rubyforge_project:
115
- rubygems_version: 2.6.10
130
+ rubygems_version: 2.7.6
116
131
  signing_key:
117
132
  specification_version: 4
118
133
  summary: A command-line utility to manage GitHub Gists