myflickr 0.1.1 → 0.1.2

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/History.txt CHANGED
@@ -1,3 +1,12 @@
1
+ == 0.1.2 2008-01-15
2
+
3
+ * Removed inbuilt memcached cache mechanism and replaced with my new gem `openuri_memcached`
4
+ * Cleaned manifest
5
+
6
+ == 0.1.1 2008-01-07
7
+
8
+ * Forgot to add cache.rb to the Manifest so the 0.1.0 gem was broken!
9
+
1
10
  == 0.1.0 2008-01-06
2
11
 
3
12
  * Added support for memcached so as to reduce the amount of queries actually sent to flickr
@@ -25,4 +34,4 @@
25
34
 
26
35
  == 0.0.1 2007-12-15
27
36
 
28
- * Initial release
37
+ * Initial release
data/Manifest.txt CHANGED
@@ -6,7 +6,6 @@ Rakefile
6
6
  config/hoe.rb
7
7
  config/requirements.rb
8
8
  lib/myflickr.rb
9
- lib/myflickr/cache.rb
10
9
  lib/myflickr/machine_tag.rb
11
10
  lib/myflickr/photo.rb
12
11
  lib/myflickr/query.rb
@@ -15,7 +14,6 @@ lib/myflickr/size.rb
15
14
  lib/myflickr/tag.rb
16
15
  lib/myflickr/version.rb
17
16
  lib/vendor/parallel/parallel.rb
18
- setup.rb
19
17
  spec/machine_tag_spec.rb
20
18
  spec/photo_spec.rb
21
19
  spec/query_spec.rb
data/config/hoe.rb CHANGED
@@ -59,7 +59,7 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
59
59
 
60
60
  # == Optional
61
61
  p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
62
- p.extra_deps = [['hpricot', '>= 0.6']] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
62
+ p.extra_deps = [['hpricot', '>= 0.6'], ['openuri_memcached']] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
63
63
 
64
64
  #p.spec_extras = {} # A hash of extra values to set in the gemspec.
65
65
 
@@ -1,54 +1,11 @@
1
- # All memcached references have been stolen straight
2
- # from the implementation in the `rubyweather` gem.
3
- # It just seemed too simple to roll in.
4
-
5
1
  module Myflickr
6
2
  class Query #:nodoc:
7
3
  def self.api_call(method, resource_uri='') #:nodoc:
8
4
  resource = "#{API_BASE}/?method=#{method}&api_key=#{API_KEY}&user_id=#{USER_ID}"
9
5
  resource += "&#{resource_uri}" unless resource_uri.empty?
10
6
 
11
- if cache?
12
- begin
13
- document = cache.get "#{USER_ID}:#{method}:#{resource_uri}"
14
- rescue
15
- puts "Querying: #{resource} [CACHE MISS]"
16
- document = false
17
- end
18
- end
19
-
20
- # No cached version exists
21
- unless document
22
- puts "Querying: #{resource}"
23
-
24
- # Query the resource
25
- document = open(resource).read
26
-
27
- # Write a new cache if available
28
- cache.set("#{USER_ID}:#{method}:#{resource_uri}", document, cache_validity) if cache?
29
- puts "[CACHING...]" if cache?
30
- end
31
-
32
7
  # Create a Hpricot object
33
- Hpricot.XML(document)
34
- end
35
-
36
- @cache = false
37
-
38
- # Turns on query caching.
39
- # See Myflickr::Query::Cache
40
- def self.enable_cache(enable = true)
41
- if enable
42
- extend Cache
43
- @cache = true
44
- else
45
- @cache = false
46
- end
47
- end
48
-
49
- # True if caching is enabled and at least one memcached server is alive, false otherwise.
50
- def self.cache?
51
- @cache and cache.active? and servers = cache.instance_variable_get(:@servers) and servers.collect{|s| s.alive?}.include?(true)
8
+ Hpricot.XML(open(resource).read)
52
9
  end
53
10
  end
54
11
  end
@@ -2,7 +2,7 @@ module Myflickr
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/myflickr.rb CHANGED
@@ -1,13 +1,15 @@
1
1
  require 'rubygems'
2
2
  require 'hpricot'
3
- require 'open-uri'
3
+ require 'openuri_memcached'
4
4
  require 'vendor/parallel/parallel'
5
5
 
6
+ OpenURI::Cache.enable!
7
+
6
8
  module Myflickr
7
9
  API_BASE = "http://api.flickr.com/services/rest"
8
10
  MAX_THREADS = 100
9
11
  end
10
12
 
11
- %w(query photo tag size set machine_tag cache version).each do |r|
13
+ %w(query photo tag size set machine_tag version).each do |r|
12
14
  require File.join(File.dirname(__FILE__), './myflickr/' + r)
13
15
  end
data/spec/query_spec.rb CHANGED
@@ -4,13 +4,4 @@ describe Query, "class" do
4
4
  it "should return a Hpricot Document object response" do
5
5
  Query.api_call('flickr.test.echo').should be_an_instance_of Hpricot::Doc
6
6
  end
7
- end
8
-
9
- describe Query, "with memcached caching for queries" do
10
- it "should return a Hpricot Document object response" do
11
- Query.enable_cache true
12
- Query.cache.servers = ["127.0.0.1:11211"]
13
- Query.api_call('flickr.test.echo').should be_an_instance_of Hpricot::Doc
14
- end
15
-
16
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myflickr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Schwarz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-01-07 00:00:00 +11:00
12
+ date: 2008-01-17 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -21,6 +21,15 @@ dependencies:
21
21
  - !ruby/object:Gem::Version
22
22
  version: "0.6"
23
23
  version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: openuri_memcached
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "0"
32
+ version:
24
33
  description: A flickr wrapper that removes all community aspects, only your data is returned
25
34
  email: ben@germanforblack.com
26
35
  executables: []
@@ -41,7 +50,6 @@ files:
41
50
  - config/hoe.rb
42
51
  - config/requirements.rb
43
52
  - lib/myflickr.rb
44
- - lib/myflickr/cache.rb
45
53
  - lib/myflickr/machine_tag.rb
46
54
  - lib/myflickr/photo.rb
47
55
  - lib/myflickr/query.rb
@@ -50,7 +58,6 @@ files:
50
58
  - lib/myflickr/tag.rb
51
59
  - lib/myflickr/version.rb
52
60
  - lib/vendor/parallel/parallel.rb
53
- - setup.rb
54
61
  - spec/machine_tag_spec.rb
55
62
  - spec/photo_spec.rb
56
63
  - spec/query_spec.rb
@@ -1,35 +0,0 @@
1
- # All memcached references have been stolen straight
2
- # from the implementation in the `rubyweather` gem.
3
- # It just seemed too simple to roll in.
4
-
5
- module Myflickr
6
- class Query
7
- module Cache
8
- attr_writer :cache_validity
9
- def cache
10
- @memcache ||= MemCache.new :namespace => "Myflickr"
11
- end
12
-
13
- def cache_validity
14
- # Default of 10 minutes
15
- @cache_validity || 60 * 10
16
- end
17
-
18
- private
19
- def self.extend_object(o)
20
- begin
21
- require 'memcache'
22
- rescue LoadError
23
- require 'rubygems'
24
- begin
25
- gem 'memcache-client', '~> 1.2.1'
26
- rescue Gem::LoadError
27
- gem 'Ruby-MemCache'
28
- end
29
- require 'memcache'
30
- end
31
- super
32
- end
33
- end
34
- end
35
- end