slaskis-fleakr 0.5.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.
Files changed (82) hide show
  1. data/README.rdoc +350 -0
  2. data/Rakefile +41 -0
  3. data/lib/fleakr.rb +164 -0
  4. data/lib/fleakr/api.rb +8 -0
  5. data/lib/fleakr/api/file_parameter.rb +47 -0
  6. data/lib/fleakr/api/method_request.rb +66 -0
  7. data/lib/fleakr/api/option.rb +175 -0
  8. data/lib/fleakr/api/parameter.rb +35 -0
  9. data/lib/fleakr/api/parameter_list.rb +97 -0
  10. data/lib/fleakr/api/response.rb +35 -0
  11. data/lib/fleakr/api/upload_request.rb +75 -0
  12. data/lib/fleakr/api/value_parameter.rb +36 -0
  13. data/lib/fleakr/core_ext.rb +3 -0
  14. data/lib/fleakr/core_ext/false_class.rb +7 -0
  15. data/lib/fleakr/core_ext/hash.rb +22 -0
  16. data/lib/fleakr/core_ext/true_class.rb +7 -0
  17. data/lib/fleakr/objects.rb +13 -0
  18. data/lib/fleakr/objects/authentication_token.rb +60 -0
  19. data/lib/fleakr/objects/comment.rb +49 -0
  20. data/lib/fleakr/objects/contact.rb +31 -0
  21. data/lib/fleakr/objects/error.rb +22 -0
  22. data/lib/fleakr/objects/group.rb +36 -0
  23. data/lib/fleakr/objects/image.rb +50 -0
  24. data/lib/fleakr/objects/photo.rb +147 -0
  25. data/lib/fleakr/objects/photo_context.rb +49 -0
  26. data/lib/fleakr/objects/search.rb +30 -0
  27. data/lib/fleakr/objects/set.rb +51 -0
  28. data/lib/fleakr/objects/tag.rb +56 -0
  29. data/lib/fleakr/objects/user.rb +95 -0
  30. data/lib/fleakr/support.rb +2 -0
  31. data/lib/fleakr/support/attribute.rb +46 -0
  32. data/lib/fleakr/support/object.rb +112 -0
  33. data/lib/fleakr/version.rb +13 -0
  34. data/test/fixtures/auth.checkToken.xml +8 -0
  35. data/test/fixtures/auth.getFullToken.xml +8 -0
  36. data/test/fixtures/auth.getToken.xml +8 -0
  37. data/test/fixtures/contacts.getPublicList.xml +7 -0
  38. data/test/fixtures/groups.pools.getPhotos.xml +7 -0
  39. data/test/fixtures/people.findByEmail.xml +6 -0
  40. data/test/fixtures/people.findByUsername.xml +6 -0
  41. data/test/fixtures/people.getInfo.xml +18 -0
  42. data/test/fixtures/people.getPublicGroups.xml +7 -0
  43. data/test/fixtures/people.getPublicPhotos.xml +7 -0
  44. data/test/fixtures/photos.comments.getList.xml +7 -0
  45. data/test/fixtures/photos.getContext.xml +6 -0
  46. data/test/fixtures/photos.getInfo.xml +20 -0
  47. data/test/fixtures/photos.getSizes.xml +10 -0
  48. data/test/fixtures/photos.search.xml +7 -0
  49. data/test/fixtures/photosets.comments.getList.xml +7 -0
  50. data/test/fixtures/photosets.getList.xml +13 -0
  51. data/test/fixtures/photosets.getPhotos.xml +7 -0
  52. data/test/fixtures/tags.getListPhoto.xml +9 -0
  53. data/test/fixtures/tags.getListUser.xml +10 -0
  54. data/test/fixtures/tags.getRelated.xml +9 -0
  55. data/test/test_helper.rb +141 -0
  56. data/test/unit/fleakr/api/file_parameter_test.rb +63 -0
  57. data/test/unit/fleakr/api/method_request_test.rb +94 -0
  58. data/test/unit/fleakr/api/option_test.rb +179 -0
  59. data/test/unit/fleakr/api/parameter_list_test.rb +176 -0
  60. data/test/unit/fleakr/api/parameter_test.rb +34 -0
  61. data/test/unit/fleakr/api/response_test.rb +49 -0
  62. data/test/unit/fleakr/api/upload_request_test.rb +149 -0
  63. data/test/unit/fleakr/api/value_parameter_test.rb +41 -0
  64. data/test/unit/fleakr/core_ext/false_class_test.rb +13 -0
  65. data/test/unit/fleakr/core_ext/hash_test.rb +32 -0
  66. data/test/unit/fleakr/core_ext/true_class_test.rb +13 -0
  67. data/test/unit/fleakr/objects/authentication_token_test.rb +61 -0
  68. data/test/unit/fleakr/objects/comment_test.rb +66 -0
  69. data/test/unit/fleakr/objects/contact_test.rb +61 -0
  70. data/test/unit/fleakr/objects/error_test.rb +21 -0
  71. data/test/unit/fleakr/objects/group_test.rb +46 -0
  72. data/test/unit/fleakr/objects/image_test.rb +81 -0
  73. data/test/unit/fleakr/objects/photo_context_test.rb +80 -0
  74. data/test/unit/fleakr/objects/photo_test.rb +246 -0
  75. data/test/unit/fleakr/objects/search_test.rb +74 -0
  76. data/test/unit/fleakr/objects/set_test.rb +82 -0
  77. data/test/unit/fleakr/objects/tag_test.rb +98 -0
  78. data/test/unit/fleakr/objects/user_test.rb +91 -0
  79. data/test/unit/fleakr/support/attribute_test.rb +126 -0
  80. data/test/unit/fleakr/support/object_test.rb +129 -0
  81. data/test/unit/fleakr_test.rb +171 -0
  82. metadata +175 -0
@@ -0,0 +1,129 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ class EmptyObject
4
+ include Fleakr::Support::Object
5
+ end
6
+
7
+ class FlickrObject
8
+
9
+ include Fleakr::Support::Object
10
+
11
+ flickr_attribute :name
12
+ flickr_attribute :description, :from => 'desc'
13
+ flickr_attribute :id, :from => '@nsid'
14
+ flickr_attribute :photoset_id, :from => 'photoset@id'
15
+ flickr_attribute :tag, :category
16
+
17
+ find_one :by_id, :call => 'people.getInfo'
18
+
19
+ end
20
+
21
+ module Fleakr
22
+ class ObjectTest < Test::Unit::TestCase
23
+
24
+ context "A class method provided by the Flickr::Object module" do
25
+
26
+ should "have an empty list of attributes if none are supplied" do
27
+ EmptyObject.attributes.should == []
28
+ end
29
+
30
+ should "know the names of all its attributes" do
31
+ FlickrObject.attributes.map {|a| a.name.to_s }.should == %w(name description id photoset_id tag category)
32
+ end
33
+
34
+ should "be able to find by ID" do
35
+ id = 1
36
+ flickr_object = stub()
37
+
38
+ response = mock_request_cycle :for => 'people.getInfo', :with => {:id => id}
39
+ FlickrObject.expects(:new).with(response.body).returns(flickr_object)
40
+
41
+ FlickrObject.find_by_id(id).should == flickr_object
42
+ end
43
+
44
+ should "be able to pass parameters to the :find_by_id method" do
45
+ id = 1
46
+ params = {:authenticate? => true}
47
+ flickr_object = stub()
48
+
49
+ response = mock_request_cycle :for => 'people.getInfo', :with => {:id => id, :authenticate? => true}
50
+ FlickrObject.expects(:new).with(response.body).returns(flickr_object)
51
+
52
+ FlickrObject.find_by_id(id, params).should == flickr_object
53
+ end
54
+
55
+ end
56
+
57
+ context "An instance method provided by the Flickr::Object module" do
58
+
59
+ should "have default reader methods" do
60
+ [:name, :description, :id, :photoset_id, :tag, :category].each do |method_name|
61
+ FlickrObject.new.respond_to?(method_name).should == true
62
+ end
63
+ end
64
+
65
+ context "when populating data from an XML document" do
66
+ setup do
67
+ xml = <<-XML
68
+ <name>Fleakr</name>
69
+ <desc>Awesome</desc>
70
+ <photoset id="1" />
71
+ <tag>Tag</tag>
72
+ <category>Category</category>
73
+ XML
74
+
75
+ @object = FlickrObject.new
76
+ @object.populate_from(Hpricot.XML(xml))
77
+ end
78
+
79
+ should "have the correct value for :name" do
80
+ @object.name.should == 'Fleakr'
81
+ end
82
+
83
+ should "have the correct value for :description" do
84
+ @object.description.should == 'Awesome'
85
+ end
86
+
87
+ should "have the correct value for :photoset_id" do
88
+ @object.photoset_id.should == '1'
89
+ end
90
+
91
+ should "have the correct value for :id" do
92
+ document = Hpricot.XML('<object nsid="1" />').at('object')
93
+ @object.populate_from(document)
94
+
95
+ @object.id.should == '1'
96
+ end
97
+
98
+ should "have the correct value for :tag" do
99
+ @object.tag.should == 'Tag'
100
+ end
101
+
102
+ should "have the correct value for :category" do
103
+ @object.category.should == 'Category'
104
+ end
105
+ end
106
+
107
+ should "populate its data from an XML document when initializing" do
108
+ document = stub()
109
+ FlickrObject.any_instance.expects(:populate_from).with(document)
110
+
111
+ FlickrObject.new(document)
112
+ end
113
+
114
+ should "not attempt to populate itself from an XML document if one is not available" do
115
+ FlickrObject.any_instance.expects(:populate_from).never
116
+ FlickrObject.new
117
+ end
118
+
119
+ should "not overwrite existing attributes when pulling in a partial new XML document" do
120
+ object = FlickrObject.new(Hpricot.XML('<name>Fleakr</name>'))
121
+ object.populate_from(Hpricot.XML('<desc>Awesome</desc>'))
122
+
123
+ object.name.should == 'Fleakr'
124
+ end
125
+
126
+ end
127
+
128
+ end
129
+ end
@@ -0,0 +1,171 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class FleakrTest < Test::Unit::TestCase
4
+
5
+ context "The Fleakr module" do
6
+
7
+ [:api_key, :shared_secret, :mini_token, :auth_token].each do |attribute|
8
+ should "be able to set a value for :#{attribute}" do
9
+ value = 'value'
10
+
11
+ Fleakr.send("#{attribute}=".to_sym, value)
12
+ Fleakr.send(attribute).should == value
13
+ end
14
+ end
15
+
16
+ should "provide a means to find a user by his username" do
17
+ user = stub()
18
+ Fleakr::Objects::User.expects(:find_by_username).with('username').returns(user)
19
+ Fleakr.user('username').should == user
20
+ end
21
+
22
+ should "fall back to finding a user by email if finding by username fails" do
23
+ user = stub()
24
+ email = 'user@host.com'
25
+
26
+ Fleakr::Objects::User.stubs(:find_by_username).with(email).raises(Fleakr::ApiError)
27
+ Fleakr::Objects::User.expects(:find_by_email).with(email).returns(user)
28
+
29
+ Fleakr.user(email).should == user
30
+ end
31
+
32
+ should "be able to perform text searches" do
33
+ photos = [stub()]
34
+
35
+ Fleakr::Objects::Search.expects(:new).with(:text => 'foo').returns(stub(:results => photos))
36
+ Fleakr.search('foo').should == photos
37
+ end
38
+
39
+ should "be able to perform searches based on tags" do
40
+ Fleakr::Objects::Search.expects(:new).with(:tags => %w(one two)).returns(stub(:results => []))
41
+ Fleakr.search(:tags => %w(one two))
42
+ end
43
+
44
+ # TODO: refactor uploading tests?
45
+ should "be able to upload a collection of images" do
46
+ glob = '*.jpg'
47
+ filenames = %w(one.jpg two.jpg)
48
+
49
+ Dir.expects(:[]).with(glob).returns(filenames)
50
+
51
+ Fleakr::Objects::Photo.expects(:upload).with('one.jpg', {})
52
+ Fleakr::Objects::Photo.expects(:upload).with('two.jpg', {})
53
+
54
+ Fleakr.upload(glob)
55
+ end
56
+
57
+ should "return recently uploaded photos" do
58
+ filename = '/path/to/image.jpg'
59
+ new_image = stub()
60
+
61
+ Dir.expects(:[]).with(filename).returns([filename])
62
+ Fleakr::Objects::Photo.expects(:upload).with(filename, {}).returns(new_image)
63
+
64
+ Fleakr.upload(filename).should == [new_image]
65
+ end
66
+
67
+ should "be able to pass options for the uploaded files" do
68
+ filename = '/path/to/image.jpg'
69
+ new_image = stub()
70
+
71
+ Dir.expects(:[]).with(filename).returns([filename])
72
+ Fleakr::Objects::Photo.expects(:upload).with(filename, :title => 'bop bip').returns(new_image)
73
+
74
+ Fleakr.upload(filename, :title => 'bop bip').should == [new_image]
75
+ end
76
+
77
+ should "be able to reset the cached token" do
78
+ @token = stub()
79
+ Fleakr.expects(:auth_token).with().at_least_once.returns('abc123')
80
+ Fleakr::Objects::AuthenticationToken.expects(:from_auth_token).with('abc123').times(2).returns(@token)
81
+ Fleakr.token # once
82
+ Fleakr.reset_token
83
+ Fleakr.token # twice
84
+ end
85
+
86
+ should "not have a token by default" do
87
+ Fleakr.expects(:mini_token).with().returns(nil)
88
+ Fleakr.expects(:auth_token).with().returns(nil)
89
+ Fleakr.expects(:frob).with().returns(nil)
90
+
91
+ Fleakr.token.should be(nil)
92
+ end
93
+
94
+ [:mini_token, :auth_token, :frob].each do |attribute|
95
+ should "reset_token when :#{attribute} is set" do
96
+ Fleakr.expects(:reset_token).with().at_least_once
97
+ Fleakr.send("#{attribute}=".to_sym, 'value')
98
+ end
99
+ end
100
+
101
+ context "when generating an AuthenticationToken from an auth_token string" do
102
+
103
+ setup do
104
+ @token = stub()
105
+
106
+ Fleakr.expects(:auth_token).with().at_least_once.returns('abc123')
107
+ Fleakr::Objects::AuthenticationToken.expects(:from_auth_token).with('abc123').returns(@token)
108
+ end
109
+
110
+ # Make sure to clear the cache
111
+ teardown { Fleakr.auth_token = nil }
112
+
113
+ should "return the token" do
114
+ Fleakr.token.should == @token
115
+ end
116
+
117
+ should "cache the result" do
118
+ 2.times { Fleakr.token }
119
+ end
120
+
121
+ end
122
+
123
+ context "when generating an AuthenticationToken from a frob string" do
124
+
125
+ setup do
126
+ @token = stub()
127
+
128
+ Fleakr.expects(:auth_token).with().at_least_once.returns(nil)
129
+ Fleakr.expects(:frob).with().at_least_once.returns('abc123')
130
+ Fleakr::Objects::AuthenticationToken.expects(:from_frob).with('abc123').returns(@token)
131
+ end
132
+
133
+ # Make sure to clear the cache
134
+ teardown { Fleakr.frob = nil }
135
+
136
+ should "return the token" do
137
+ Fleakr.token.should == @token
138
+ end
139
+
140
+ should "cache the result" do
141
+ 2.times { Fleakr.token }
142
+ end
143
+
144
+ end
145
+
146
+ context "when generating an AuthenticationToken from a mini_token string" do
147
+
148
+ setup do
149
+ @token = stub()
150
+
151
+ Fleakr.expects(:auth_token).with().at_least_once.returns(nil)
152
+ Fleakr.expects(:mini_token).with().at_least_once.returns('123-123-123')
153
+ Fleakr::Objects::AuthenticationToken.expects(:from_mini_token).with('123-123-123').returns(@token)
154
+ end
155
+
156
+ # Make sure to clear the cache
157
+ teardown { Fleakr.mini_token = nil }
158
+
159
+ should "return the token" do
160
+ Fleakr.token.should == @token
161
+ end
162
+
163
+ should "cache the result" do
164
+ 2.times { Fleakr.token }
165
+ end
166
+
167
+ end
168
+
169
+ end
170
+
171
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slaskis-fleakr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Patrick Reagan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-13 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hpricot
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 0.8.1
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: "2.0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: loggable
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.2.0
44
+ version:
45
+ description:
46
+ email: reaganpr@gmail.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - README.rdoc
53
+ files:
54
+ - README.rdoc
55
+ - Rakefile
56
+ - lib/fleakr
57
+ - lib/fleakr/api
58
+ - lib/fleakr/api/file_parameter.rb
59
+ - lib/fleakr/api/method_request.rb
60
+ - lib/fleakr/api/option.rb
61
+ - lib/fleakr/api/parameter.rb
62
+ - lib/fleakr/api/parameter_list.rb
63
+ - lib/fleakr/api/response.rb
64
+ - lib/fleakr/api/upload_request.rb
65
+ - lib/fleakr/api/value_parameter.rb
66
+ - lib/fleakr/api.rb
67
+ - lib/fleakr/core_ext
68
+ - lib/fleakr/core_ext/false_class.rb
69
+ - lib/fleakr/core_ext/hash.rb
70
+ - lib/fleakr/core_ext/true_class.rb
71
+ - lib/fleakr/core_ext.rb
72
+ - lib/fleakr/objects
73
+ - lib/fleakr/objects/authentication_token.rb
74
+ - lib/fleakr/objects/comment.rb
75
+ - lib/fleakr/objects/contact.rb
76
+ - lib/fleakr/objects/error.rb
77
+ - lib/fleakr/objects/group.rb
78
+ - lib/fleakr/objects/image.rb
79
+ - lib/fleakr/objects/photo.rb
80
+ - lib/fleakr/objects/photo_context.rb
81
+ - lib/fleakr/objects/search.rb
82
+ - lib/fleakr/objects/set.rb
83
+ - lib/fleakr/objects/tag.rb
84
+ - lib/fleakr/objects/user.rb
85
+ - lib/fleakr/objects.rb
86
+ - lib/fleakr/support
87
+ - lib/fleakr/support/attribute.rb
88
+ - lib/fleakr/support/object.rb
89
+ - lib/fleakr/support.rb
90
+ - lib/fleakr/version.rb
91
+ - lib/fleakr.rb
92
+ - test/fixtures
93
+ - test/fixtures/auth.checkToken.xml
94
+ - test/fixtures/auth.getFullToken.xml
95
+ - test/fixtures/auth.getToken.xml
96
+ - test/fixtures/contacts.getPublicList.xml
97
+ - test/fixtures/groups.pools.getPhotos.xml
98
+ - test/fixtures/people.findByEmail.xml
99
+ - test/fixtures/people.findByUsername.xml
100
+ - test/fixtures/people.getInfo.xml
101
+ - test/fixtures/people.getPublicGroups.xml
102
+ - test/fixtures/people.getPublicPhotos.xml
103
+ - test/fixtures/photos.comments.getList.xml
104
+ - test/fixtures/photos.getContext.xml
105
+ - test/fixtures/photos.getInfo.xml
106
+ - test/fixtures/photos.getSizes.xml
107
+ - test/fixtures/photos.search.xml
108
+ - test/fixtures/photosets.comments.getList.xml
109
+ - test/fixtures/photosets.getList.xml
110
+ - test/fixtures/photosets.getPhotos.xml
111
+ - test/fixtures/tags.getListPhoto.xml
112
+ - test/fixtures/tags.getListUser.xml
113
+ - test/fixtures/tags.getRelated.xml
114
+ - test/test_helper.rb
115
+ - test/unit
116
+ - test/unit/fleakr
117
+ - test/unit/fleakr/api
118
+ - test/unit/fleakr/api/file_parameter_test.rb
119
+ - test/unit/fleakr/api/method_request_test.rb
120
+ - test/unit/fleakr/api/option_test.rb
121
+ - test/unit/fleakr/api/parameter_list_test.rb
122
+ - test/unit/fleakr/api/parameter_test.rb
123
+ - test/unit/fleakr/api/response_test.rb
124
+ - test/unit/fleakr/api/upload_request_test.rb
125
+ - test/unit/fleakr/api/value_parameter_test.rb
126
+ - test/unit/fleakr/core_ext
127
+ - test/unit/fleakr/core_ext/false_class_test.rb
128
+ - test/unit/fleakr/core_ext/hash_test.rb
129
+ - test/unit/fleakr/core_ext/true_class_test.rb
130
+ - test/unit/fleakr/objects
131
+ - test/unit/fleakr/objects/authentication_token_test.rb
132
+ - test/unit/fleakr/objects/comment_test.rb
133
+ - test/unit/fleakr/objects/contact_test.rb
134
+ - test/unit/fleakr/objects/error_test.rb
135
+ - test/unit/fleakr/objects/group_test.rb
136
+ - test/unit/fleakr/objects/image_test.rb
137
+ - test/unit/fleakr/objects/photo_context_test.rb
138
+ - test/unit/fleakr/objects/photo_test.rb
139
+ - test/unit/fleakr/objects/search_test.rb
140
+ - test/unit/fleakr/objects/set_test.rb
141
+ - test/unit/fleakr/objects/tag_test.rb
142
+ - test/unit/fleakr/objects/user_test.rb
143
+ - test/unit/fleakr/support
144
+ - test/unit/fleakr/support/attribute_test.rb
145
+ - test/unit/fleakr/support/object_test.rb
146
+ - test/unit/fleakr_test.rb
147
+ has_rdoc: true
148
+ homepage: http://sneaq.net
149
+ post_install_message:
150
+ rdoc_options:
151
+ - --main
152
+ - README.rdoc
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: "0"
160
+ version:
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: "0"
166
+ version:
167
+ requirements: []
168
+
169
+ rubyforge_project:
170
+ rubygems_version: 1.2.0
171
+ signing_key:
172
+ specification_version: 2
173
+ summary: A small, yet powerful, gem to interface with Flickr photostreams
174
+ test_files: []
175
+