brainshell 0.1.0 → 0.2.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 +4 -4
- data/.gitignore +1 -0
- data/README.md +39 -17
- data/lib/brainshell/commands/base.rb +26 -2
- data/lib/brainshell/commands/subscription.rb +13 -3
- data/lib/brainshell/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcd4cf8b64a93c6963518f47c700abca59f8a896
|
4
|
+
data.tar.gz: d08890fa82ad601da1507d2dfd6036d1eba1691c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2f0b3eb9b149c2295deeb8141e6aced802d07f101c502355963f114891e22a1bb2aaf26cbcc48b9e9a3a1d39b6a3fef451e22cb88e9a2a6a0b196db81b4ab72
|
7
|
+
data.tar.gz: 1e3758696bd4d1179d216018b89d0757c70c496ef3a8f304012e47e8783e60c222a41270719168786f40446b47715368153be29935490f1c8791e026b50fe6a9
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,36 +1,58 @@
|
|
1
1
|
# Brainshell
|
2
2
|
|
3
|
-
|
3
|
+
Brainshell is a console interface to your Braintree account. To get started, simply install the gem and set
|
4
|
+
the following environment variables:
|
4
5
|
|
5
|
-
|
6
|
+
export BRAINTREE_ENVIRONMENT=can be production or staging
|
7
|
+
export BRAINTREE_MERCHANT_ID=your Braintree merchant id
|
8
|
+
export BRAINTREE_PUBLIC_KEY=your Braintree public key
|
9
|
+
export BRAINTREE_PRIVATE_KEY=your Braintree private key
|
6
10
|
|
7
11
|
## Installation
|
8
12
|
|
9
|
-
|
13
|
+
You can install it by running:
|
10
14
|
|
11
|
-
|
12
|
-
gem 'brainshell'
|
13
|
-
```
|
15
|
+
$ gem install brainshell
|
14
16
|
|
15
|
-
|
17
|
+
## Usage
|
16
18
|
|
17
|
-
|
19
|
+
For detailed description, run `brainshell help` and `brainshell command help`
|
18
20
|
|
19
|
-
|
21
|
+
Brainshell commands usually contain sub-command name, one or more filter options, and optional array of columns to
|
22
|
+
be rendered. By default, brainshell will print only IDs of matching objects.
|
20
23
|
|
21
|
-
|
24
|
+
For example, to find active and pending
|
25
|
+
subscriptions with price in range between 100.0 and 200.0 you can use the following command:
|
22
26
|
|
23
|
-
|
27
|
+
brainshell subscription query --price=10..300 --status=Active Pending --columns=id price status created_at
|
28
|
+
|
29
|
+
This command will print the result like this:
|
30
|
+
|
31
|
+
d6nbxr 300.0 Active 2016-06-26 10:24:55 UTC
|
32
|
+
2dh32m 30.0 Active 2016-05-02 14:39:01 UTC
|
33
|
+
|
34
|
+
##Options values
|
35
|
+
|
36
|
+
There are three types of values that you can specify for options:
|
37
|
+
|
38
|
+
1. Text value
|
39
|
+
2. Range value
|
40
|
+
2. Multiple value
|
24
41
|
|
25
|
-
|
42
|
+
To see which columns support which types of values, please refer to Braintree documentation.
|
43
|
+
Text values can be passed as simple string arguments. If value contains space, it should be enclosed in double quotes:
|
26
44
|
|
27
|
-
|
45
|
+
--status=Active
|
46
|
+
--status="Past Due"
|
28
47
|
|
29
|
-
|
48
|
+
Range values can have values of _equal_, _greater than_, _less than_, and _in range_ (inclusive):
|
30
49
|
|
31
|
-
|
50
|
+
--price=100.0
|
51
|
+
--price=gt100.0
|
52
|
+
--price=lt200.0
|
53
|
+
--price=100..200
|
32
54
|
|
33
|
-
|
55
|
+
Multiple values are passed separated by whitespace:
|
34
56
|
|
35
|
-
|
57
|
+
--status=Active Pending
|
36
58
|
|
@@ -4,10 +4,34 @@ module Brainshell
|
|
4
4
|
|
5
5
|
include ValueFormatter
|
6
6
|
|
7
|
-
class_option :columns, type: :array
|
7
|
+
class_option :columns, type: :array
|
8
8
|
|
9
9
|
protected
|
10
10
|
|
11
|
+
def assign_range_criteria(search, field)
|
12
|
+
if criteria = options[field]
|
13
|
+
if criteria.match(/([\d.]+)\.\.([\d.]+)/)
|
14
|
+
search.send(field).between $1, $2
|
15
|
+
elsif criteria.match(/\Agt([\d.]+)/)
|
16
|
+
search.send(field) >= $1
|
17
|
+
elsif criteria.match(/\Alt([\d.]+)/)
|
18
|
+
search.send(field) <= $1
|
19
|
+
elsif criteria.match(/([\d.]+)/)
|
20
|
+
search.send(field).is $1
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def assign_multiple_value_criteria(search, field)
|
26
|
+
if criteria = options[field]
|
27
|
+
if criteria.size == 1
|
28
|
+
search.send(field).is criteria
|
29
|
+
else
|
30
|
+
search.send(field).in criteria
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
11
35
|
def build_table(objects)
|
12
36
|
rows = []
|
13
37
|
objects.each do |object|
|
@@ -17,7 +41,7 @@ module Brainshell
|
|
17
41
|
end
|
18
42
|
|
19
43
|
def render_row(object)
|
20
|
-
columns =
|
44
|
+
columns = options[:columns] ? options[:columns] : default_columns
|
21
45
|
columns.map { |column| get_column_value(object, column) }
|
22
46
|
end
|
23
47
|
|
@@ -9,10 +9,20 @@ module Brainshell
|
|
9
9
|
build_table([subscription])
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
method_option :ids, type: :array
|
13
|
+
method_option :plan_id, type: :array, aliases: '-pi'
|
14
|
+
method_option :status, type: :array
|
15
|
+
method_option :price
|
16
|
+
method_option :billing_cycles_remaining, aliases: '-bcr'
|
17
|
+
method_option :days_past_due, aliases: '-dpd'
|
18
|
+
desc 'query OPTIONS', 'Find subscriptions matching criteria specified in options'
|
19
|
+
def query
|
14
20
|
search_results = Braintree::Subscription.search do |search|
|
15
|
-
search
|
21
|
+
assign_multiple_value_criteria(search, :ids)
|
22
|
+
assign_multiple_value_criteria(search, :plan_id)
|
23
|
+
assign_multiple_value_criteria(search, :status)
|
24
|
+
|
25
|
+
assign_range_criteria(search, :price)
|
16
26
|
end
|
17
27
|
|
18
28
|
build_table(search_results.to_a)
|
data/lib/brainshell/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brainshell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- koss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|