slaskis-fleakr 0.5.2 → 0.5.3

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/lib/fleakr.rb CHANGED
@@ -93,12 +93,17 @@ module Fleakr
93
93
  # Fleakr.api_key = 'ABC123'
94
94
  # Fleakr.user('the decapitator') # => #<Fleakr::Objects::User:0x692648 @username="the decapitator", @id="21775151@N06">
95
95
  # Fleakr.user('user@host.com') # => #<Fleakr::Objects::User:0x11f484c @username="bckspcr", @id="84481630@N00">
96
+ # Fleakr.user( 'http://www.flickr.com/photos/bckspcr/' ) # => #<Fleakr::Objects::User:0x12354a0 @username="bckspcr", @id="84481630@N00">
96
97
  #
97
98
  def self.user(user_data)
98
99
  begin
99
100
  Objects::User.find_by_username(user_data)
100
101
  rescue ApiError
101
- Objects::User.find_by_email(user_data)
102
+ begin
103
+ Objects::User.find_by_email(user_data)
104
+ rescue ApiError
105
+ Objects::User.find_by_url(user_data)
106
+ end
102
107
  end
103
108
  end
104
109
 
@@ -18,13 +18,32 @@ module Fleakr
18
18
 
19
19
  include Fleakr::Support::Object
20
20
 
21
- has_many :sets, :collections
21
+ attr_accessor :collections, :sets
22
22
 
23
- flickr_attribute :id, :title, :description
23
+ flickr_attribute :id, :title, :description, :iconlarge, :iconsmall
24
24
 
25
25
  find_all :by_collection_id, :call => 'collections.getTree', :path => "collections/collection:gt(0)"
26
26
  find_all :by_user_id, :call => 'collections.getTree', :path => 'collections/collection'
27
-
27
+
28
+ def initialize(document=nil)
29
+ self.populate_from(document) unless document.nil?
30
+ self.sets = document.search("//set").map{|s| Fleakr::Objects::Set.new(s)} || []
31
+ self.collections = recurse_collections(document.search("//collection"))
32
+ end
33
+
34
+ private
35
+
36
+ def recurse_collections(search)
37
+ collections = Array.new
38
+ search.each do |e|
39
+ c = self.class.new(e)
40
+ collections << c
41
+ c.sets = e.search("//set").map{|s| Fleakr::Objects::Set.new(s)} || []
42
+ c.collections = recurse_collections(e.search("//collection"))
43
+ end
44
+ return collections
45
+ end
46
+
28
47
  end
29
48
  end
30
49
  end
@@ -44,7 +44,7 @@ module Fleakr
44
44
 
45
45
  include Fleakr::Support::Object
46
46
 
47
- flickr_attribute :id, :from => 'user@nsid'
47
+ flickr_attribute :id, :from => ['user@id','user@nsid']
48
48
  flickr_attribute :username, :location
49
49
  flickr_attribute :name, :from => 'person/realname'
50
50
  flickr_attribute :photos_url, :from => 'person/photosurl'
@@ -60,6 +60,7 @@ module Fleakr
60
60
  find_one :by_username, :call => 'people.findByUsername'
61
61
  find_one :by_email, :using => :find_email, :call => 'people.findByEmail'
62
62
  find_one :by_id, :using => :user_id, :call => 'people.getInfo'
63
+ find_one :by_url, :using => :url, :call => 'urls.lookupUser'
63
64
 
64
65
  lazily_load :name, :photos_url, :profile_url, :photos_count, :location, :with => :load_info
65
66
  lazily_load :icon_server, :icon_farm, :pro, :admin, :with => :load_info
@@ -90,6 +91,18 @@ module Fleakr
90
91
  self.populate_from(response.body)
91
92
  end
92
93
 
94
+ def collection_by_id(id)
95
+ response = Fleakr::Api::MethodRequest.with_response!('collections.getTree', :user_id => self.id)
96
+ doc = response.body
97
+ (doc/"//collection").map do |e|
98
+ if e[:id] =~ /^\d*-?#{id}$/
99
+ Collection.new(e)
100
+ else
101
+ nil
102
+ end
103
+ end.compact!.first
104
+ end
105
+
93
106
  end
94
107
  end
95
108
  end
@@ -39,9 +39,6 @@ module Fleakr
39
39
  class_eval <<-CODE
40
40
  def self.find_all_#{condition}(value, options = {})
41
41
  options.merge!(:#{attribute} => value)
42
-
43
- logger.info("Ran XPath on response: #{options[:path]}")
44
-
45
42
  response = Fleakr::Api::MethodRequest.with_response!('#{options[:call]}', options)
46
43
  (response.body/'rsp/#{options[:path]}').map {|e| #{target_class}.new(e) }
47
44
  end
@@ -3,7 +3,7 @@ module Fleakr
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 5
6
- TINY = 1
6
+ TINY = 3
7
7
 
8
8
  def self.to_s
9
9
  [MAJOR, MINOR, TINY].join('.')
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Fleakr::Objects
4
+ class CollectionTest < Test::Unit::TestCase
5
+
6
+ should_have_many :sets, :collections
7
+
8
+ context "The Collection class" do
9
+
10
+ should_find_one :collection, :by => :collection_id, :call => 'collections.getTree', :path => 'rsp/collections/collection'
11
+
12
+ end
13
+
14
+ context "An instance of the Collection class" do
15
+
16
+ context "when populating from an XML document" do
17
+ setup do
18
+ @object = Collection.new(Hpricot.XML(read_fixture('collections.getTree')).at('rsp/collections/collection'))
19
+ end
20
+
21
+ should_have_a_value_for :id => '34762917-72157617429277370'
22
+ should_have_a_value_for :title => 'test2'
23
+ should_have_a_value_for :description => ''
24
+
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slaskis-fleakr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Reagan
8
- - "Robert Sk\xC3\xB6ld"
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
11
 
13
- date: 2009-07-16 00:00:00 -07:00
12
+ date: 2009-08-19 00:00:00 -07:00
14
13
  default_executable:
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
@@ -72,9 +71,9 @@ files:
72
71
  - lib/fleakr/core_ext.rb
73
72
  - lib/fleakr/objects
74
73
  - lib/fleakr/objects/authentication_token.rb
74
+ - lib/fleakr/objects/collection.rb
75
75
  - lib/fleakr/objects/comment.rb
76
76
  - lib/fleakr/objects/contact.rb
77
- - lib/fleakr/objects/collection.rb
78
77
  - lib/fleakr/objects/error.rb
79
78
  - lib/fleakr/objects/group.rb
80
79
  - lib/fleakr/objects/image.rb
@@ -133,6 +132,7 @@ files:
133
132
  - test/unit/fleakr/core_ext/true_class_test.rb
134
133
  - test/unit/fleakr/objects
135
134
  - test/unit/fleakr/objects/authentication_token_test.rb
135
+ - test/unit/fleakr/objects/collection_test.rb
136
136
  - test/unit/fleakr/objects/comment_test.rb
137
137
  - test/unit/fleakr/objects/contact_test.rb
138
138
  - test/unit/fleakr/objects/error_test.rb
@@ -148,8 +148,9 @@ files:
148
148
  - test/unit/fleakr/support/attribute_test.rb
149
149
  - test/unit/fleakr/support/object_test.rb
150
150
  - test/unit/fleakr_test.rb
151
- has_rdoc: true
151
+ has_rdoc: false
152
152
  homepage: http://sneaq.net
153
+ licenses:
153
154
  post_install_message:
154
155
  rdoc_options:
155
156
  - --main
@@ -171,9 +172,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
172
  requirements: []
172
173
 
173
174
  rubyforge_project:
174
- rubygems_version: 1.2.0
175
+ rubygems_version: 1.3.5
175
176
  signing_key:
176
- specification_version: 2
177
+ specification_version: 3
177
178
  summary: A small, yet powerful, gem to interface with Flickr photostreams
178
179
  test_files: []
179
180