krb 0.0.15 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16c66e849f0804928047b4f60236a32f2f27100b4ad1232ecc1884903bc72c9b
4
- data.tar.gz: 1a8c27b06a89d03f12ec116adb5132353859cea8d650540b9f3ab7a323dd294c
3
+ metadata.gz: da97684e23279c468a024efa73198522bfc137ffc697730af3a58ae923883a27
4
+ data.tar.gz: 3e459d2dd69bc70bf5c95c106af15f24b232a1cdc756535b024ffe3e52697f78
5
5
  SHA512:
6
- metadata.gz: aa89bc3221a493354cb9586245467a5df1f01f3afcb0de3b7ce2d209c12e546df48ad1c01f06bb7730bd1e79e5f816bc308d08c1a803226c0aa36fe12806347d
7
- data.tar.gz: 8873ca48989983dd8eba56acfeaa33ebb0f58dd6571787338e39f125d6ade48379481f2e24238d684f6fe89b1627d54f16cb877af3e9ab4742ce372864c3a62d
6
+ metadata.gz: ea200a33e22baf6c5d7d58ebb087d25cdb83fc9201a2f1ebaeca7063dd39eb26acae4194fbc3f002ba5dc1ad7e8f868160becda6e3943a8840bc28c4d8f0db2c
7
+ data.tar.gz: a600eb085335aaca7cf4bcc5a338b76b5c84e64671cb473ade2e5c00dfdc249dab7a4a34df72cd727c8c3abebe7332f74001fe8a3941b0fc8b0365186b5b9255
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'
data/Gemfile.lock CHANGED
@@ -1,21 +1,34 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- krb (0.0.15)
4
+ krb (0.1.0)
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::Base.process
11
+ elsif entrypoint == 'download'
12
+ Krb::Download::Base.process
13
+ else
14
+ puts 'Please specify a command.'
15
+ end
data/http_server.rb ADDED
@@ -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,62 @@ 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
+ protected
34
+
35
+ def setup
36
+ @setup ||= begin
37
+ if File.exist?(setup_file_path)
38
+ YAML.load_file(setup_file_path)
39
+ else
40
+ {}
41
+ end
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def key?
48
+ config ? config.storefront_token.present? : false
49
+ end
50
+
51
+ def config_file_path
52
+ [Dir.pwd, '.krb'].join('/')
53
+ end
54
+
55
+ def config_file?
56
+ File.exist?(config_file_path)
57
+ end
58
+
59
+ def config
60
+ return unless config_file?
61
+ YAML.load_file(config_file_path)
62
+ end
10
63
  end
11
64
  end
12
65
 
13
66
  Dir[File.dirname(__FILE__) + '/**/*.rb'].each do |file|
14
67
  require file
15
- end
68
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Krb
4
+ module Download
5
+ # Download methods
6
+ class Base < ApplicationService
7
+ def initialize
8
+ super
9
+ verify_setup
10
+ end
11
+
12
+ def process
13
+ 'ok download'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Krb
4
+ module Import
5
+ # Import methods
6
+ class Base < ApplicationService
7
+ def initialize
8
+ super
9
+ verify_setup
10
+ end
11
+
12
+ def process
13
+ 'ok import'
14
+ end
15
+ end
16
+ end
17
+ 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,34 @@
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 wrap_up
19
+ File.open(setup_file_path, 'w+') { |f| f.write(setup.to_yaml) }
20
+ Krb::Setup::GitIgnore.process
21
+ end
22
+
23
+ def shopify_prompts
24
+ setup['shop_name'] = Krb::Setup::AskShopifyShopName.process
25
+ setup['access_key'] = Krb::Setup::AskShopifyAccessKey.process(setup)
26
+ end
27
+
28
+ def language_prompt
29
+ input = prompt.select('Select your library :', %w[php rails node])
30
+ setup['language'] = input
31
+ end
32
+ end
33
+ end
34
+ 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
data/lib/krb/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Krb
4
- VERSION = '0.0.15'.freeze
4
+ VERSION = '0.1.0'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: krb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bbnnt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-26 00:00:00.000000000 Z
11
+ date: 2018-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -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/base.rb
80
+ - lib/krb/import/base.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
data/lib/krb/php/base.rb DELETED
@@ -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
data/lib/krb/ruby/base.rb DELETED
@@ -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