class Stripe::CLI::Command
Public Instance Methods
inspect(object)
click to toggle source
# File lib/stripe/cli/command.rb, line 87 def inspect object case object when Array object.map {|o| inspect(o) } when Hash handle_hash object when Stripe::ListObject inspect object.data when Stripe::StripeObject inspect object.instance_variable_get(:@values) when Numeric object > 1000000000 ? handle_date(object) : object else object end end
Protected Instance Methods
api_key()
click to toggle source
# File lib/stripe/cli/command.rb, line 20 def api_key @api_key ||= options[:key] || stored_api_option('key') end
api_version()
click to toggle source
# File lib/stripe/cli/command.rb, line 24 def api_version @api_version ||= options.delete(:version) || stored_api_option('version') end
config()
click to toggle source
# File lib/stripe/cli/command.rb, line 54 def config ParseConfig.new(config_file) if File.exist?(config_file) end
config_file()
click to toggle source
# File lib/stripe/cli/command.rb, line 58 def config_file File.exist?(@@local_config) ? @@local_config : @@root_config end
create(klass, options)
click to toggle source
# File lib/stripe/cli/command.rb, line 74 def create klass, options request klass, :create, options end
date_format()
click to toggle source
# File lib/stripe/cli/command.rb, line 32 def date_format options.delete(:dates) || stored_api_option('dates') end
delete(klass, id)
click to toggle source
# File lib/stripe/cli/command.rb, line 70 def delete klass, id request klass.new( id, {:api_key => api_key} ), :delete end
dollar_amounts()
click to toggle source
# File lib/stripe/cli/command.rb, line 36 def dollar_amounts options.delete(:dollar_amounts) { !(stored_api_option('dollar_amounts') == 'false') } end
environment()
click to toggle source
# File lib/stripe/cli/command.rb, line 28 def environment @env ||= options.delete(:env) || config['default'] end
find(klass, id)
click to toggle source
# File lib/stripe/cli/command.rb, line 66 def find klass, id request klass, :retrieve, {:id => id, :expand => options[:expand]} end
list(klass, options)
click to toggle source
# File lib/stripe/cli/command.rb, line 62 def list klass, options request klass, :all, options end
request(object, method, *arguments)
click to toggle source
# File lib/stripe/cli/command.rb, line 78 def request object, method, *arguments pre_request_setup begin output object.send method, *arguments rescue StripeError => e output e.message end end
stored_api_option(option)
click to toggle source
# File lib/stripe/cli/command.rb, line 44 def stored_api_option option if File.exists?(config_file) if environment config[environment][option.to_s] || config[option.to_s] else config[option.to_s] end end end
strip_nils?()
click to toggle source
# File lib/stripe/cli/command.rb, line 40 def strip_nils? options.delete(:strip_nils) { stored_api_option('strip_nils') == "true" } end
Private Instance Methods
handle_date(object)
click to toggle source
# File lib/stripe/cli/command.rb, line 127 def handle_date object case @date_format when 'unix' then object when 'utc' Time.at( object ).utc else Time.at( object ) end end
handle_hash(object)
click to toggle source
# File lib/stripe/cli/command.rb, line 120 def handle_hash object object.inject({}) do |hash, (key, value)| hash[key] = inspect( value ) unless @strip_nils && value.nil? hash end end
output(objects)
click to toggle source
# File lib/stripe/cli/command.rb, line 107 def output objects ap inspect( objects ), :indent => -2 end
pre_request_setup()
click to toggle source
strip non-api params from options hash set api_version
& api_key
# File lib/stripe/cli/command.rb, line 113 def pre_request_setup @strip_nils = strip_nils? @date_format = date_format Stripe.api_key = api_key Stripe.api_version = api_version unless api_version.nil? end