krb 0.0.2 → 0.0.3

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: 48e7ff5740c7d0fc100376a8a37e048ea22a01d4fbfbbb18714373500f280675
4
- data.tar.gz: 0b517654b81e69688a7ddc9420c388564aaaf001c3008c241d520b8910125190
3
+ metadata.gz: f18b7c1de9a96f5793cceaf607ed187a0852341e40b0db323a3347100f98cb49
4
+ data.tar.gz: 8563324a0629b919afe389cb0c353058d5180ecdd4a53f2f771c5c0e4af4588f
5
5
  SHA512:
6
- metadata.gz: b9c73662fa2abb10c1926cfa2025fc41cd3e4814bd44c2980a07aac128bb5a262b065751352279d0f21bcb8716e740cd935c64c4d458103db106da02c49cbe0c
7
- data.tar.gz: 20a0de6dbd255545379f8f5a65de2a5b281e03a6a04c3b5b69c34bad5f45a3683d77724ba68907ae52fde74766694c031e12b2fe9070680206262e7df5ac565f
6
+ metadata.gz: 93236544418397a1bde3f983082f9c27aff3ebd9631a6a9bd2438cabbcf3d4c5dd9b4bc86855641e378758df0d8055b32e54a264cc18625834944974d60386eb
7
+ data.tar.gz: 17eaf0267611c018635681bab2ac3f979e0507cb38b7e21d47d6edb8f2a04e0d9d1dc7408caa582c3912a05c88821f40039f75dba7c2169eb05079270ce5c0e8
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ /.storefront_setup
data/Gemfile CHANGED
@@ -5,3 +5,6 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
5
5
  # Specify your gem's dependencies in krb.gemspec
6
6
  gemspec
7
7
  gem 'tty'
8
+ gem 'tty-prompt'
9
+ gem 'http'
10
+ gem 'rack'
@@ -1,21 +1,34 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- krb (0.0.2)
4
+ krb (0.0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ addressable (2.5.2)
10
+ public_suffix (>= 2.0.2, < 4.0)
9
11
  diff-lcs (1.3)
12
+ domain_name (0.5.20180417)
13
+ unf (>= 0.0.5, < 1.0.0)
10
14
  equatable (0.5.0)
11
15
  hitimes (1.3.0)
12
- kramdown (1.16.2)
16
+ http (3.3.0)
17
+ addressable (~> 2.3)
18
+ http-cookie (~> 1.0)
19
+ http-form_data (~> 2.0)
20
+ http_parser.rb (~> 0.6.0)
21
+ http-cookie (1.0.3)
22
+ domain_name (~> 0.5)
23
+ http-form_data (2.1.1)
24
+ http_parser.rb (0.6.0)
13
25
  necromancer (0.4.0)
14
26
  pastel (0.7.2)
15
27
  equatable (~> 0.5.0)
16
28
  tty-color (~> 0.4.0)
29
+ public_suffix (3.0.3)
30
+ rack (2.0.5)
17
31
  rake (10.5.0)
18
- rouge (3.1.1)
19
32
  rspec (3.8.0)
20
33
  rspec-core (~> 3.8.0)
21
34
  rspec-expectations (~> 3.8.0)
@@ -29,86 +42,25 @@ GEM
29
42
  diff-lcs (>= 1.2.0, < 2.0)
30
43
  rspec-support (~> 3.8.0)
31
44
  rspec-support (3.8.0)
32
- strings (0.1.2)
33
- unicode-display_width (~> 1.4.0)
34
- unicode_utils (~> 1.4.0)
35
- thor (0.20.0)
36
45
  timers (4.1.2)
37
46
  hitimes
38
- tty (0.8.1)
39
- bundler (~> 1.16, < 2.0)
40
- equatable (~> 0.5.0)
41
- pastel (~> 0.7.2)
42
- thor (~> 0.20.0)
43
- tty-color (~> 0.4.2)
44
- tty-command (~> 0.8.0)
45
- tty-config (~> 0.2.0)
46
- tty-cursor (~> 0.5.0)
47
- tty-editor (~> 0.4.0)
48
- tty-file (~> 0.6.0)
49
- tty-font (~> 0.2.0)
50
- tty-markdown (~> 0.4.0)
51
- tty-pager (~> 0.11.0)
52
- tty-platform (~> 0.1.0)
53
- tty-progressbar (~> 0.15.0)
54
- tty-prompt (~> 0.16.1)
55
- tty-screen (~> 0.6.4)
56
- tty-spinner (~> 0.8.0)
57
- tty-table (~> 0.10.0)
58
- tty-tree (~> 0.1.0)
59
- tty-which (~> 0.3.0)
47
+ tty (0.1.0)
60
48
  tty-color (0.4.3)
61
- tty-command (0.8.2)
62
- pastel (~> 0.7.0)
63
- tty-config (0.2.0)
64
- tty-cursor (0.5.0)
65
- tty-editor (0.4.0)
66
- tty-prompt (~> 0.16.0)
67
- tty-which (~> 0.3.0)
68
- tty-file (0.6.0)
69
- diff-lcs (~> 1.3.0)
70
- pastel (~> 0.7.2)
71
- tty-prompt (~> 0.16.1)
72
- tty-font (0.2.0)
73
- tty-markdown (0.4.0)
74
- kramdown (~> 1.16.2)
75
- pastel (~> 0.7.2)
76
- rouge (~> 3.1.0)
77
- strings (~> 0.1.0)
78
- tty-color (~> 0.4.2)
79
- tty-screen (~> 0.6.4)
80
- tty-pager (0.11.0)
81
- strings (~> 0.1.0)
82
- tty-screen (~> 0.6.4)
83
- tty-which (~> 0.3.0)
84
- tty-platform (0.1.0)
85
- tty-progressbar (0.15.1)
86
- tty-cursor (~> 0.5.0)
87
- tty-screen (~> 0.6.4)
88
- unicode-display_width (~> 1.3)
89
- tty-prompt (0.16.1)
49
+ tty-cursor (0.6.0)
50
+ tty-prompt (0.17.0)
90
51
  necromancer (~> 0.4.0)
91
52
  pastel (~> 0.7.0)
92
53
  timers (~> 4.0)
93
- tty-cursor (~> 0.5.0)
94
- tty-reader (~> 0.3.0)
95
- tty-reader (0.3.0)
96
- tty-cursor (~> 0.5.0)
54
+ tty-cursor (~> 0.6.0)
55
+ tty-reader (~> 0.4.0)
56
+ tty-reader (0.4.0)
57
+ tty-cursor (~> 0.6.0)
97
58
  tty-screen (~> 0.6.4)
98
59
  wisper (~> 2.0.0)
99
60
  tty-screen (0.6.5)
100
- tty-spinner (0.8.0)
101
- tty-cursor (>= 0.5.0)
102
- tty-table (0.10.0)
103
- equatable (~> 0.5.0)
104
- necromancer (~> 0.4.0)
105
- pastel (~> 0.7.2)
106
- strings (~> 0.1.0)
107
- tty-screen (~> 0.6.4)
108
- tty-tree (0.1.0)
109
- tty-which (0.3.0)
110
- unicode-display_width (1.4.0)
111
- unicode_utils (1.4.0)
61
+ unf (0.1.4)
62
+ unf_ext
63
+ unf_ext (0.0.7.5)
112
64
  wisper (2.0.0)
113
65
 
114
66
  PLATFORMS
@@ -116,10 +68,13 @@ PLATFORMS
116
68
 
117
69
  DEPENDENCIES
118
70
  bundler (~> 1.16)
71
+ http
119
72
  krb!
73
+ rack
120
74
  rake (~> 10.0)
121
75
  rspec (~> 3.0)
122
76
  tty
77
+ tty-prompt
123
78
 
124
79
  BUNDLED WITH
125
80
  1.16.1
data/exe/krb ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'krb'
4
+
5
+ entrypoint = ARGV[0]
6
+
7
+ if entrypoint == 'setup'
8
+ Krb::Setup::Base.process
9
+ elsif entrypoint == 'import'
10
+ Krb::Import.process
11
+ elsif entrypoint == 'download'
12
+ Krb::Download.process
13
+ else
14
+ puts 'Please specify a command.'
15
+ end
@@ -0,0 +1,24 @@
1
+ # require 'socket'
2
+ # require 'rack/utils'
3
+
4
+ # server = TCPServer.new 5678
5
+
6
+ # def query_params(req)
7
+ # return if req.match(/\/favicon\.ico/)
8
+ # params = req.to_s.split('?').last.to_s.split(' ').first
9
+ # Rack::Utils.parse_nested_query(params)
10
+ # end
11
+
12
+ # while session = server.accept
13
+ # request = session.gets
14
+ # puts query_params(request).to_s
15
+
16
+ # session.print "HTTP/1.1 200\r\n"
17
+ # session.print "Content-Type: text/html\r\n"
18
+ # session.print "\r\n"
19
+ # session.print "Hello world! The time is #{Time.now}"
20
+
21
+ # session.close
22
+
23
+ # # server.close
24
+ # end
@@ -7,9 +7,50 @@ module Krb
7
7
  def self.process(*args, &block)
8
8
  new(*args, &block).process
9
9
  end
10
+
11
+ def prompt
12
+ ::TTY::Prompt.new(interrupt: :exit)
13
+ end
14
+
15
+ def setup_file_name
16
+ '.storefront_setup'
17
+ end
18
+
19
+ def setup_file_path
20
+ [Dir.pwd, setup_file_name].join('/')
21
+ end
22
+
23
+ def verify_setup
24
+ return if key?
25
+ msg = <<-END.gsub(/^\s+\|/, '')
26
+ |-----
27
+ |ok
28
+ |-----
29
+ END
30
+ print msg
31
+ end
32
+
33
+ private
34
+
35
+ def key?
36
+ config ? config.storefront_token.present? : false
37
+ end
38
+
39
+ def config_file_path
40
+ [Dir.pwd, '.krb'].join('/')
41
+ end
42
+
43
+ def config_file?
44
+ File.exist?(config_file_path)
45
+ end
46
+
47
+ def config
48
+ return unless config_file?
49
+ YAML.load_file(config_file_path)
50
+ end
10
51
  end
11
52
  end
12
53
 
13
54
  Dir[File.dirname(__FILE__) + '/**/*.rb'].each do |file|
14
55
  require file
15
- end
56
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Krb
4
+ # Sets up configuration
5
+ class Download < ApplicationService
6
+ def initialize
7
+ super
8
+ verify_setup
9
+ end
10
+
11
+ def process
12
+ 'ok download'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Krb
4
+ # Sets up configuration
5
+ class Import < ApplicationService
6
+ def initialize
7
+ super
8
+ verify_setup
9
+ end
10
+
11
+ def process
12
+ 'ok import'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'http'
4
+ require 'tty/prompt'
5
+
6
+ module Krb
7
+ module Setup
8
+ # Sets up configuration
9
+ class AskShopifyAccessKey < ApplicationService
10
+ def initialize(setup)
11
+ @shop_name = setup.dig('shop_name')
12
+ end
13
+
14
+ def process
15
+ if graphql_endpoint?
16
+ input
17
+ else
18
+ abort("\nInvalid credentials. Please try again.\n")
19
+ return ''
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def input
26
+ @input ||= prompt.mask(ask_phrase) { |q| q.required true }
27
+ end
28
+
29
+ def ask_phrase
30
+ 'Please enter your shopify storefront access key : '
31
+ end
32
+
33
+ def graphql_endpoint?
34
+ response = HTTP.headers(graphql_headers).post(graphql_url, body: graphql_payload)
35
+ response.code == 200
36
+ end
37
+
38
+ def graphql_headers
39
+ {
40
+ 'Content-Type' => 'application/graphql',
41
+ 'X-Shopify-Storefront-Access-Token' => input
42
+ }
43
+ end
44
+
45
+ def graphql_payload
46
+ '{ shop { name } }'
47
+ end
48
+
49
+ def graphql_url
50
+ "https://#{@shop_name}.myshopify.com/api/graphql"
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'http'
4
+ require 'tty/prompt'
5
+
6
+ module Krb
7
+ module Setup
8
+ # Sets up configuration
9
+ class AskShopifyShopName < ApplicationService
10
+ def process
11
+ prompt.ask(ask_phrase) { |q| q.required true }
12
+ end
13
+
14
+ private
15
+
16
+ def input
17
+ @input ||= prompt.ask(ask_phrase) { |q| q.required true }
18
+ end
19
+
20
+ def ask_phrase
21
+ 'Please enter your shopify shop name : '
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tty/prompt'
4
+ require 'yaml'
5
+
6
+ module Krb
7
+ module Setup
8
+ # Sets up configuration
9
+ class Base < ApplicationService
10
+ def process
11
+ shopify_prompts
12
+ language_prompt
13
+ wrap_up
14
+ end
15
+
16
+ private
17
+
18
+ def setup
19
+ @setup ||= begin
20
+ if File.exist?(setup_file_path)
21
+ YAML.load_file(setup_file_path)
22
+ else
23
+ {}
24
+ end
25
+ end
26
+ end
27
+
28
+ def wrap_up
29
+ File.open(setup_file_path, 'w+') { |f| f.write(setup.to_yaml) }
30
+ Krb::Setup::GitIgnore.process
31
+ end
32
+
33
+ def shopify_prompts
34
+ setup['shop_name'] = Krb::Setup::AskShopifyShopName.process
35
+ setup['access_key'] = Krb::Setup::AskShopifyAccessKey.process(setup)
36
+ end
37
+
38
+ def language_prompt
39
+ input = prompt.select('Select your library :', %w[php rails node])
40
+ setup['language'] = input
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Krb
4
+ module Setup
5
+ # Sets up configuration
6
+ class GitIgnore < ApplicationService
7
+ def process
8
+ return if has_gitignore? && is_ignored?
9
+ add_gitignore unless has_gitignore?
10
+ write_to_gitignore unless is_ignored?
11
+ end
12
+
13
+ private
14
+
15
+ def write_to_gitignore
16
+ open(dot_gitignore, 'a') { |f| f << "\n#{ignore_path}\n" }
17
+ end
18
+
19
+ def add_gitignore
20
+ File.open(dot_gitignore, 'w+') { |f| f.write('') }
21
+ end
22
+
23
+ def is_ignored?
24
+ File.readlines(dot_gitignore).grep(/#{ignore_path}/).size >= 1
25
+ end
26
+
27
+ def has_gitignore?
28
+ File.exist?(dot_gitignore)
29
+ end
30
+
31
+ def dot_gitignore
32
+ [Dir.pwd, '.gitignore'].join('/')
33
+ end
34
+
35
+ def ignore_path
36
+ "/#{setup_file_name}"
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Krb
4
- VERSION = '0.0.2'.freeze
4
+ VERSION = '0.0.3'.freeze
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: krb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - bbnnt
@@ -55,7 +55,8 @@ dependencies:
55
55
  description: CLI tools to interact with a shopify store
56
56
  email:
57
57
  - ben@dee.mx
58
- executables: []
58
+ executables:
59
+ - krb
59
60
  extensions: []
60
61
  extra_rdoc_files: []
61
62
  files:
@@ -69,14 +70,18 @@ files:
69
70
  - README.md
70
71
  - Rakefile
71
72
  - bin/console
72
- - bin/krb
73
73
  - bin/setup
74
+ - exe/krb
75
+ - http_server.rb
74
76
  - krb.gemspec
75
77
  - lib/krb.rb
76
78
  - lib/krb/application_service.rb
77
- - lib/krb/installer/base.rb
78
- - lib/krb/php/base.rb
79
- - lib/krb/ruby/base.rb
79
+ - lib/krb/download.rb
80
+ - lib/krb/import.rb
81
+ - lib/krb/setup/ask_shopify_access_key.rb
82
+ - lib/krb/setup/ask_shopify_shop_name.rb
83
+ - lib/krb/setup/base.rb
84
+ - lib/krb/setup/git_ignore.rb
80
85
  - lib/krb/version.rb
81
86
  homepage: https://ngx.host
82
87
  licenses:
data/bin/krb DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'krb'
4
- Krb::Installer::Base.process
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'tty/prompt'
4
-
5
- module Krb
6
- module Installer
7
- # syntactic sugar
8
- class Base < ::Krb::ApplicationService
9
- def process
10
- verify_key
11
- end
12
-
13
- private
14
-
15
- def verify_key
16
- return if File.exist?('~/.storefront')
17
- prompt = ::TTY::Prompt.new
18
-
19
- x = prompt.ask('What is your name?') do |q|
20
- q.required true
21
- end
22
-
23
- pp x
24
- end
25
- end
26
- end
27
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Krb
4
- module Php
5
- # entrypoiny for php tools
6
- class Base < ::Krb::ApplicationService
7
- def self.import
8
- 'Import php'
9
- end
10
- end
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Krb
4
- module Ruby
5
- # entrypoiny for php tools
6
- class Base < ::Krb::ApplicationService
7
- def self.import
8
- 'Import ruby'
9
- end
10
- end
11
- end
12
- end