heywatch 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/heywatch +48 -12
  2. data/lib/heywatch.rb +17 -3
  3. metadata +3 -3
data/bin/heywatch CHANGED
@@ -10,20 +10,48 @@ config_file = "#{ENV["HOME"]}/.heywatch"
10
10
  if File.exists?(config_file)
11
11
  user, passwd = File.read(config_file).split("\n")
12
12
  else
13
- puts "HeyWatch username:"
14
- user = $stdin.gets.chomp
15
- puts "HeyWatch password:"
16
- system "stty -echo"
17
- passwd = $stdin.gets.chomp
18
- system "stty echo"
13
+ print "Do you want to create an HeyWatch account? (Y/n) "
14
+ if $stdin.gets.chomp.downcase == "y"
15
+ data = {}
16
+ [:firstname, :lastname, :email, :login].each do |f|
17
+ print "#{f}: ".capitalize
18
+ data[f] = $stdin.gets.chomp
19
+ end
20
+
21
+ [:password, :password_confirmation].each do |f|
22
+ print "#{f}: ".capitalize.gsub("_", " ")
23
+ system "stty -echo"
24
+ data[f] = $stdin.gets.chomp
25
+ system "stty echo"
26
+ puts
27
+ end
28
+
29
+ print "Is the information correct? (Y/n) "
30
+ exit if $stdin.gets.chomp.downcase != "y"
31
+
32
+ begin
33
+ HeyWatch.register(data)
34
+ user, passwd = data[:login], data[:password]
35
+ rescue => e
36
+ puts e
37
+ exit
38
+ end
39
+ else
40
+ print "HeyWatch username: "
41
+ user = $stdin.gets.chomp
42
+ print "HeyWatch password: "
43
+ system "stty -echo"
44
+ passwd = $stdin.gets.chomp
45
+ system "stty echo"
46
+ puts
47
+ end
19
48
 
20
49
  # testing credentials
21
50
  begin
22
51
  HeyWatch.new(user, passwd)
23
52
  File.open(config_file, "w") {|f| f.write("#{user}\n#{passwd}") }
24
53
  File.chmod(0600, config_file)
25
- puts "Your credentials have been saved in this file #{config_file} (0600)"
26
- exit
54
+ puts "Your credentials have been saved in this file #{config_file} (0600)\n-----\n"
27
55
  rescue => e
28
56
  puts "Wrong login or password."
29
57
  exit
@@ -38,7 +66,7 @@ begin
38
66
 
39
67
  Resources:
40
68
 
41
- account # account information
69
+ account # manage account | create, update
42
70
  video # manage video | all, info, delete, count, bin
43
71
  encoded_video # manage encoded video | all, info, delete, count, bin, jpg
44
72
  download # manage download | all, info, delete, count, create
@@ -48,6 +76,7 @@ begin
48
76
  Usage:
49
77
 
50
78
  heywatch account
79
+ heywatch account:update env=sandbox
51
80
  heywatch video:info 123456
52
81
  heywatch job:all
53
82
  heywatch download:create url=http://site.com/video.mp4 title=mytitle
@@ -60,7 +89,7 @@ begin
60
89
  exit
61
90
  end
62
91
 
63
- if ARGV[0] == "account"
92
+ if ARGV.size == 1 and ARGV[0] == "account"
64
93
  puts JSON.pretty_generate(hw.account)
65
94
  exit
66
95
  end
@@ -72,13 +101,20 @@ begin
72
101
 
73
102
  if method == "create"
74
103
  params = Hash[*ARGV[1..-1].map{|p| k,v = p.split("=") }.flatten]
75
- puts JSON.pretty_generate(hw.send(method, *[resource, params]))
104
+
105
+ if resource == "account"
106
+ puts JSON.pretty_generate(HeyWatch.register(params))
107
+ else
108
+ puts JSON.pretty_generate(hw.send(method, *[resource, params]))
109
+ end
76
110
  exit
77
111
  end
78
112
 
79
113
  if method == "update"
80
114
  params = Hash[*ARGV[2..-1].map{|p| k,v = p.split("=") }.flatten]
81
- puts JSON.pretty_generate(hw.send(method, *[resource, ARGV[1], params]))
115
+
116
+ hw.send(method, *[resource, ARGV[1], params])
117
+ puts "ok"
82
118
  exit
83
119
  end
84
120
 
data/lib/heywatch.rb CHANGED
@@ -6,7 +6,7 @@ class HeyWatch
6
6
  class BadRequest < RuntimeError; end
7
7
 
8
8
  URL = "https://heywatch.com"
9
- VERSION = "1.0.3"
9
+ VERSION = "1.0.4"
10
10
 
11
11
  attr_reader :cli
12
12
 
@@ -20,6 +20,14 @@ class HeyWatch
20
20
  self
21
21
  end
22
22
 
23
+ def self.register(data={})
24
+ cli = RestClient::Resource.new(URL, {:headers =>
25
+ {:user_agent => "HeyWatch Ruby/#{VERSION}", :accept => "application/json"}})
26
+ JSON.parse(cli["/account"].post(data))
27
+ rescue RestClient::BadRequest=> e
28
+ raise BadRequest, e.http_body
29
+ end
30
+
23
31
  def inspect # :nodoc:
24
32
  "#<HeyWatch: " + account.inspect + ">"
25
33
  end
@@ -104,10 +112,16 @@ class HeyWatch
104
112
  raise BadRequest, e.http_body
105
113
  end
106
114
 
107
- # Update an object by giving its resource and ID
115
+ # Update an object by giving its resource and ID (except account)
108
116
  #
109
117
  # hw.update :format, 9877, :video_bitrate => 890
110
- def update(resource, id, data={})
118
+ def update(resource, *params)
119
+ if resource.to_sym == :account
120
+ @cli["/#{resource}"].put(params[0])
121
+ return true
122
+ end
123
+
124
+ id, data = params
111
125
  @cli["/#{resource}/#{id}"].put(data)
112
126
  true
113
127
  rescue RestClient::BadRequest=> e
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heywatch
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 3
10
- version: 1.0.3
9
+ - 4
10
+ version: 1.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bruno Celeste