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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad334b11646d8031486b8095eacda21ae0fb3814
4
- data.tar.gz: d6f44d782357e6914378a96acd0ebafe874c398b
3
+ metadata.gz: bcd4cf8b64a93c6963518f47c700abca59f8a896
4
+ data.tar.gz: d08890fa82ad601da1507d2dfd6036d1eba1691c
5
5
  SHA512:
6
- metadata.gz: 29d49251f146af54aebe65aaa7d168018722c37eeac598be4516e6ab092273cc444bdd833c0ef7aeafed9bc4d1dd936ad7ea109ed9a3570859bba7dc251a1d5d
7
- data.tar.gz: 90e66cbdb593f257a3422ce6062b61893b431c477d28953a1bbc0d7996734fff5ae1968f0beab754f0bb856b0b40428afb7b3522788a176c8bfa5a7ff954b6f7
6
+ metadata.gz: f2f0b3eb9b149c2295deeb8141e6aced802d07f101c502355963f114891e22a1bb2aaf26cbcc48b9e9a3a1d39b6a3fef451e22cb88e9a2a6a0b196db81b4ab72
7
+ data.tar.gz: 1e3758696bd4d1179d216018b89d0757c70c496ef3a8f304012e47e8783e60c222a41270719168786f40446b47715368153be29935490f1c8791e026b50fe6a9
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
  .idea/
11
11
  runner.sh
12
+ *.gem
data/README.md CHANGED
@@ -1,36 +1,58 @@
1
1
  # Brainshell
2
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.
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
- TODO: Delete this and the text above, and describe your gem
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
- Add this line to your application's Gemfile:
13
+ You can install it by running:
10
14
 
11
- ```ruby
12
- gem 'brainshell'
13
- ```
15
+ $ gem install brainshell
14
16
 
15
- And then execute:
17
+ ## Usage
16
18
 
17
- $ bundle
19
+ For detailed description, run `brainshell help` and `brainshell command help`
18
20
 
19
- Or install it yourself as:
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
- $ gem install brainshell
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
- ## Usage
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
- TODO: Write usage instructions here
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
- ## Development
45
+ --status=Active
46
+ --status="Past Due"
28
47
 
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.
48
+ Range values can have values of _equal_, _greater than_, _less than_, and _in range_ (inclusive):
30
49
 
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).
50
+ --price=100.0
51
+ --price=gt100.0
52
+ --price=lt200.0
53
+ --price=100..200
32
54
 
33
- ## Contributing
55
+ Multiple values are passed separated by whitespace:
34
56
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/brainshell.
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, default: []
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 = default_columns + options[: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
- desc "in_status [#{Braintree::Subscription::Status::All.join(', ')}]", 'Get subscriptions in specified status'
13
- def in_status(status)
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.status.is status
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)
@@ -1,3 +1,3 @@
1
1
  module Brainshell
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
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.1.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-09 00:00:00.000000000 Z
11
+ date: 2016-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor