sudokku_cli 0.1.1 → 0.1.4

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
2
  SHA256:
3
- metadata.gz: 718a3e60b8f81a86a3fcded0b2f66887c6a888f3fe7fd7c907946f8385a53acb
4
- data.tar.gz: 8475568983126f7a04ac83e75fac9470ea61d27c44b08088f80796c67e2dba68
3
+ metadata.gz: 6ac8fbbc9ae4681c6bf1200cdf2caefffb53a21a5841d48d5c1bbd9613f54d47
4
+ data.tar.gz: 13c6a5e051554e36cc666d8950a63d91faf507bee23ca9d9e81b3ea9d541da66
5
5
  SHA512:
6
- metadata.gz: 27e108fcec7593e5f83f155e3bceb852d1c1512daf8a6076dde5dce5d8ed7f01fe782ee626ac36f9e4a51b5518439301f7a661ab593000ddc6aeb738bc3e1fd7
7
- data.tar.gz: 415c9b2e146ac6e70ba274e1aa1d0aa90bd269c07384ed927df057e30d9d5d3f7d5cf8a76e814074675f8041f34509c5b0c60ea0eb9e4f6446b5441532d3fc42
6
+ metadata.gz: 1f215c7fdfdbfc097b6f53b5c9223426517d24d12a39b9fa4480a779b18790c09487f6f2af6cd04c519172d58ecb37425d6baa1dfa481b0b6d328776f504b8a9
7
+ data.tar.gz: c2b98b71e1507e54510e027e7c4b24f7585939e225a996608fba1d4d180ac32b0ef4f406589ba08efce2340cdda001c62b8cd4715fc68a71740b38d426d815d6
data/Gemfile CHANGED
@@ -8,3 +8,4 @@ gemspec
8
8
  gem "rake", "~> 13.0"
9
9
 
10
10
  gem "minitest", "~> 5.0"
11
+ gem 'dotenv'
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sudokku_cli (0.1.1)
4
+ sudokku_cli (0.1.3)
5
5
  json
6
+ net-http
6
7
  netrc
7
8
  open-uri
8
9
 
@@ -10,8 +11,14 @@ GEM
10
11
  remote: https://rubygems.org/
11
12
  specs:
12
13
  date (3.3.3)
14
+ dotenv (2.8.1)
13
15
  json (2.6.1)
14
16
  minitest (5.17.0)
17
+ net-http (0.2.0)
18
+ net-protocol
19
+ uri
20
+ net-protocol (0.2.1)
21
+ timeout
15
22
  netrc (0.11.0)
16
23
  open-uri (0.2.0)
17
24
  stringio
@@ -21,12 +28,14 @@ GEM
21
28
  stringio (3.0.1)
22
29
  time (0.2.0)
23
30
  date
31
+ timeout (0.3.2)
24
32
  uri (0.11.0)
25
33
 
26
34
  PLATFORMS
27
35
  x86_64-linux
28
36
 
29
37
  DEPENDENCIES
38
+ dotenv
30
39
  minitest (~> 5.0)
31
40
  rake (~> 13.0)
32
41
  sudokku_cli!
data/README.md CHANGED
@@ -9,8 +9,8 @@ A CLI program for logging in to Sudokku git server.
9
9
  ## Usage
10
10
 
11
11
  Use `sudokku login` to log in to the Sudokku git server. This will try to connect to the git server using credentials saved
12
- in the .netrc file. If the credentials are not found, or are expired, you will be given a url to visit where you can log in.
13
- After successfully logging in, the program will save the newly generated credentials to the .netrc file.
12
+ in your .netrc file. If the credentials are not found, or are expired, you will be given a url to visit where you can log in.
13
+ After successfully logging in, the program will save the newly generated credentials to your .netrc file.
14
14
 
15
15
  [//]: # (## Development)
16
16
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SudokkuCli
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/sudokku_cli.rb CHANGED
@@ -4,41 +4,46 @@ require_relative "sudokku_cli/version"
4
4
  require 'netrc'
5
5
  require 'json'
6
6
  require 'open-uri'
7
+ require 'net/http'
8
+ require 'dotenv/load'
7
9
 
8
10
  module SudokkuCli
9
11
  class Error < StandardError; end
10
12
 
11
- ENDPOINT = 'https://git.sudokku.com'
13
+ ENDPOINT = ENV["ENDPOINT"] || 'https://git.sudokku.com'
12
14
 
13
- def send_request(path, params = {})
15
+ def self.send_request(path, params = {})
14
16
  uri = URI.join(ENDPOINT, path)
15
17
  uri.query = URI.encode_www_form(params)
16
18
  request = Net::HTTP::Get.new(uri.request_uri)
17
19
  netrc = Netrc.read
18
20
  user, password = netrc[uri.host]
19
21
  request.basic_auth(user, password)
20
- response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
22
+ response = Net::HTTP.start(uri.host, uri.port) do |http|
21
23
  http.request(request)
22
24
  end
23
25
  JSON.parse(response.body)
24
26
  end
25
27
 
26
- def login
28
+ def self.login
27
29
  response = send_request('/login')
28
30
  if response['status'] == 'success'
29
31
  puts 'You are logged in!'
30
32
  else
33
+ token = response['token']
31
34
  # credentials are not valid, prompt user to authenticate via browser
32
35
  puts "Please visit #{response['url']} to authenticate."
36
+ puts "Waiting for authentication..."
33
37
  # check for new credentials
34
38
  loop do
35
- response = send_request('/check-authentication', { 'token': response['token'] })
39
+ response = send_request('/check-authentication', { token: token })
36
40
  if response['status'] == 'success'
37
41
  # new credentials received, save to .netrc file
38
42
  netrc = Netrc.read
39
- netrc[ENDPOINT] = response['credentials']
43
+ host = ENDPOINT.gsub('https://', '').gsub('http://', '')
44
+ netrc[host] = response['credentials']
40
45
  netrc.save
41
- puts 'Successfully logged in!'
46
+ puts "Successfully logged in as #{response['credentials'][0]}!"
42
47
  break
43
48
  end
44
49
  sleep(5) # wait 5 seconds before checking again
data/sig/sudokku_cli.rbs CHANGED
@@ -1,4 +1,5 @@
1
1
  module SudokkuCli
2
+ ENDPOINT: String
2
3
  VERSION: String
3
4
  # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
5
  end
data/sudokku_cli.gemspec CHANGED
@@ -30,4 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.add_runtime_dependency "netrc"
31
31
  spec.add_runtime_dependency "json"
32
32
  spec.add_runtime_dependency "open-uri"
33
+ spec.add_runtime_dependency "net-http"
33
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sudokku_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tasos Maschalidis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-17 00:00:00.000000000 Z
11
+ date: 2023-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: netrc
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: net-http
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description:
56
70
  email:
57
71
  - tas.o.s@hotmail.com