cloudapp_api 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -17,5 +17,7 @@ tmtags
17
17
  coverage
18
18
  rdoc
19
19
  pkg
20
+ .autotest
20
21
 
21
22
  ## PROJECT::SPECIFIC
23
+ test/test_config.yml
data/README.md CHANGED
@@ -87,9 +87,10 @@ If you are using the client interface, you must create a client instance.
87
87
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
88
88
  * Send me a pull request. Bonus points for topic branches.
89
89
 
90
- ## Author
90
+ ## Author & Contributors
91
91
 
92
92
  * [Aaron Russell](http://www.aaronrussell.co.uk)
93
+ * [Wade West](http://github.com/wadewest)
93
94
 
94
95
  ## Copyright
95
96
 
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ begin
9
9
  gem.description = %Q{A simple Ruby wrapper for the CloudApp API. Uses HTTParty with a simple ActiveResource-like interface.}
10
10
  gem.email = "aaron@gc4.co.uk"
11
11
  gem.homepage = "http://github.com/aaronrussell/cloud_app"
12
- gem.authors = ["Aaron Russell"]
12
+ gem.authors = ["Aaron Russell", "Wade West"]
13
13
  gem.add_dependency "httparty", ">= 0.5.2"
14
14
  gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
15
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
@@ -48,7 +48,7 @@ Rake::RDocTask.new do |rdoc|
48
48
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
49
 
50
50
  rdoc.rdoc_dir = 'rdoc'
51
- rdoc.title = "cloudly #{version}"
51
+ rdoc.title = "cloudapp_api #{version}"
52
52
  rdoc.rdoc_files.include('README*')
53
53
  rdoc.rdoc_files.include('lib/**/*.rb')
54
54
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/cloudapp_api.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cloudapp_api}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Aaron Russell"]
12
- s.date = %q{2010-05-18}
11
+ s.authors = ["Aaron Russell", "Wade West"]
12
+ s.date = %q{2010-11-13}
13
13
  s.description = %q{A simple Ruby wrapper for the CloudApp API. Uses HTTParty with a simple ActiveResource-like interface.}
14
14
  s.email = %q{aaron@gc4.co.uk}
15
15
  s.extra_rdoc_files = [
@@ -32,23 +32,29 @@ Gem::Specification.new do |s|
32
32
  "lib/cloudapp/multipart.rb",
33
33
  "lib/cloudapp_api.rb",
34
34
  "test/helper.rb",
35
- "test/test_cloudly.rb"
35
+ "test/helper/faking_setup.rb",
36
+ "test/helper/methods.rb",
37
+ "test/test_base.rb",
38
+ "test/test_cloudapp_api.rb"
36
39
  ]
37
40
  s.homepage = %q{http://github.com/aaronrussell/cloud_app}
38
41
  s.rdoc_options = ["--charset=UTF-8"]
39
42
  s.require_paths = ["lib"]
40
- s.rubygems_version = %q{1.3.6}
43
+ s.rubygems_version = %q{1.3.7}
41
44
  s.summary = %q{A simple Ruby wrapper for the CloudApp API. Uses HTTParty with a simple ActiveResource-like interface.}
42
45
  s.test_files = [
43
- "test/helper.rb",
44
- "test/test_cloudly.rb"
46
+ "test/helper/faking_setup.rb",
47
+ "test/helper/methods.rb",
48
+ "test/helper.rb",
49
+ "test/test_base.rb",
50
+ "test/test_cloudapp_api.rb"
45
51
  ]
46
52
 
47
53
  if s.respond_to? :specification_version then
48
54
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
55
  s.specification_version = 3
50
56
 
51
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
57
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
58
  s.add_runtime_dependency(%q<httparty>, [">= 0.5.2"])
53
59
  s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
60
  else
data/lib/cloudapp/base.rb CHANGED
@@ -24,8 +24,9 @@ module CloudApp
24
24
  res.ok? ? Item.new(res) : res
25
25
  end
26
26
 
27
- def self.all(opts = {})
28
- res = get "/items", opts.merge!(:digest_auth => @@auth)
27
+ def self.all(opts = nil)
28
+ opts = opts.nil? ? "" : "?#{opts.to_params}"
29
+ res = get "/items#{opts}", :digest_auth => @@auth
29
30
  res.ok? ? res.collect{|i| Item.new(i)} : res
30
31
  end
31
32
 
@@ -29,7 +29,8 @@ module CloudApp
29
29
  end
30
30
 
31
31
  def delete(id)
32
- Item.find(id).delete
32
+ item = Item.find(id)
33
+ item.class == Item ? item.delete : item
33
34
  end
34
35
 
35
36
  end
@@ -7,7 +7,7 @@ end
7
7
  module HTTParty
8
8
  class Response < HTTParty::BasicObject
9
9
  def ok?
10
- @code == 200
10
+ self.code == 200
11
11
  end
12
12
  end
13
13
 
@@ -0,0 +1,15 @@
1
+ require 'fakeweb'
2
+ require 'helper/methods'
3
+
4
+ FakeWeb.allow_net_connect = false
5
+
6
+ FakeWeb.register_uri :head, %r\^http://(my|f).cl.ly(/items)?\, auth_response
7
+ FakeWeb.register_uri :get, "http://my.cl.ly/items", item_listing_response
8
+ FakeWeb.register_uri :post, %r|^http://my.cl.ly/items|, new_bookmark_response
9
+
10
+ FakeWeb.register_uri :get, %r|^http://cl.ly|, get_item_response
11
+
12
+ FakeWeb.register_uri :delete, "http://my.cl.ly/items/1234", [ ok_response, not_found_response ]
13
+
14
+ FakeWeb.register_uri :get, "http://my.cl.ly/items/new", new_item_response
15
+ FakeWeb.register_uri :post, "http://f.cl.ly", ok_response
@@ -0,0 +1,81 @@
1
+ require 'json'
2
+ require 'json/add/rails'
3
+
4
+ def slug_character
5
+ characters = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
6
+ characters[ rand(characters.size) ]
7
+ end
8
+
9
+ def random_slug
10
+ slug_character + slug_character + slug_character + slug_character
11
+ end
12
+
13
+ def build_item( params = {} )
14
+ params = {
15
+ :type => 'image',
16
+ :public_slug => random_slug
17
+ }.merge(params)
18
+ {
19
+ "href" => "http://my.cl.ly/items/1234",
20
+ "content_url" => "http://cl.ly/#{params[:public_slug]}/content",
21
+ "redirect_url" => params[:type] == 'bookmark' ? "http://cloudapp.com" : nil,
22
+ "public_slug" => params[:public_slug],
23
+ "private" => false,
24
+ "deleted_at" => nil,
25
+ "url" => "http://cl.ly/#{params[:public_slug]}",
26
+ "remote_url" => params[:type] != 'bookmark' ? "http://f.cl.ly/items/1d1a7310f29c96/Item_Name.png" : nil,
27
+ "last_viewed" => nil,
28
+ "icon" => "http://my.cl.ly/images/item_types/#{params[:type]}.png",
29
+ "item_type" => params[:type]
30
+ }
31
+ end
32
+
33
+ def ok_response
34
+ { :status => ["200", "OK"] }
35
+ end
36
+
37
+ def auth_response
38
+ { :status => ["401", "Unauthorized"] }
39
+ end
40
+
41
+ def not_found_response
42
+ { :status => ["404", "Not Found"] }
43
+ end
44
+
45
+ def json_response
46
+ {:content_type => "application/json; charset=utf-8"}.merge(ok_response)
47
+ end
48
+
49
+ def item_listing_response
50
+ {
51
+ :body => [build_item, build_item, build_item(:type=>'bookmark')].to_json
52
+ }.merge(json_response)
53
+ end
54
+
55
+ def get_item_response
56
+ {
57
+ :body => build_item.to_json
58
+ }.merge(json_response)
59
+ end
60
+
61
+ def new_item_response
62
+ {
63
+ :body => {
64
+ "url" =>"http://f.cl.ly",
65
+ "params" => {
66
+ "success_action_redirect" => "http://my.cl.ly/items/s3",
67
+ "acl" => "public-read",
68
+ "AWSAccessKeyId" => "AKIABHXGSHSBEOFS6Q",
69
+ "key" => "items/dcb0aa186du4450478f0/${filename}",
70
+ "signature" => "Cm5S8VMo8fcyi4heVXqRqpYj6sE=",
71
+ "policy" => "eyJRoLXJhbmdlIiwwLDI2MjE0NDAeSIsIml0ZW1zL2RjYjBhYTE1Y2NjNDQ1MDQ3OGYwLyJdXX0=",
72
+ }
73
+ }.to_json
74
+ }.merge(json_response)
75
+ end
76
+
77
+ def new_bookmark_response
78
+ {
79
+ :body => build_item(:type => 'bookmark' ).to_json
80
+ }.merge(json_response)
81
+ end
data/test/helper.rb CHANGED
@@ -1,10 +1,24 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'shoulda'
4
+ require 'treetop'
5
+ require 'yaml'
4
6
 
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ TEST_DIR = File.join(File.dirname(__FILE__))
8
+
9
+ $LOAD_PATH.unshift(File.join(TEST_DIR, '..', 'lib'))
6
10
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'cloudly'
11
+ require 'helper/faking_setup'
12
+ require 'cloudapp_api'
8
13
 
9
14
  class Test::Unit::TestCase
15
+
16
+ def cloudapp_config
17
+ @@cloudapp_config ||= {:username=> 'fake@example.com', :password=>'foobar'}
18
+ end
19
+
20
+ def client
21
+ @@client ||= CloudApp::Client.new cloudapp_config
22
+ end
23
+
10
24
  end
data/test/test_base.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'helper'
2
+
3
+ class TestBase < Test::Unit::TestCase
4
+ def setup
5
+ @auth = CloudApp::Base.authenticate( cloudapp_config[:username], cloudapp_config[:password] )
6
+ end
7
+
8
+ should "be able to enter authentication info" do
9
+ setup
10
+ assert @auth, "CloudApp::Base.authenticate shouldn't have returned falsey value"
11
+ end
12
+
13
+ should "be able to find an item by public slug" do
14
+ setup
15
+ item = CloudApp::Base.find random_slug
16
+ assert_instance_of CloudApp::Item, item
17
+ end
18
+
19
+ end
@@ -0,0 +1,38 @@
1
+ require 'helper'
2
+
3
+ class TestCloudAppAPI < Test::Unit::TestCase
4
+
5
+ should "be able to create a client" do
6
+ assert_instance_of CloudApp::Client, client, "Couldn't create client."
7
+ end
8
+
9
+ should "test retreiving a listing of my uploaded files." do
10
+ items = client.items
11
+ assert_instance_of Array, items, "Couldn't retrieve the items."
12
+ end
13
+
14
+ should "test creating a bookmark" do
15
+ b = client.bookmark("CloudApp","http://cloudapp.com")
16
+ assert_instance_of CloudApp::Item, b, "Failed to create a bookmark."
17
+ end
18
+
19
+ should "be able to delete an item" do
20
+ res = client.delete "rAnD"
21
+ assert_same true, res, "Couldn't delete an item"
22
+
23
+ bad_res = client.delete "rAnD"
24
+ message = "Shouldn't be able to delete the same item"
25
+ assert_not_same true, bad_res, message
26
+ # HTTParty::Response has no instance_of? method so
27
+ # we can't use assert_instance_of
28
+ assert bad_res.class == HTTParty::Response, message
29
+ end
30
+
31
+ should "be able to upload a file" do
32
+ res = client.upload "README.md"
33
+ assert_instance_of CloudApp::Item, res, "Couldn't upload the file"
34
+ end
35
+
36
+ ### Can't think of any other test to add at the moment
37
+
38
+ end
metadata CHANGED
@@ -1,29 +1,33 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudapp_api
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 25
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 2
9
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
10
11
  platform: ruby
11
12
  authors:
12
13
  - Aaron Russell
14
+ - Wade West
13
15
  autorequire:
14
16
  bindir: bin
15
17
  cert_chain: []
16
18
 
17
- date: 2010-05-18 00:00:00 +01:00
19
+ date: 2010-11-13 00:00:00 +00:00
18
20
  default_executable:
19
21
  dependencies:
20
22
  - !ruby/object:Gem::Dependency
21
23
  name: httparty
22
24
  prerelease: false
23
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
24
27
  requirements:
25
28
  - - ">="
26
29
  - !ruby/object:Gem::Version
30
+ hash: 15
27
31
  segments:
28
32
  - 0
29
33
  - 5
@@ -35,9 +39,11 @@ dependencies:
35
39
  name: thoughtbot-shoulda
36
40
  prerelease: false
37
41
  requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
38
43
  requirements:
39
44
  - - ">="
40
45
  - !ruby/object:Gem::Version
46
+ hash: 3
41
47
  segments:
42
48
  - 0
43
49
  version: "0"
@@ -68,7 +74,10 @@ files:
68
74
  - lib/cloudapp/multipart.rb
69
75
  - lib/cloudapp_api.rb
70
76
  - test/helper.rb
71
- - test/test_cloudly.rb
77
+ - test/helper/faking_setup.rb
78
+ - test/helper/methods.rb
79
+ - test/test_base.rb
80
+ - test/test_cloudapp_api.rb
72
81
  has_rdoc: true
73
82
  homepage: http://github.com/aaronrussell/cloud_app
74
83
  licenses: []
@@ -79,26 +88,33 @@ rdoc_options:
79
88
  require_paths:
80
89
  - lib
81
90
  required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
82
92
  requirements:
83
93
  - - ">="
84
94
  - !ruby/object:Gem::Version
95
+ hash: 3
85
96
  segments:
86
97
  - 0
87
98
  version: "0"
88
99
  required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
89
101
  requirements:
90
102
  - - ">="
91
103
  - !ruby/object:Gem::Version
104
+ hash: 3
92
105
  segments:
93
106
  - 0
94
107
  version: "0"
95
108
  requirements: []
96
109
 
97
110
  rubyforge_project:
98
- rubygems_version: 1.3.6
111
+ rubygems_version: 1.3.7
99
112
  signing_key:
100
113
  specification_version: 3
101
114
  summary: A simple Ruby wrapper for the CloudApp API. Uses HTTParty with a simple ActiveResource-like interface.
102
115
  test_files:
116
+ - test/helper/faking_setup.rb
117
+ - test/helper/methods.rb
103
118
  - test/helper.rb
104
- - test/test_cloudly.rb
119
+ - test/test_base.rb
120
+ - test/test_cloudapp_api.rb
data/test/test_cloudly.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestCloudAppAPI < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end