brainshell 0.2.0 → 0.3.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
  SHA1:
3
- metadata.gz: bcd4cf8b64a93c6963518f47c700abca59f8a896
4
- data.tar.gz: d08890fa82ad601da1507d2dfd6036d1eba1691c
3
+ metadata.gz: e2809d5e93e973a4704de6514e98a229298cde6e
4
+ data.tar.gz: 6f286dac2ffd4e6d34ced575ceaa79b66f827fea
5
5
  SHA512:
6
- metadata.gz: f2f0b3eb9b149c2295deeb8141e6aced802d07f101c502355963f114891e22a1bb2aaf26cbcc48b9e9a3a1d39b6a3fef451e22cb88e9a2a6a0b196db81b4ab72
7
- data.tar.gz: 1e3758696bd4d1179d216018b89d0757c70c496ef3a8f304012e47e8783e60c222a41270719168786f40446b47715368153be29935490f1c8791e026b50fe6a9
6
+ metadata.gz: a6a23a4e709213b81f6703706d0fff88471da23306c0d783eb1107ebaaf8174c2e53fb3757174a9d84b74a5c0d5b62ba56066004ce45e1839e6b35fa6b3f7810
7
+ data.tar.gz: eb7279166f16c4128e232d032e75aca9749e611523ae5ce9e3d1fac99192c8399cd2e735d7c89c71b676905652bd69e523858a8b4785a28b2f09a6a3cd3fb36d
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.12'
26
26
  spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec'
27
28
  end
@@ -7,6 +7,8 @@ require 'brainshell/commands/base'
7
7
  require 'brainshell/commands/customer'
8
8
  require 'brainshell/commands/subscription'
9
9
  require 'brainshell/commands/transaction'
10
+ require 'brainshell/commands/credit_card'
11
+ require 'brainshell/commands/merchant_account'
10
12
 
11
13
  module Brainshell
12
14
 
@@ -21,6 +23,12 @@ module Brainshell
21
23
  desc 'transaction OPTIONS', 'Query Braintree transactions'
22
24
  subcommand 'transaction', Commands::Transaction
23
25
 
26
+ desc 'credit_card OPTIONS', 'Query Braintree credit cards'
27
+ subcommand 'credit_card', Commands::CreditCard
28
+
29
+ desc 'merchant_account OPTIONS', 'Query Braintree merchant accounts'
30
+ subcommand 'merchant_account', Commands::MerchantAccount
31
+
24
32
  end
25
33
 
26
34
  end
@@ -6,7 +6,39 @@ module Brainshell
6
6
 
7
7
  class_option :columns, type: :array
8
8
 
9
- protected
9
+ class << self
10
+
11
+ def define_query_options
12
+ multiple_search_fields.each do |field|
13
+ method_option field, type: :array
14
+ end
15
+ text_search_fields.each do |field|
16
+ method_option field
17
+ end
18
+ range_search_fields.each do |field|
19
+ method_option field
20
+ end
21
+ end
22
+
23
+ def text_search_fields; [] end
24
+ def multiple_search_fields; [] end
25
+ def range_search_fields; [] end
26
+
27
+ end
28
+
29
+ protected
30
+
31
+ def run_query(entity)
32
+ search_results = entity.search do |search|
33
+
34
+ self.class.text_search_fields.each { |field| assign_text_criteria(search, field) }
35
+ self.class.multiple_search_fields.each { |field| assign_multiple_value_criteria(search, field) }
36
+ self.class.range_search_fields.each { |field| assign_range_criteria(search, field) }
37
+
38
+ end
39
+
40
+ build_table(search_results.to_a)
41
+ end
10
42
 
11
43
  def assign_range_criteria(search, field)
12
44
  if criteria = options[field]
@@ -32,16 +64,22 @@ module Brainshell
32
64
  end
33
65
  end
34
66
 
35
- def build_table(objects)
67
+ def assign_text_criteria(search, field)
68
+ if criteria = options[field]
69
+ search.send(field).is criteria
70
+ end
71
+ end
72
+
73
+ def build_table(objects, columns = nil)
36
74
  rows = []
37
75
  objects.each do |object|
38
- rows << render_row(object)
76
+ rows << render_row(object,columns)
39
77
  end
40
78
  shell.print_table(rows)
41
79
  end
42
80
 
43
- def render_row(object)
44
- columns = options[:columns] ? options[:columns] : default_columns
81
+ def render_row(object, columns)
82
+ columns = columns ||(options[:columns] ? options[:columns] : default_columns)
45
83
  columns.map { |column| get_column_value(object, column) }
46
84
  end
47
85
 
@@ -0,0 +1,14 @@
1
+ module Brainshell
2
+ module Commands
3
+ class CreditCard < Base
4
+
5
+ desc 'find ID', 'Get credit card by identifier'
6
+ def find(id)
7
+ credit_card = Braintree::CreditCard.find(id)
8
+ build_table([credit_card])
9
+ end
10
+
11
+ end
12
+ end
13
+ end
14
+
@@ -2,13 +2,37 @@ module Brainshell
2
2
  module Commands
3
3
  class Customer < Base
4
4
 
5
+ class << self
6
+
7
+ def text_search_fields
8
+ %w(address_country_name address_extended_address address_first_name
9
+ address_last_name address_locality address_postal_code address_region address_street_address cardholder_name
10
+ company credit_card_expiration_date credit_card_number email fax first_name id last_name payment_method_token
11
+ payment_method_token_with_duplicates paypal_account_email phone website).freeze
12
+ end
13
+
14
+ def multiple_search_fields
15
+ %w(ids).freeze
16
+ end
17
+
18
+ def range_search_fields
19
+ %w(created_at).freeze
20
+ end
21
+
22
+ end
23
+
5
24
  desc 'find ID', 'Get customer by identifier'
6
25
  def find(id)
7
26
  customer = Braintree::Customer.find(id)
8
-
9
27
  build_table([customer])
10
28
  end
11
29
 
30
+ desc 'query OPTIONS', 'Find customer matching criteria specified in options'
31
+ define_query_options
32
+ def query
33
+ run_query Braintree::Customer
34
+ end
35
+
12
36
  end
13
37
  end
14
38
  end
@@ -0,0 +1,14 @@
1
+ module Brainshell
2
+ module Commands
3
+ class MerchantAccount < Base
4
+
5
+ desc 'find ID', 'Get merchant account by identifier'
6
+ def find(id)
7
+ merchant_account = Braintree::MerchantAccount.find(id)
8
+ build_table([merchant_account])
9
+ end
10
+
11
+ end
12
+ end
13
+ end
14
+
@@ -2,30 +2,38 @@ module Brainshell
2
2
  module Commands
3
3
  class Subscription < Base
4
4
 
5
+ class << self
6
+
7
+ def text_search_fields
8
+ %w(id transaction_id).freeze
9
+ end
10
+
11
+ def multiple_search_fields
12
+ %w(ids in_trial_period merchant_account_id plan_id status).freeze
13
+ end
14
+
15
+ def range_search_fields
16
+ %w(billing_cycles_remaining days_past_due next_billing_date price).freeze
17
+ end
18
+ end
19
+
5
20
  desc 'find ID', 'Get subscription by identifier'
6
21
  def find(id)
7
22
  subscription = Braintree::Subscription.find(id)
8
-
9
23
  build_table([subscription])
10
24
  end
11
25
 
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
20
- search_results = Braintree::Subscription.search do |search|
21
- assign_multiple_value_criteria(search, :ids)
22
- assign_multiple_value_criteria(search, :plan_id)
23
- assign_multiple_value_criteria(search, :status)
26
+ desc 'status_history ID', 'Get subscription status history by identifier'
27
+ def status_history(id)
28
+ subscription = Braintree::Subscription.find(id)
24
29
 
25
- assign_range_criteria(search, :price)
26
- end
30
+ build_table(subscription.status_history, [:balance, :price, :status, :subscription_source])
31
+ end
27
32
 
28
- build_table(search_results.to_a)
33
+ desc 'query OPTIONS', 'Find subscriptions matching criteria specified in options'
34
+ define_query_options
35
+ def query
36
+ run_query Braintree::Subscription
29
37
  end
30
38
 
31
39
  end
@@ -2,6 +2,31 @@ module Brainshell
2
2
  module Commands
3
3
  class Transaction < Base
4
4
 
5
+ class << self
6
+
7
+ def text_search_fields
8
+ %w(billing_company billing_country_name billing_extended_address billing_first_name
9
+ billing_last_name billing_locality billing_postal_code billing_region billing_street_address
10
+ credit_card_cardholder_name credit_card_expiration_date credit_card_number credit_card_unique_identifier
11
+ currency customer_company customer_email customer_fax customer_first_name customer_id customer_last_name
12
+ customer_phone customer_website id order_id payment_method_token paypal_authorization_id paypal_payer_email
13
+ paypal_payment_id processor_authorization_code settlement_batch_id shipping_company shipping_country_name
14
+ shipping_extended_address shipping_first_name shipping_last_name shipping_locality shipping_postal_code
15
+ shipping_region shipping_street_address).freeze
16
+ end
17
+
18
+ def multiple_search_fields
19
+ %w(created_using credit_card_card_type credit_card_customer_location ids merchant_account_id
20
+ payment_instrument_type refund settled_at source status type user).freeze
21
+ end
22
+
23
+ def range_search_fields
24
+ %w(amount authorization_expired_at authorized_at created_at dispute_date failed_at
25
+ gateway_rejected_at processor_declined_at submitted_for_settlement_at voided_at).freeze
26
+ end
27
+
28
+ end
29
+
5
30
  desc 'find TOKEN', 'Get transaction by identifier'
6
31
  def find(token)
7
32
  transaction = Braintree::Transaction.find(token)
@@ -9,6 +34,19 @@ module Brainshell
9
34
  build_table([transaction])
10
35
  end
11
36
 
37
+ desc 'query OPTIONS', 'Find subscriptions matching criteria specified in options'
38
+ define_query_options
39
+ def query
40
+ run_query Braintree::Transaction
41
+ end
42
+
43
+ desc 'disbursement_details TOKEN', 'Get disbursement details by identifier'
44
+ def disbursement_details(token)
45
+ transaction = Braintree::Transaction.find(token)
46
+
47
+ build_table([transaction.disbursement_details], [:disbursement_date, :funds_held?, :settlement_amount, :success])
48
+ end
49
+
12
50
  end
13
51
  end
14
52
  end
@@ -3,12 +3,18 @@ module Brainshell
3
3
 
4
4
  KNOWN_FORMAT_METHODS = {
5
5
  BigDecimal => :big_decimal,
6
- DateTime => :date_time
6
+ DateTime => :date_time,
7
+ Braintree::CreditCard => :model_with_token,
8
+ Braintree::Subscription => :model_with_id
7
9
  }.freeze
8
10
 
9
11
  def format_value(value)
10
- format_method = KNOWN_FORMAT_METHODS[value.class]
11
- format_method ? send(format_method, value) : value
12
+ if value.is_a? Array
13
+ value.map { |item| format_value(item) }.join(',')
14
+ else
15
+ format_method = KNOWN_FORMAT_METHODS[value.class]
16
+ format_method ? send(format_method, value) : value
17
+ end
12
18
  end
13
19
 
14
20
  protected
@@ -21,5 +27,13 @@ module Brainshell
21
27
  value.iso8601
22
28
  end
23
29
 
30
+ def model_with_token(value)
31
+ value.token
32
+ end
33
+
34
+ def model_with_id(value)
35
+ value.id
36
+ end
37
+
24
38
  end
25
39
  end
@@ -1,3 +1,3 @@
1
1
  module Brainshell
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.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.2.0
4
+ version: 0.3.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-10 00:00:00.000000000 Z
11
+ date: 2016-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
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'
69
83
  description: Console client for accessing Braintree payment gateway
70
84
  email:
71
85
  - koss.lebedev@gmail.com
@@ -75,13 +89,16 @@ extensions: []
75
89
  extra_rdoc_files: []
76
90
  files:
77
91
  - ".gitignore"
92
+ - ".rspec"
78
93
  - Gemfile
79
94
  - README.md
80
95
  - bin/brainshell
81
96
  - brainshell.gemspec
82
97
  - lib/brainshell.rb
83
98
  - lib/brainshell/commands/base.rb
99
+ - lib/brainshell/commands/credit_card.rb
84
100
  - lib/brainshell/commands/customer.rb
101
+ - lib/brainshell/commands/merchant_account.rb
85
102
  - lib/brainshell/commands/subscription.rb
86
103
  - lib/brainshell/commands/transaction.rb
87
104
  - lib/brainshell/value_formatter.rb