cloudapp_api 0.0.3 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore DELETED
@@ -1,23 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
- .autotest
21
-
22
- ## PROJECT::SPECIFIC
23
- test/test_config.yml
@@ -1,34 +0,0 @@
1
- module HTTParty
2
-
3
- module ClassMethods
4
- def digest_auth(u, p)
5
- default_options[:digest_auth] = {:username => u, :password => p}
6
- end
7
- end
8
-
9
- class Request
10
-
11
- private
12
-
13
- def credentials
14
- options[:basic_auth] || options[:digest_auth]
15
- end
16
-
17
- def username
18
- credentials[:username]
19
- end
20
-
21
- def password
22
- credentials[:password]
23
- end
24
-
25
- def setup_digest_auth
26
- res = http.head(uri.request_uri, options[:headers])
27
- if res['www-authenticate'] != nil && res['www-authenticate'].length > 0
28
- @raw_request.digest_auth(username, password, res)
29
- end
30
- end
31
-
32
- end
33
-
34
- end
@@ -1,35 +0,0 @@
1
- require 'digest/md5'
2
- require 'net/http'
3
-
4
- module Net
5
- module HTTPHeader
6
- def digest_auth(user, password, response)
7
- response['www-authenticate'] =~ /^(\w+) (.*)/
8
-
9
- params = {}
10
- $2.gsub(/(\w+)="(.*?)"/) { params[$1] = $2 }
11
- params.merge!("cnonce" => Digest::MD5.hexdigest("%x" % (Time.now.to_i + rand(65535))))
12
-
13
- a_1 = Digest::MD5.hexdigest("#{user}:#{params['realm']}:#{password}")
14
- a_2 = Digest::MD5.hexdigest("#{@method}:#{@path}")
15
-
16
- request_digest = Digest::MD5.hexdigest(
17
- [a_1, params['nonce'], "0", params['cnonce'], params['qop'], a_2].join(":")
18
- )
19
-
20
- header = [
21
- %Q(Digest username="#{user}"),
22
- %Q(realm="#{params['realm']}"),
23
- %Q(qop="#{params['qop']}"),
24
- %Q(uri="#{@path}"),
25
- %Q(nonce="#{params['nonce']}"),
26
- %Q(nc="0"),
27
- %Q(cnonce="#{params['cnonce']}"),
28
- %Q(opaque="#{params['opaque']}"),
29
- %Q(response="#{request_digest}")
30
- ]
31
-
32
- @header['Authorization'] = header
33
- end
34
- end
35
- end
data/test/helper.rb DELETED
@@ -1,24 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
- require 'treetop'
5
- require 'yaml'
6
-
7
- TEST_DIR = File.join(File.dirname(__FILE__))
8
-
9
- $LOAD_PATH.unshift(File.join(TEST_DIR, '..', 'lib'))
10
- $LOAD_PATH.unshift(File.dirname(__FILE__))
11
- require 'helper/faking_setup'
12
- require 'cloudapp_api'
13
-
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
-
24
- end
@@ -1,15 +0,0 @@
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
@@ -1,81 +0,0 @@
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/test_base.rb DELETED
@@ -1,19 +0,0 @@
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
@@ -1,38 +0,0 @@
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