Class: BSClient::CLI
- Inherits:
-
Thor
- Object
- Thor
- BSClient::CLI
- Defined in:
- lib/bsclient/cli.rb
Instance Method Summary collapse
- #create_user_image(account, text, size = "30", color = "red") ⇒ Object
- #download_user_image(account) ⇒ Object
- #get(url, *raw_params) ⇒ Object
- #post(url, *args) ⇒ Object
- #query_registration(task_id, account) ⇒ Object
- #register_account(filename = nil) ⇒ Object
Instance Method Details
#create_user_image(account, text, size = "30", color = "red") ⇒ Object
30 31 32 33 34 |
# File 'lib/bsclient/cli.rb', line 30 def create_user_image(account, text, size="30", color="red") req_content = {account: account, text: text, fontSize: size, fontColor: color}.to_json app = App.new(, Config.create([:env])) print app.create_user_image(req_content) end |
#download_user_image(account) ⇒ Object
37 38 39 40 41 |
# File 'lib/bsclient/cli.rb', line 37 def download_user_image(account) params = {account: account, imageName: ''} app = App.new(, Config.create([:env])) print app.download_user_image(params) end |
#get(url, *raw_params) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/bsclient/cli.rb', line 44 def get(url, *raw_params) params = raw_params.each_with_object({}) do |param, h| k, v = param.split('=') h[k.to_sym] = v end app = App.new(, Config.create([:env])) print app.get(url, params) end |
#post(url, *args) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/bsclient/cli.rb', line 54 def post(url, *args) if not STDIN.isatty params = JSON.parse(STDIN.read) elsif File.exist?(args.first) params = File.read(args.first) else params = args.each_with_object({}) do |param, h| k, v = param.split('=') value = v value = JSON.parse(v[1..-1]) if v[0] == ':' h[k.to_sym] = value end end app = App.new(, Config.create([:env])) print app.post_json(url, params) end |
#query_registration(task_id, account) ⇒ Object
24 25 26 27 |
# File 'lib/bsclient/cli.rb', line 24 def query_registration(task_id, account) app = App.new(, Config.create([:env])) print app.query_registration(task_id, account) end |
#register_account(filename = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/bsclient/cli.rb', line 12 def register_account(filename = nil) req_content = if filename IO.read(filename) else STDIN.read end req_content = JSON.generate(JSON.parse(req_content)) app = App.new(, Config.create([:env])) print app.register_account(req_content) end |