chunky_baconfile 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.document +5 -0
  2. data/.gitignore +22 -0
  3. data/.yardoc/checksums +5 -0
  4. data/.yardoc/objects/ChunkyBaconfile.dat +0 -0
  5. data/.yardoc/objects/ChunkyBaconfile/Client.dat +0 -0
  6. data/.yardoc/objects/ChunkyBaconfile/Client/build_multipart_bodies_c.dat +0 -0
  7. data/.yardoc/objects/ChunkyBaconfile/Client/build_multipart_bodies_i.dat +0 -0
  8. data/.yardoc/objects/ChunkyBaconfile/Client/create_folder_i.dat +0 -0
  9. data/.yardoc/objects/ChunkyBaconfile/Client/delete_i.dat +0 -0
  10. data/.yardoc/objects/ChunkyBaconfile/Client/file_i.dat +0 -0
  11. data/.yardoc/objects/ChunkyBaconfile/Client/folder_i.dat +0 -0
  12. data/.yardoc/objects/ChunkyBaconfile/Client/initialize_i.dat +0 -0
  13. data/.yardoc/objects/ChunkyBaconfile/Client/mime_type_c.dat +0 -0
  14. data/.yardoc/objects/ChunkyBaconfile/Client/mime_type_i.dat +0 -0
  15. data/.yardoc/objects/ChunkyBaconfile/Client/public_i.dat +0 -0
  16. data/.yardoc/objects/ChunkyBaconfile/Client/upload_file_i.dat +0 -0
  17. data/.yardoc/objects/ChunkyBaconfile/Client/username_3D_i.dat +0 -0
  18. data/.yardoc/objects/ChunkyBaconfile/Client/username_i.dat +0 -0
  19. data/.yardoc/objects/ChunkyBaconfile/Client/verify_i.dat +0 -0
  20. data/.yardoc/objects/ChunkyBaconfile/FileInfo.dat +0 -0
  21. data/.yardoc/objects/ChunkyBaconfile/FileInfo/image_3F_i.dat +0 -0
  22. data/.yardoc/objects/ChunkyBaconfile/FileInfo/size_i.dat +0 -0
  23. data/.yardoc/objects/ChunkyBaconfile/FileInfo/time_modified_i.dat +0 -0
  24. data/.yardoc/objects/ChunkyBaconfile/FileInfo/type_i.dat +0 -0
  25. data/.yardoc/objects/ChunkyBaconfile/public_c.dat +0 -0
  26. data/.yardoc/objects/root.dat +0 -0
  27. data/.yardoc/proxy_types +0 -0
  28. data/LICENSE +20 -0
  29. data/README.md +47 -0
  30. data/Rakefile +60 -0
  31. data/VERSION +1 -0
  32. data/changelog.md +5 -0
  33. data/lib/chunky_baconfile.rb +24 -0
  34. data/lib/chunky_baconfile/client.rb +121 -0
  35. data/lib/chunky_baconfile/file_info.rb +19 -0
  36. data/test/fixtures/bacon.json +242 -0
  37. data/test/fixtures/cat.jpg +0 -0
  38. data/test/fixtures/cat.jpg.json +20 -0
  39. data/test/fixtures/delete.json +1 -0
  40. data/test/fixtures/error.json +1 -0
  41. data/test/fixtures/new_file.json +20 -0
  42. data/test/fixtures/new_folder.json +20 -0
  43. data/test/fixtures/public.json +402 -0
  44. data/test/fixtures/verify.json +1 -0
  45. data/test/helper.rb +43 -0
  46. data/test/test_chunky_baconfile.rb +87 -0
  47. metadata +171 -0
@@ -0,0 +1 @@
1
+ {"user": {"username": "pengwynn", "timezone": "America/Chicago", "id": 947}}
@@ -0,0 +1,43 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'fakeweb'
5
+ gem 'jnunemaker-matchy', '0.4.0'
6
+ require 'matchy'
7
+
8
+ FakeWeb.allow_net_connect = false
9
+
10
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
11
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
12
+ require 'chunky_baconfile'
13
+
14
+ class Test::Unit::TestCase
15
+ end
16
+
17
+ def baconfile_url(url)
18
+ url =~ /^http/ ? url : "http://baconfile.com#{url}"
19
+ end
20
+
21
+ def fixture_file(filename)
22
+ return '' if filename == ''
23
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
24
+ File.read(file_path)
25
+ end
26
+
27
+ def binary_file_fixture(filename)
28
+ File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
29
+ end
30
+
31
+ def stub_get(url, filename, options={})
32
+ opts = {:body => fixture_file(filename)}.merge(options)
33
+
34
+ FakeWeb.register_uri(:get, baconfile_url(url), opts)
35
+ end
36
+
37
+ def stub_post(url, filename)
38
+ FakeWeb.register_uri(:post, baconfile_url(url), :body => fixture_file(filename))
39
+ end
40
+
41
+ def stub_delete(url, filename)
42
+ FakeWeb.register_uri(:delete, baconfile_url(url), :body => fixture_file(filename))
43
+ end
@@ -0,0 +1,87 @@
1
+ require 'helper'
2
+
3
+ class TestChunkyBaconfile < Test::Unit::TestCase
4
+
5
+ context "when not supplying a username" do
6
+
7
+ should "return a list of most recent public files" do
8
+ stub_get("http://baconfile.com/public.json", "public.json")
9
+ items = ChunkyBaconfile.public
10
+ items.size.should == 20
11
+ items.first.size.should == 54462
12
+ items.first.description.should == 'GPS on Lake Tahoe'
13
+ items.first.user.username.should == 'pengwynn'
14
+ end
15
+ end
16
+
17
+
18
+ context "when unauthenticated" do
19
+
20
+ setup do
21
+ @bacon = ChunkyBaconfile::Client.new("leah")
22
+ end
23
+
24
+ should "return items in a folder" do
25
+ stub_get("http://baconfile.com/leah/bacon.json", "bacon.json")
26
+ items = @bacon.folder("bacon")
27
+ items.size.should == 12
28
+ items.first.size.should == 84295
29
+ items.first.path.should == 'leah/bacon/bacon-comic.gif'
30
+ items.first.user.username.should == 'leah'
31
+ end
32
+
33
+ should "return info about a file" do
34
+ stub_get("http://baconfile.com/leah/bacon/cat.jpg.json", "cat.jpg.json")
35
+ file = @bacon.file("bacon", "cat.jpg.json")
36
+ file.size.should == 39368
37
+ file.permalink.should == "http://baconfile.com/leah/cat.jpg/"
38
+ file.description.should == "die in a fire!"
39
+ file.time_modified.should == Time.at(1236391578)
40
+ end
41
+
42
+ should "return a list of most recent public files" do
43
+ stub_get("http://baconfile.com/public.json", "public.json")
44
+ items = @bacon.public
45
+ items.size.should == 20
46
+ items.first.size.should == 54462
47
+ items.first.description.should == 'GPS on Lake Tahoe'
48
+ items.first.user.username.should == 'pengwynn'
49
+ end
50
+ end
51
+
52
+ context "when authenticated" do
53
+
54
+ setup do
55
+ @bacon = ChunkyBaconfile::Client.new("pengwynn", "test")
56
+ end
57
+
58
+ should "verify credentials" do
59
+ stub_get("http://pengwynn:test@baconfile.com/verify.json", "verify.json")
60
+ @bacon.verify.should == true
61
+ end
62
+
63
+ should "create a new folder" do
64
+ stub_post("http://pengwynn:test@baconfile.com/pengwynn.json", "new_folder.json")
65
+ folder = @bacon.create_folder("test_folder")
66
+ folder.url.should == '/pengwynn/test_folder/'
67
+ folder.time_modified.should == Time.at(1262753640)
68
+ folder.size.should be_nil
69
+ end
70
+
71
+ should "create a new file" do
72
+ stub_post("http://pengwynn:test@baconfile.com/pengwynn.json", "new_file.json")
73
+ file = @bacon.upload_file(File.new(binary_file_fixture('cat.jpg')))
74
+ file.tiny_url.should == 'http://tinyb.cn/1qm'
75
+ file.time_modified.should == Time.at(1262755171)
76
+ file.size.should == 7271
77
+ end
78
+
79
+ should "delete a file or a folder" do
80
+ stub_delete("http://pengwynn:test@baconfile.com/pengwynn/test_folder.json", "delete.json")
81
+ @bacon.delete("test_folder").key?(:success).should == true
82
+ end
83
+
84
+ end
85
+
86
+
87
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chunky_baconfile
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Wynn Netherland
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-07 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hashie
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 0.1.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: httparty
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.5
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: shoulda
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.10.1
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: jnunemaker-matchy
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "="
52
+ - !ruby/object:Gem::Version
53
+ version: 0.4.0
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
57
+ type: :development
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "="
62
+ - !ruby/object:Gem::Version
63
+ version: 0.9.4
64
+ version:
65
+ - !ruby/object:Gem::Dependency
66
+ name: fakeweb
67
+ type: :development
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 1.2.5
74
+ version:
75
+ - !ruby/object:Gem::Dependency
76
+ name: yard
77
+ type: :development
78
+ version_requirement:
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ description: Tasty wrapper for the Baconfile API
86
+ email: wynn.netherland@gmail.com
87
+ executables: []
88
+
89
+ extensions: []
90
+
91
+ extra_rdoc_files:
92
+ - LICENSE
93
+ - README.md
94
+ files:
95
+ - .document
96
+ - .gitignore
97
+ - .yardoc/checksums
98
+ - .yardoc/objects/ChunkyBaconfile.dat
99
+ - .yardoc/objects/ChunkyBaconfile/Client.dat
100
+ - .yardoc/objects/ChunkyBaconfile/Client/build_multipart_bodies_c.dat
101
+ - .yardoc/objects/ChunkyBaconfile/Client/build_multipart_bodies_i.dat
102
+ - .yardoc/objects/ChunkyBaconfile/Client/create_folder_i.dat
103
+ - .yardoc/objects/ChunkyBaconfile/Client/delete_i.dat
104
+ - .yardoc/objects/ChunkyBaconfile/Client/file_i.dat
105
+ - .yardoc/objects/ChunkyBaconfile/Client/folder_i.dat
106
+ - .yardoc/objects/ChunkyBaconfile/Client/initialize_i.dat
107
+ - .yardoc/objects/ChunkyBaconfile/Client/mime_type_c.dat
108
+ - .yardoc/objects/ChunkyBaconfile/Client/mime_type_i.dat
109
+ - .yardoc/objects/ChunkyBaconfile/Client/public_i.dat
110
+ - .yardoc/objects/ChunkyBaconfile/Client/upload_file_i.dat
111
+ - .yardoc/objects/ChunkyBaconfile/Client/username_3D_i.dat
112
+ - .yardoc/objects/ChunkyBaconfile/Client/username_i.dat
113
+ - .yardoc/objects/ChunkyBaconfile/Client/verify_i.dat
114
+ - .yardoc/objects/ChunkyBaconfile/FileInfo.dat
115
+ - .yardoc/objects/ChunkyBaconfile/FileInfo/image_3F_i.dat
116
+ - .yardoc/objects/ChunkyBaconfile/FileInfo/size_i.dat
117
+ - .yardoc/objects/ChunkyBaconfile/FileInfo/time_modified_i.dat
118
+ - .yardoc/objects/ChunkyBaconfile/FileInfo/type_i.dat
119
+ - .yardoc/objects/ChunkyBaconfile/public_c.dat
120
+ - .yardoc/objects/root.dat
121
+ - .yardoc/proxy_types
122
+ - LICENSE
123
+ - README.md
124
+ - Rakefile
125
+ - VERSION
126
+ - changelog.md
127
+ - lib/chunky_baconfile.rb
128
+ - lib/chunky_baconfile/client.rb
129
+ - lib/chunky_baconfile/file_info.rb
130
+ - test/fixtures/bacon.json
131
+ - test/fixtures/cat.jpg
132
+ - test/fixtures/cat.jpg.json
133
+ - test/fixtures/delete.json
134
+ - test/fixtures/error.json
135
+ - test/fixtures/new_file.json
136
+ - test/fixtures/new_folder.json
137
+ - test/fixtures/public.json
138
+ - test/fixtures/verify.json
139
+ - test/helper.rb
140
+ - test/test_chunky_baconfile.rb
141
+ has_rdoc: true
142
+ homepage: http://github.com/pengwynn/chunky-baconfile
143
+ licenses: []
144
+
145
+ post_install_message:
146
+ rdoc_options:
147
+ - --charset=UTF-8
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: "0"
155
+ version:
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: "0"
161
+ version:
162
+ requirements: []
163
+
164
+ rubyforge_project:
165
+ rubygems_version: 1.3.5
166
+ signing_key:
167
+ specification_version: 3
168
+ summary: Tasty wrapper for the Baconfile API
169
+ test_files:
170
+ - test/helper.rb
171
+ - test/test_chunky_baconfile.rb