shelly 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - ree
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # shelly: Shelly Cloud command line tool
1
+ # shelly: Shelly Cloud command line tool [![Build Status](https://secure.travis-ci.org/Ragnarson/shelly.png)](http://travis-ci.org/Ragnarson/shelly.png)
2
2
 
3
3
  ## Installation
4
4
 
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
+ task :default => :spec
4
5
  desc "Run specs"
5
6
  RSpec::Core::RakeTask.new do |t|
6
7
  t.rspec_opts = %w(-fs --color)
data/lib/shelly.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  require "rubygems"
2
2
  require "thor"
3
3
  require "core_ext/object"
4
+ require "shelly/helpers"
4
5
 
5
6
  module Shelly
6
- autoload :VERSION, "shelly/version"
7
7
  autoload :Client, "shelly/client"
8
+ autoload :User, "shelly/user"
9
+ autoload :VERSION, "shelly/version"
8
10
  end
data/lib/shelly/cli.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  require "shelly"
2
+ require "shelly/user"
2
3
 
3
4
  module Shelly
4
5
  class CLI < Thor
6
+ include Helpers
5
7
  include Thor::Actions
6
- autoload :User, "shelly/user"
7
8
 
8
9
  map %w(-v --version) => :version
9
10
  desc "version", "Displays shelly version"
@@ -16,7 +17,7 @@ module Shelly
16
17
  email_question = User.guess_email.blank? ? "Email:" : "Email (default #{User.guess_email}):"
17
18
  email = ask(email_question)
18
19
  email = User.guess_email if email.blank?
19
- password = ask("Password:")
20
+ password = ask_for_password
20
21
 
21
22
  if email.blank? or password.blank?
22
23
  say "Email and password can't be blank" and exit 1
@@ -31,5 +32,15 @@ module Shelly
31
32
  e.errors.each { |error| say "#{error.first} #{error.last}" }
32
33
  end
33
34
  end
35
+
36
+ no_tasks do
37
+ def ask_for_password
38
+ say "Password: "
39
+ echo_off
40
+ password = $stdin.gets.strip
41
+ echo_on
42
+ password
43
+ end
44
+ end
34
45
  end
35
46
  end
data/lib/shelly/client.rb CHANGED
@@ -41,16 +41,26 @@ module Shelly
41
41
  end
42
42
 
43
43
  def request(path, method, params = {})
44
+ options = request_parameters(path, method, params)
45
+ RestClient::Request.execute(options) do |response, request|
46
+ process_response(response)
47
+ end
48
+ end
49
+
50
+ def headers
51
+ {:accept => :json,
52
+ :content_type => :json,
53
+ "shelly-version" => Shelly::VERSION}
54
+ end
55
+
56
+ def request_parameters(path, method, params = {})
44
57
  unless @email.blank? or @password.blank?
45
58
  params.merge!(:email => @email, :password => @password)
46
59
  end
47
-
48
- RestClient::Request.execute(
49
- :method => method,
50
- :url => "#{api_url}#{path}",
51
- :headers => headers,
52
- :payload => params.to_json
53
- ) { |response, request| process_response(response) }
60
+ {:method => method,
61
+ :url => "#{api_url}#{path}",
62
+ :headers => headers,
63
+ :payload => params.to_json}
54
64
  end
55
65
 
56
66
  def process_response(response)
@@ -68,11 +78,5 @@ module Shelly
68
78
  raise UnsupportedResponseException.new(e)
69
79
  end
70
80
  end
71
-
72
- def headers
73
- {:accept => :json,
74
- :content_type => :json,
75
- "shelly-version" => Shelly::VERSION}
76
- end
77
81
  end
78
82
  end
@@ -0,0 +1,11 @@
1
+ module Shelly
2
+ module Helpers
3
+ def echo_off
4
+ system "stty -echo"
5
+ end
6
+
7
+ def echo_on
8
+ system "stty echo"
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Shelly
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/shelly.gemspec CHANGED
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
13
13
 
14
14
  s.rubyforge_project = "shelly"
15
15
  s.add_development_dependency "rspec"
16
+ s.add_development_dependency "rake"
16
17
  s.add_development_dependency "guard"
17
18
  s.add_development_dependency "guard-rspec"
18
19
  if RUBY_PLATFORM =~ /darwin/
@@ -23,57 +23,52 @@ describe Shelly::Client do
23
23
  end
24
24
  end
25
25
 
26
- describe "#request" do
27
- it "should make a request to given URL" do
28
- RestClient::Request.should_receive(:execute).with(
29
- request_parameters("/account", :get)
30
- )
31
- @client.request("/account", :get)
26
+ describe "#register_user" do
27
+ it "should send post request with login and password" do
28
+ @client.should_receive(:post).with("/users", {:user => {:email => "test@example.com", :password => "secret"}})
29
+ @client.register_user("test@example.com", "secret")
32
30
  end
31
+ end
33
32
 
34
- it "should include provided parameters in the request" do
35
- RestClient::Request.should_receive(:execute).with(
36
- request_parameters("/account", :post, {:name => "test"})
37
- )
38
- @client.request("/account", :post, :name => "test")
33
+ describe "#request_parameters" do
34
+ it "should return hash of resquest parameters" do
35
+ expected = {
36
+ :method => :post,
37
+ :url => "#{@client.api_url}/account",
38
+ :headers => @client.headers,
39
+ :payload => {:name => "bob", :email => "bob@example.com", :password => "secret"}.to_json
40
+ }
41
+ @client.request_parameters("/account", :post, :name => "bob").should == expected
39
42
  end
40
43
 
41
- it "should include user credentials in the request parameters" do
42
- @client = Shelly::Client.new("megan-fox@example.com", "secret")
43
- RestClient::Request.should_receive(:execute).with(
44
- request_parameters("/account", :get, {:email => "megan-fox@example.com", :password => "secret"})
45
- )
46
- @client.request("/account", :get)
44
+ it "should not include user credentials when they are blank" do
45
+ client = Shelly::Client.new
46
+ expected = {
47
+ :method => :get,
48
+ :url => "#{@client.api_url}/account",
49
+ :headers => @client.headers,
50
+ :payload => {}.to_json
51
+ }
52
+ client.request("/account", :get)
47
53
  end
54
+ end
48
55
 
49
- it "should not include user credentials when they are blank" do
50
- @client = Shelly::Client.new
51
- RestClient::Request.should_receive(:execute).with(
52
- :method => :get,
53
- :url => "https://admin.winniecloud.com/apiv2/account",
54
- :headers => {:accept => :json, :content_type => :json, "shelly-version" => Shelly::VERSION},
55
- :payload => "{}"
56
- )
57
- @client.request("/account", :get)
56
+ describe "#request" do
57
+ it "should get request parameters" do
58
+ @client.should_receive(:request_parameters)\
59
+ .with("/account", :get, {:sth => "foo"})\
60
+ .and_return({:method => :get})
61
+ RestClient::Request.should_receive(:execute).with({:method => :get})
62
+ @client.request("/account", :get, {:sth => "foo"})
58
63
  end
59
64
 
60
65
  it "should pass response to process_response method" do
61
66
  response = mock(RestClient::Response)
62
67
  request = mock(RestClient::Request)
63
68
  @client.should_receive(:process_response).with(response)
64
- RestClient::Request.should_receive(:execute).with(
65
- request_parameters("/account", :get)
66
- ).and_yield(response, request)
67
-
69
+ RestClient::Request.stub(:execute).and_yield(response, request)
68
70
  @client.request("/account", :get)
69
71
  end
70
-
71
- def request_parameters(path, method, payload = {})
72
- {:method => method,
73
- :url => "https://admin.winniecloud.com/apiv2#{path}",
74
- :headers => {:accept => :json, :content_type => :json, "shelly-version" => Shelly::VERSION},
75
- :payload => ({:email => "bob@example.com", :password => "secret"}.merge(payload)).to_json}
76
- end
77
72
  end
78
73
 
79
74
  describe "#process_response" do
@@ -135,6 +130,17 @@ describe Shelly::Client do
135
130
  end
136
131
  end
137
132
 
133
+ describe "#headers" do
134
+ it "should return hash of headers" do
135
+ expected = {
136
+ :accept => :json,
137
+ :content_type => :json,
138
+ "shelly-version" => Shelly::VERSION
139
+ }
140
+ @client.headers.should == expected
141
+ end
142
+ end
143
+
138
144
  describe "#get" do
139
145
  it "should make GET request to given path" do
140
146
  @client.should_receive(:request).with("/account", :get)
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require "rspec"
2
- require "helpers"
3
2
  require "shelly"
4
- require "io_ext"
3
+ require "helpers"
5
4
  require "input_faker"
6
5
  require "fakefs/safe"
7
6
  require "fakefs/spec_helpers"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shelly
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Shelly Cloud team
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-13 00:00:00 +02:00
18
+ date: 2011-09-15 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -33,7 +33,7 @@ dependencies:
33
33
  type: :development
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- name: guard
36
+ name: rake
37
37
  prerelease: false
38
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
@@ -47,7 +47,7 @@ dependencies:
47
47
  type: :development
48
48
  version_requirements: *id002
49
49
  - !ruby/object:Gem::Dependency
50
- name: guard-rspec
50
+ name: guard
51
51
  prerelease: false
52
52
  requirement: &id003 !ruby/object:Gem::Requirement
53
53
  none: false
@@ -61,7 +61,7 @@ dependencies:
61
61
  type: :development
62
62
  version_requirements: *id003
63
63
  - !ruby/object:Gem::Dependency
64
- name: growl_notify
64
+ name: guard-rspec
65
65
  prerelease: false
66
66
  requirement: &id004 !ruby/object:Gem::Requirement
67
67
  none: false
@@ -75,7 +75,7 @@ dependencies:
75
75
  type: :development
76
76
  version_requirements: *id004
77
77
  - !ruby/object:Gem::Dependency
78
- name: rb-fsevent
78
+ name: growl_notify
79
79
  prerelease: false
80
80
  requirement: &id005 !ruby/object:Gem::Requirement
81
81
  none: false
@@ -89,7 +89,7 @@ dependencies:
89
89
  type: :development
90
90
  version_requirements: *id005
91
91
  - !ruby/object:Gem::Dependency
92
- name: fakefs
92
+ name: rb-fsevent
93
93
  prerelease: false
94
94
  requirement: &id006 !ruby/object:Gem::Requirement
95
95
  none: false
@@ -103,7 +103,7 @@ dependencies:
103
103
  type: :development
104
104
  version_requirements: *id006
105
105
  - !ruby/object:Gem::Dependency
106
- name: thor
106
+ name: fakefs
107
107
  prerelease: false
108
108
  requirement: &id007 !ruby/object:Gem::Requirement
109
109
  none: false
@@ -114,10 +114,10 @@ dependencies:
114
114
  segments:
115
115
  - 0
116
116
  version: "0"
117
- type: :runtime
117
+ type: :development
118
118
  version_requirements: *id007
119
119
  - !ruby/object:Gem::Dependency
120
- name: rest-client
120
+ name: thor
121
121
  prerelease: false
122
122
  requirement: &id008 !ruby/object:Gem::Requirement
123
123
  none: false
@@ -131,7 +131,7 @@ dependencies:
131
131
  type: :runtime
132
132
  version_requirements: *id008
133
133
  - !ruby/object:Gem::Dependency
134
- name: json
134
+ name: rest-client
135
135
  prerelease: false
136
136
  requirement: &id009 !ruby/object:Gem::Requirement
137
137
  none: false
@@ -144,6 +144,20 @@ dependencies:
144
144
  version: "0"
145
145
  type: :runtime
146
146
  version_requirements: *id009
147
+ - !ruby/object:Gem::Dependency
148
+ name: json
149
+ prerelease: false
150
+ requirement: &id010 !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ hash: 3
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ type: :runtime
160
+ version_requirements: *id010
147
161
  description: Tool for managing applications and clouds at shellycloud.com
148
162
  email:
149
163
  - support@shellycloud.com
@@ -155,6 +169,7 @@ extra_rdoc_files: []
155
169
 
156
170
  files:
157
171
  - .gitignore
172
+ - .travis.yml
158
173
  - Gemfile
159
174
  - Guardfile
160
175
  - README.md
@@ -164,12 +179,12 @@ files:
164
179
  - lib/shelly.rb
165
180
  - lib/shelly/cli.rb
166
181
  - lib/shelly/client.rb
182
+ - lib/shelly/helpers.rb
167
183
  - lib/shelly/user.rb
168
184
  - lib/shelly/version.rb
169
185
  - shelly.gemspec
170
186
  - spec/helpers.rb
171
187
  - spec/input_faker.rb
172
- - spec/io_ext.rb
173
188
  - spec/shelly/cli_spec.rb
174
189
  - spec/shelly/client_spec.rb
175
190
  - spec/shelly/user_spec.rb
@@ -211,7 +226,6 @@ summary: Shelly Cloud command line tool
211
226
  test_files:
212
227
  - spec/helpers.rb
213
228
  - spec/input_faker.rb
214
- - spec/io_ext.rb
215
229
  - spec/shelly/cli_spec.rb
216
230
  - spec/shelly/client_spec.rb
217
231
  - spec/shelly/user_spec.rb
data/spec/io_ext.rb DELETED
@@ -1,5 +0,0 @@
1
- class IO
2
- def read_available_bytes
3
- readpartial(100000)
4
- end
5
- end