brainshell 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ad334b11646d8031486b8095eacda21ae0fb3814
4
+ data.tar.gz: d6f44d782357e6914378a96acd0ebafe874c398b
5
+ SHA512:
6
+ metadata.gz: 29d49251f146af54aebe65aaa7d168018722c37eeac598be4516e6ab092273cc444bdd833c0ef7aeafed9bc4d1dd936ad7ea109ed9a3570859bba7dc251a1d5d
7
+ data.tar.gz: 90e66cbdb593f257a3422ce6062b61893b431c477d28953a1bbc0d7996734fff5ae1968f0beab754f0bb856b0b40428afb7b3522788a176c8bfa5a7ff954b6f7
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea/
11
+ runner.sh
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in brainshell.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Brainshell
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/brainshell`. 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
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'brainshell'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install brainshell
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/brainshell.
36
+
data/bin/brainshell ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'brainshell'
4
+
5
+ Braintree::Configuration.logger = Logger.new("/dev/null")
6
+ Braintree::Configuration.environment = ENV['BRAINTREE_ENVIRONMENT'].to_sym
7
+ Braintree::Configuration.merchant_id = ENV['BRAINTREE_MERCHANT_ID']
8
+ Braintree::Configuration.public_key = ENV['BRAINTREE_PUBLIC_KEY']
9
+ Braintree::Configuration.private_key = ENV['BRAINTREE_PRIVATE_KEY']
10
+
11
+ Brainshell::Main.start ARGV
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'brainshell/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'brainshell'
9
+ spec.version = Brainshell::VERSION
10
+ spec.authors = ['koss']
11
+ spec.email = ['koss.lebedev@gmail.com']
12
+
13
+ spec.summary = %q{Console client for accessing Braintree payment gateway}
14
+ spec.description = %q{Console client for accessing Braintree payment gateway}
15
+ spec.homepage = 'https://github.com/koss-lebedev/brainshell'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'bin'
19
+ spec.executables = ['brainshell']
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'thor', '~> 0.19.1'
23
+ spec.add_dependency 'braintree', '2.60.0'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.12'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ end
@@ -0,0 +1,37 @@
1
+ module Brainshell
2
+ module Commands
3
+ class Base < Thor
4
+
5
+ include ValueFormatter
6
+
7
+ class_option :columns, type: :array, default: []
8
+
9
+ protected
10
+
11
+ def build_table(objects)
12
+ rows = []
13
+ objects.each do |object|
14
+ rows << render_row(object)
15
+ end
16
+ shell.print_table(rows)
17
+ end
18
+
19
+ def render_row(object)
20
+ columns = default_columns + options[:columns]
21
+ columns.map { |column| get_column_value(object, column) }
22
+ end
23
+
24
+ def default_columns
25
+ [ :id ]
26
+ end
27
+
28
+ def get_column_value(object, column)
29
+ value = object.send(column)
30
+ format_value(value)
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+
37
+
@@ -0,0 +1,14 @@
1
+ module Brainshell
2
+ module Commands
3
+ class Customer < Base
4
+
5
+ desc 'find ID', 'Get customer by identifier'
6
+ def find(id)
7
+ customer = Braintree::Customer.find(id)
8
+
9
+ build_table([customer])
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ module Brainshell
2
+ module Commands
3
+ class Subscription < Base
4
+
5
+ desc 'find ID', 'Get subscription by identifier'
6
+ def find(id)
7
+ subscription = Braintree::Subscription.find(id)
8
+
9
+ build_table([subscription])
10
+ end
11
+
12
+ desc "in_status [#{Braintree::Subscription::Status::All.join(', ')}]", 'Get subscriptions in specified status'
13
+ def in_status(status)
14
+ search_results = Braintree::Subscription.search do |search|
15
+ search.status.is status
16
+ end
17
+
18
+ build_table(search_results.to_a)
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ module Brainshell
2
+ module Commands
3
+ class Transaction < Base
4
+
5
+ desc 'find TOKEN', 'Get transaction by identifier'
6
+ def find(token)
7
+ transaction = Braintree::Transaction.find(token)
8
+
9
+ build_table([transaction])
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ module Brainshell
2
+ module ValueFormatter
3
+
4
+ KNOWN_FORMAT_METHODS = {
5
+ BigDecimal => :big_decimal,
6
+ DateTime => :date_time
7
+ }.freeze
8
+
9
+ def format_value(value)
10
+ format_method = KNOWN_FORMAT_METHODS[value.class]
11
+ format_method ? send(format_method, value) : value
12
+ end
13
+
14
+ protected
15
+
16
+ def big_decimal(value)
17
+ value.to_f
18
+ end
19
+
20
+ def date_time(value)
21
+ value.iso8601
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Brainshell
2
+ VERSION = '0.1.0'
3
+ end
data/lib/brainshell.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'thor'
2
+ require 'braintree'
3
+
4
+ require 'brainshell/version'
5
+ require 'brainshell/value_formatter'
6
+ require 'brainshell/commands/base'
7
+ require 'brainshell/commands/customer'
8
+ require 'brainshell/commands/subscription'
9
+ require 'brainshell/commands/transaction'
10
+
11
+ module Brainshell
12
+
13
+ class Main < Thor
14
+
15
+ desc 'customer OPTIONS', 'Query Braintree customers'
16
+ subcommand 'customer', Commands::Customer
17
+
18
+ desc 'subscription OPTIONS', 'Query Braintree subscriptions'
19
+ subcommand 'subscription', Commands::Subscription
20
+
21
+ desc 'transaction OPTIONS', 'Query Braintree transactions'
22
+ subcommand 'transaction', Commands::Transaction
23
+
24
+ end
25
+
26
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brainshell
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - koss
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-09 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.19.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: braintree
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.60.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.60.0
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.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
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
+ description: Console client for accessing Braintree payment gateway
70
+ email:
71
+ - koss.lebedev@gmail.com
72
+ executables:
73
+ - brainshell
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - README.md
80
+ - bin/brainshell
81
+ - brainshell.gemspec
82
+ - lib/brainshell.rb
83
+ - lib/brainshell/commands/base.rb
84
+ - lib/brainshell/commands/customer.rb
85
+ - lib/brainshell/commands/subscription.rb
86
+ - lib/brainshell/commands/transaction.rb
87
+ - lib/brainshell/value_formatter.rb
88
+ - lib/brainshell/version.rb
89
+ homepage: https://github.com/koss-lebedev/brainshell
90
+ licenses: []
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.8
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Console client for accessing Braintree payment gateway
112
+ test_files: []