bootic_cli 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f2a3c068eab8692e48632559045c3df977266d3
4
+ data.tar.gz: 26ebde53b193412f58110f95bfd72e2cec736ace
5
+ SHA512:
6
+ metadata.gz: 3f0ad5def58d8eaabdf3535aaf0cacc17d70fa401d45c39f280edc0f798737bcea68220bc51ba4e7229c684d0b3c5cfdbe9bb2e90101c273469e0ed93d273035
7
+ data.tar.gz: ad5d228ff4e5b31eeb8696baef6744cf206919100f8582a0f7f04cf0285376415739f0ccefa42e885a137600dacabc0ce0865a8365d09fa246d5dd602db52bb4
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in btc.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ismael Celis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Bootic CLI
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/btc`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Install in your system.
10
+
11
+ ```
12
+ gem install bootic_cli
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```
18
+ btc help
19
+ btc login
20
+ btc console
21
+ ```
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec btc` to use the code located in this directory, ignoring other installed copies of this gem.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/[my-github-username]/btc/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bootic_cli"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bootic_cli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bootic_cli"
8
+ spec.version = BooticCli::VERSION
9
+ spec.authors = ["Ismael Celis"]
10
+ spec.email = ["ismaelct@gmail.com"]
11
+
12
+ spec.summary = %q{Bootic command line.}
13
+ spec.description = %q{Bootic command line.}
14
+ spec.homepage = "http://www.bootic.net"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'thor'
23
+ spec.add_dependency 'bootic_client', "~> 0.0.15"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.9"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec"
28
+
29
+ spec.post_install_message = <<-END
30
+ Bootic client installed.
31
+ Try running:
32
+ btc help
33
+ END
34
+
35
+ end
data/exe/btc ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bootic_cli/cli"
4
+
5
+ BooticCli::CLI.start
@@ -0,0 +1,81 @@
1
+ module BooticCli
2
+ module Commands
3
+ class Orders < BooticCli::Command
4
+ class OrdersTable
5
+ def self.call(orders)
6
+ new(orders).data
7
+ end
8
+
9
+ def initialize(orders)
10
+ @orders = orders
11
+ end
12
+
13
+ def data
14
+ data = [['status', 'updated', 'created', 'code', 'total', 'discount', 'payment', 'client']]
15
+ data += orders.map do |order|
16
+ [order.status, order.updated_on, order.created_on, order.code, order.total, discount_line(order), payment_line(order), order_contact_name(order)]
17
+ end
18
+ data
19
+ end
20
+
21
+ private
22
+ attr_reader :orders
23
+
24
+ def order_contact_name(order)
25
+ return '' unless order.has?(:contact)
26
+ "#{order.contact.name} <#{order.contact.email}>"
27
+ end
28
+
29
+ def discount_line(order)
30
+ order.discount_total > 0 ? "#{order.discount_total} (#{order.discount_name})" : ''
31
+ end
32
+
33
+ def payment_line(order)
34
+ order.has?(:payment_info) ? order.payment_info.name : ''
35
+ end
36
+ end
37
+
38
+ MAPPERS = {
39
+ 'table' => OrdersTable,
40
+ 'csv' => OrdersTable,
41
+ 'json' => ->(orders) { orders.to_hash }
42
+ }
43
+
44
+ desc 'list', 'List shop orders'
45
+ option :s, banner: "<status>"
46
+ option :o, banner: "<output_format>", default: 'table'
47
+ option :a, type: :boolean, desc: "Get full data set", default: false
48
+ option :q, banner: "<query>"
49
+ option :so, banner: "<sort>"
50
+ option :ugte, banner: "<updated_after>", desc: "Updated after, ie. 2015-10-01"
51
+ option :ulte, banner: "<updated_before>", desc: "Updated before, ie. 2015-10-01"
52
+ option :dgte, banner: "<discount_greater_than>", desc: "Discount greater than, ie. 10000"
53
+ option :dlte, banner: "<discount_less_than>", desc: "Discount less than, ie. 20000"
54
+ option :tgte, banner: "<total_greater_than>", desc: "Total greather than, ie. 23000"
55
+ option :tlte, banner: "<total_less_than>", desc: "Total less than, ie. 23000"
56
+ option :c, banner: "<code>"
57
+
58
+ def list
59
+ logged_in_action do
60
+ opts = {}
61
+ opts[:status] = options['s'] if options['s']
62
+ opts[:q] = options['q'] if options['q']
63
+ opts[:sort] = options['so'] if options['so']
64
+ opts[:updated_on_gte] = options['ugte'] if options['ugte']
65
+ opts[:updated_on_lte] = options['ulte'] if options['ugte']
66
+ opts[:total_gte] = options['tgte'] if options['tgte']
67
+ opts[:total_lte] = options['tlte'] if options['tlte']
68
+ opts[:discount_total_gte] = options['dgte'] if options['dgte']
69
+ opts[:discount_total_lte] = options['dlte'] if options['dlte']
70
+ opts[:code] = options['c'] if options['c']
71
+
72
+ orders = shop.orders(opts)
73
+ orders = orders.full_set if options[:a]
74
+ puts Formatters.format(options['o'], MAPPERS[options['o']].call(orders))
75
+ end
76
+ end
77
+
78
+ declare self, "manage orders"
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,134 @@
1
+ require 'thor'
2
+ require 'bootic_cli/connectivity'
3
+ require 'bootic_cli/formatters'
4
+
5
+ module BooticCli
6
+ class CLI < Thor
7
+ include Thor::Actions
8
+ include BooticCli::Connectivity
9
+
10
+ CUSTOM_COMMANDS_DIR = ENV.fetch("BTC_CUSTOM_COMMANDS_PATH") { File.join(ENV["HOME"], "btc") }
11
+
12
+ desc 'setup', 'Setup OAuth2 application credentials'
13
+ def setup
14
+ client_id = ask("Enter your application's client_id:")
15
+ client_secret = ask("Enter your application's client_secret:")
16
+
17
+ session.setup(client_id, client_secret)
18
+
19
+ say "Credentials stored. client_id: #{client_id}"
20
+ end
21
+
22
+ desc 'login', 'Login to your Bootic account'
23
+ def login(scope = 'admin')
24
+ if !session.setup?
25
+ say "App not configured. Running setup first. You only need to do this once."
26
+ say "Please create an OAuth2 app and get its credentials at https://auth.bootic.net/dev/apps"
27
+ invoke :setup, []
28
+ end
29
+
30
+ username = ask("Enter your Bootic user name:")
31
+ pwd = ask("Enter your Bootic password:", echo: false)
32
+
33
+ say "Loging in as #{username}. Getting access token..."
34
+
35
+ begin
36
+ session.login username, pwd, scope
37
+ say "Logged in as #{username} (#{scope})"
38
+ say "try: btc help"
39
+ rescue StandardError => e
40
+ say e.message
41
+ end
42
+ end
43
+
44
+ desc 'logout', 'Log out (delete access token)'
45
+ def logout
46
+ session.logout!
47
+ say_status 'Logged out', 'You are now logged out', :red
48
+ end
49
+
50
+ desc "erase", "clear all credentials from this computer"
51
+ def erase
52
+ session.erase!
53
+ say "all credentials erased from this computer"
54
+ end
55
+
56
+ desc 'info', 'Test API connectivity'
57
+ def info
58
+ logged_in_action do
59
+ print_table([
60
+ ['username', root.user_name],
61
+ ['email', root.email],
62
+ ['scopes', root.scopes],
63
+ ['shop', "#{shop.url} (#{shop.subdomain})"],
64
+ ['custom commands dir', CUSTOM_COMMANDS_DIR]
65
+ ])
66
+
67
+ say_status 'OK', 'API connection is working', :green
68
+ end
69
+ end
70
+
71
+ desc 'runner', 'Run an arbitrary ruby script with a client session'
72
+ def runner(filename)
73
+ require 'bootic_cli/file_runner'
74
+
75
+ logged_in_action do
76
+ FileRunner.run(root, filename)
77
+ end
78
+ end
79
+
80
+ desc 'console', 'Log into interactive console'
81
+ def console
82
+ logged_in_action do
83
+ require 'irb'
84
+ require 'irb/completion'
85
+ IRB.setup nil
86
+ IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
87
+ require 'irb/ext/multi-irb'
88
+ require 'bootic_cli/console'
89
+ context = Console.new(root)
90
+ prompt = "/#{shop.subdomain} (#{root.user_name}|#{root.scopes}) $ "
91
+
92
+ IRB.conf[:PROMPT][:CUSTOM] = {
93
+ :PROMPT_I => prompt,
94
+ :PROMPT_S => "%l>> ",
95
+ :PROMPT_C => prompt,
96
+ :PROMPT_N => prompt,
97
+ :RETURN => "=> %s\n"
98
+ }
99
+ IRB.conf[:PROMPT_MODE] = :CUSTOM
100
+ IRB.conf[:AUTO_INDENT] = false
101
+
102
+ IRB.irb nil, context
103
+ end
104
+ end
105
+
106
+ def self.sub(klass, descr)
107
+ command_name = underscore(klass.name)
108
+ register klass, command_name, "#{command_name} SUBCOMMAND ...ARGS", descr
109
+ end
110
+
111
+ private
112
+
113
+ def self.underscore(str)
114
+ str.gsub(/::/, '/').
115
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
116
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
117
+ tr("-", "_").
118
+ downcase.split("/").last
119
+ end
120
+
121
+ require "bootic_cli/command"
122
+
123
+ Dir[File.join(File.dirname(__FILE__), 'cli', '*.rb')].each do |f|
124
+ require f
125
+ end
126
+
127
+ if File.directory?(CUSTOM_COMMANDS_DIR)
128
+ Dir[File.join(CUSTOM_COMMANDS_DIR, '*.rb')].each do |f|
129
+ require f
130
+ end
131
+ end
132
+ end
133
+ end
134
+
@@ -0,0 +1,14 @@
1
+ require 'thor'
2
+ require 'bootic_cli/connectivity'
3
+
4
+ module BooticCli
5
+ class Command < Thor
6
+ include Thor::Actions
7
+ include BooticCli::Connectivity
8
+
9
+ def self.declare(klass, descr)
10
+ BooticCli::CLI.sub klass, descr
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,42 @@
1
+ require 'bootic_cli/store'
2
+ require 'bootic_cli/session'
3
+
4
+ module BooticCli
5
+ module Connectivity
6
+
7
+ private
8
+
9
+ def session
10
+ @session ||= (
11
+ store = BooticCli::Store.new(ENV['HOME'])
12
+ BooticCli::Session.new(store)
13
+ )
14
+ end
15
+
16
+ def root
17
+ @root ||= session.client.root
18
+ end
19
+
20
+ def shop
21
+ root.shops.first
22
+ end
23
+
24
+ def logged_in_action(&block)
25
+ if !session.setup?
26
+ say_status "ERROR", "No app credentials. Run btc setup", :red
27
+ return
28
+ end
29
+
30
+ if !session.logged_in?
31
+ say_status "ERROR", "No access token. Run btc login", :red
32
+ return
33
+ end
34
+
35
+ yield
36
+
37
+ rescue StandardError => e
38
+ say_status "ERROR", e.message, :red
39
+ nil
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,108 @@
1
+ module BooticCli
2
+ class Console
3
+ include BooticCli::Connectivity
4
+
5
+ SEPCOUNT = 80.freeze
6
+
7
+ def initialize(r = root)
8
+ @root = r
9
+ end
10
+
11
+ def explain(entity, include_links = true)
12
+ if entity.is_a?(String) || entity.is_a?(Integer)
13
+ puts entity
14
+ return
15
+ end
16
+
17
+ if entity.is_a?(Array)
18
+ entity.each{|e| explain(e) }
19
+ return
20
+ end
21
+
22
+ title 'PROPERTIES:'
23
+ puts table(entity.properties)
24
+
25
+ puts ''
26
+
27
+ if include_links
28
+ title 'LINKS (explain_link <ENTITY>, <LINK_NAME>):'
29
+ puts links(entity.rels)
30
+
31
+ puts ''
32
+ end
33
+
34
+ title 'ENTITIES (explain <SUBENTITY>):'
35
+ puts entity.entities.keys.join("\r\n")
36
+
37
+ puts '-' * SEPCOUNT
38
+ puts ''
39
+ nil
40
+ end
41
+
42
+ def explain_link(entity, key)
43
+ return "This entity does not appear to have links" unless entity.respond_to?(:rels)
44
+ rel = entity.rels[key.to_sym]
45
+ return "This entity does not have link '#{key}'" unless rel
46
+
47
+ data = [
48
+ ['name', key],
49
+ ['type', rel.type],
50
+ ['title', rel.title],
51
+ ['method', rel.transport_method],
52
+ ['docs', rel.docs],
53
+ ['href', rel.href],
54
+ ['parameters', rel.parameters.join(', ')]
55
+ ]
56
+
57
+ puts table(data)
58
+ puts ''
59
+ token = session.config[:access_token]
60
+ puts %(curl -i -H "Authorization: Bearer #{token}" "#{rel.href}")
61
+
62
+ nil
63
+ end
64
+
65
+ def list(entities)
66
+ if entities.respond_to?(:each)
67
+ entities.each{|e| explain(e, false)}
68
+ puts ''
69
+ if entities.respond_to?(:total_items)
70
+ puts "Page #{entities.page} of #{(entities.total_items / entities.per_page) + 1}. Total items #{entities.total_items}"
71
+ end
72
+ if entities.respond_to?(:next)
73
+ @last_in_list = entities
74
+ puts "There is more. run 'more'"
75
+ else
76
+ @last_in_list = nil
77
+ puts "End of list"
78
+ end
79
+ else
80
+ explain entities
81
+ end
82
+
83
+ nil
84
+ end
85
+
86
+ def more
87
+ puts "End of list" unless @last_in_list
88
+ list @last_in_list.next
89
+ end
90
+
91
+ private
92
+
93
+ def table(hash)
94
+ hash.map{|k,v| [k.to_s.ljust(20), v].join}.join("\r\n")
95
+ end
96
+
97
+ def title(str)
98
+ puts "### #{str}\r\n"
99
+ nil
100
+ end
101
+
102
+ def links(rels)
103
+ table = rels.map do |key, relation|
104
+ [key.to_s.ljust(25), relation.title.to_s.ljust(50)].join
105
+ end.join("\r\n")
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,25 @@
1
+ module BooticCli
2
+ class FileRunner
3
+ include BooticCli::Connectivity
4
+
5
+ def self.run(root, file_name)
6
+ new(root, file_name).run
7
+ end
8
+
9
+ def initialize(root, file_name)
10
+ @root = root
11
+ @file_name = file_name
12
+ end
13
+
14
+ def run
15
+ self.instance_eval File.read(@file_name), @file_name
16
+ end
17
+
18
+ # #root is already defined in Connectivity
19
+ # but we want to pass a pre-initialized root
20
+ # to avoid having to re-fetch root from API
21
+ def root
22
+ @root
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,65 @@
1
+ require 'json'
2
+ require 'csv'
3
+
4
+ module BooticCli
5
+ module Formatters
6
+
7
+ class Table
8
+ CELL_PADDING = 5.freeze
9
+
10
+ def format(array_of_arrays, headings = true)
11
+ array_of_arrays = array_of_arrays.dup
12
+
13
+ # [122, 23, 45, 66]
14
+ cell_sizes = array_of_arrays.each.with_object([]) do |row, memo|
15
+ row.each.with_index do |cell, idx|
16
+ if !memo[idx] || memo[idx] < cell.size
17
+ memo[idx] = cell.size
18
+ end
19
+ end
20
+ end
21
+
22
+ data = array_of_arrays.map do |row|
23
+ row.map.with_index{|e, idx|
24
+ e.to_s.ljust(cell_sizes[idx] + CELL_PADDING)
25
+ }.join(' | ')
26
+ end
27
+
28
+ if headings
29
+ sep = cell_sizes.map{|i| '-' * (i + CELL_PADDING)}.join('-|-')
30
+ data.insert(1, sep)
31
+ end
32
+
33
+ data.join("\r\n")
34
+
35
+ end
36
+
37
+ end
38
+
39
+ class Json
40
+ def format(data)
41
+ JSON.dump data
42
+ end
43
+ end
44
+
45
+ class Csv
46
+ def format(data)
47
+ CSV.generate do |csv|
48
+ data.each do |row|
49
+ csv << row
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ FMTS = {
56
+ table: Table,
57
+ json: Json,
58
+ csv: Csv
59
+ }
60
+
61
+ def self.format(k, data)
62
+ FMTS[k.to_sym].new.format(data)
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,90 @@
1
+ require 'oauth2'
2
+ require 'bootic_client'
3
+
4
+ module BooticCli
5
+
6
+ class Session
7
+ def initialize(store)
8
+ @store = store
9
+ end
10
+
11
+ def setup?
12
+ store.transaction do
13
+ store['client_id'] && store['client_secret']
14
+ end
15
+ end
16
+
17
+ def logged_in?
18
+ store.transaction{ store['access_token'] }
19
+ end
20
+
21
+ def ready?
22
+ setup? && logged_in?
23
+ end
24
+
25
+ def setup(client_id, client_secret)
26
+ store.transaction do
27
+ store['client_id'] = client_id
28
+ store['client_secret'] = client_secret
29
+ end
30
+ end
31
+
32
+ def login(username, pwd, scope)
33
+ token = oauth_client.password.get_token(username, pwd, 'scope' => scope)
34
+
35
+ store.transaction do
36
+ store['access_token'] = token.token
37
+ end
38
+ end
39
+
40
+ def erase!
41
+ store.erase
42
+ end
43
+
44
+ def logout!
45
+ store.transaction do
46
+ store['access_token'] = nil
47
+ end
48
+ end
49
+
50
+ def config
51
+ @config ||= store.transaction do
52
+ {
53
+ client_id: store['client_id'],
54
+ client_secret: store['client_secret'],
55
+ access_token: store['access_token']
56
+ }
57
+ end
58
+ end
59
+
60
+ def client
61
+ @client ||= begin
62
+ raise "First setup credentials and log in" unless ready?
63
+ BooticClient.configure do |c|
64
+ c.client_id = config[:client_id]
65
+ c.client_secret = config[:client_secret]
66
+ c.logger = Logger.new(STDOUT)
67
+ c.logging = false
68
+ end
69
+
70
+ BooticClient.client(:authorized, access_token: config[:access_token]) do |new_token|
71
+ store.transaction{ store['access_token'] = new_token }
72
+ end
73
+ end
74
+ end
75
+
76
+ private
77
+
78
+ attr_reader :store
79
+
80
+ def oauth_client
81
+ @oauth_client ||= OAuth2::Client.new(
82
+ config[:client_id],
83
+ config[:client_secret],
84
+ site: BooticClient.auth_host
85
+ )
86
+ end
87
+
88
+ end
89
+
90
+ end
@@ -0,0 +1,41 @@
1
+ require 'fileutils'
2
+ require 'pstore'
3
+
4
+ module BooticCli
5
+
6
+ class Store
7
+
8
+ DIRNAME = '.btc'.freeze
9
+ FILE_NAME = 'store.pstore'.freeze
10
+
11
+ def initialize(base_dir = ENV['HOME'], dir = DIRNAME)
12
+ @base_dir = File.join(base_dir, dir)
13
+ FileUtils.mkdir_p @base_dir
14
+ end
15
+
16
+ def []=(k, v)
17
+ store[k] = v
18
+ end
19
+
20
+ def [](k)
21
+ store[k]
22
+ end
23
+
24
+ def transaction(&block)
25
+ store.transaction(&block)
26
+ end
27
+
28
+ def erase
29
+ FileUtils.rm_rf base_dir
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :base_dir
35
+
36
+ def store
37
+ @store ||= PStore.new(File.join(base_dir, FILE_NAME))
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,3 @@
1
+ module BooticCli
2
+ VERSION = "0.1.0"
3
+ end
data/lib/bootic_cli.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "bootic_cli/version"
2
+
3
+ module BooticCli
4
+ # Your code goes here...
5
+ end
6
+
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bootic_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ismael Celis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bootic_client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.15
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.15
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Bootic command line.
84
+ email:
85
+ - ismaelct@gmail.com
86
+ executables:
87
+ - btc
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - bootic_cli.gemspec
101
+ - exe/btc
102
+ - lib/bootic_cli.rb
103
+ - lib/bootic_cli/cli.rb
104
+ - lib/bootic_cli/cli/orders.rb
105
+ - lib/bootic_cli/command.rb
106
+ - lib/bootic_cli/connectivity.rb
107
+ - lib/bootic_cli/console.rb
108
+ - lib/bootic_cli/file_runner.rb
109
+ - lib/bootic_cli/formatters.rb
110
+ - lib/bootic_cli/session.rb
111
+ - lib/bootic_cli/store.rb
112
+ - lib/bootic_cli/version.rb
113
+ homepage: http://www.bootic.net
114
+ licenses:
115
+ - MIT
116
+ metadata: {}
117
+ post_install_message: |
118
+ Bootic client installed.
119
+ Try running:
120
+ btc help
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.4.5
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Bootic command line.
140
+ test_files: []