square-circle-triangle-flickr_mapper 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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Square Circle Triangle
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = flickr_mapper
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Square Circle Triangle. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "flickr_mapper"
8
+ gem.summary = "Flickr Mapper"
9
+ gem.email = "sct@sct.com.au"
10
+ gem.homepage = "http://github.com/square-circle-triangle/flickr_mapper"
11
+ gem.authors = ["Square Circle Triangle"]
12
+ gem.add_dependency "hpricot"
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'spec/rake/spectask'
21
+ Spec::Rake::SpecTask.new(:spec) do |spec|
22
+ spec.libs << 'lib' << 'spec'
23
+ spec.spec_files = FileList['spec/**/*_spec.rb']
24
+ end
25
+
26
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
27
+ spec.libs << 'lib' << 'spec'
28
+ spec.pattern = 'spec/**/*_spec.rb'
29
+ spec.rcov = true
30
+ end
31
+
32
+
33
+ task :default => :spec
34
+
35
+ require 'rake/rdoctask'
36
+ Rake::RDocTask.new do |rdoc|
37
+ if File.exist?('VERSION.yml')
38
+ config = YAML.load(File.read('VERSION.yml'))
39
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
40
+ else
41
+ version = ""
42
+ end
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "flickr_mapper #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
49
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -0,0 +1,54 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{flickr_mapper}
5
+ s.version = "0.1.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Square Circle Triangle"]
9
+ s.date = %q{2009-07-03}
10
+ s.email = %q{sct@sct.com.au}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "flickr_mapper.gemspec",
23
+ "lib/flickr_mapper.rb",
24
+ "lib/flickr_mapper/base.rb",
25
+ "lib/flickr_mapper/connection.rb",
26
+ "lib/flickr_mapper/parser.rb",
27
+ "lib/flickr_mapper/photo.rb",
28
+ "lib/flickr_mapper/photoset.rb",
29
+ "spec/flickr_mapper_spec.rb",
30
+ "spec/spec_helper.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/square-circle-triangle/flickr_mapper}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.3}
36
+ s.summary = %q{Flickr Mapper}
37
+ s.test_files = [
38
+ "spec/flickr_mapper_spec.rb",
39
+ "spec/spec_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<hpricot>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<hpricot>, [">= 0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<hpricot>, [">= 0"])
53
+ end
54
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'hpricot'
3
+ require 'open-uri'
4
+
5
+ module FlickrMapper
6
+ end
7
+
8
+ %w(base connection parser photoset photo).each{|r| require(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), r))}
@@ -0,0 +1,34 @@
1
+ module FlickrMapper
2
+
3
+ class Base
4
+ attr_accessor :connection
5
+
6
+ def initialize(id=nil)
7
+ @id = id unless id.nil?
8
+ @connection = FlickrMapper::Connection.new() #user_id??
9
+ end
10
+
11
+ # This can definitely be done in a cleaner way
12
+ def attributes
13
+ attributes = {}
14
+ self.instance_variables.each do |i|
15
+ meth = i.gsub("@","")
16
+ attributes[meth.to_sym] = self.send meth
17
+ end
18
+ attributes
19
+ end
20
+
21
+ def self.find(method, params={})
22
+ req = FlickrMapper::Connection.new #('2415296118')
23
+ raw = HpricotParser.parse(req.call(method, params))
24
+ self.parse(raw)
25
+ end
26
+
27
+ def request_raw(method, params={})
28
+ req = FlickrMapper::Connection.new #('2415296118')
29
+ HpricotParser.parse(req.call(method, params))
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,38 @@
1
+ module FlickrMapper
2
+
3
+ class Connection
4
+ API_BASE = "http://api.flickr.com/services/rest/"
5
+
6
+ @@api_key = "098c9bad4cdd2f0f1b587cb4c44017f8"
7
+ #cattr_accessor :api_key
8
+ attr_accessor :user_id
9
+
10
+ def initialize(user_id=nil) # 26327616@N00
11
+ @user_id = user_id unless user_id.nil?
12
+ end
13
+
14
+ def call(api_method, params)
15
+ raise "no api key has been set!" if @@api_key.nil?
16
+ dispatch(build_query(api_method, params))
17
+ end
18
+
19
+ private
20
+
21
+ def api_url
22
+ url = "#{API_BASE}?api_key=#{@@api_key}"
23
+ url << "&user_id=#{@user_id}" if @user_id
24
+ url
25
+ end
26
+
27
+ def dispatch(query)
28
+ response = open(query).read
29
+ return response
30
+ end
31
+
32
+ def build_query(api_method, params={})
33
+ optstr = { :method => api_method }.merge(params).map { |key, value| "#{key}=#{value}" }.join("&")
34
+ "#{api_url}&#{optstr}"
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,17 @@
1
+ module FlickrMapper
2
+ class Parser
3
+ class Failure < StandardError; end
4
+ def parse
5
+ raise "abstract parse method called"
6
+ end
7
+ end
8
+
9
+ class HpricotParser < Parser
10
+ def self.parse(data)
11
+ response = Hpricot.XML(data)
12
+ raise Parser::Failure, response.at(:err)['msg'] unless response.search(:err).empty?
13
+ response
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,99 @@
1
+ class FlickrMapper::Photo < FlickrMapper::Base
2
+
3
+ attr_accessor :id, :owner, :title, :description, :visibility, :date_posted, :editability, :comments, :notes, :urls, :farm, :secret, :server, :original_format, :original_secret
4
+
5
+ THUMB_SIZES = { :tiny => 't', :medium => 'm', :square => 's'}
6
+ IMAGE_SIZES = { :big => 'b', :medium => 'm', :original => 'o'}
7
+
8
+ # Hack til I find a method to get the attributes
9
+ #@@attrs = %w{owner title description visibility dates_posted editability comments notes urls}
10
+
11
+
12
+ def initialize(id=nil)
13
+ super(id)
14
+ @owner = nil
15
+ @title = ""
16
+ @description = ""
17
+ @visibility = nil
18
+ @date_posted = nil
19
+ @editability = nil
20
+ @comments = nil
21
+ @notes = ""
22
+ @urls = nil
23
+ @farm = ""
24
+ @secret = ""
25
+ @server = ""
26
+ @original_format = ""
27
+ @original_secret = ""
28
+ end
29
+
30
+
31
+
32
+ def self.find(param, args={})
33
+ if param.is_a? String
34
+ args = args.merge!(:photo_id => param)
35
+ super('flickr.photos.getInfo', args)
36
+ elsif param.is_a? Array
37
+ photos = []
38
+ param.each do |p|
39
+ data = args.merge!(:photo_id => p)
40
+ photos << super('flickr.photos.getInfo', data)
41
+ end
42
+ return photos
43
+ elsif param.is_a? Symbol
44
+ if param == :all
45
+ #blah
46
+ elsif param == :first
47
+ end
48
+ end
49
+ end
50
+
51
+
52
+ def self.parse(doc)
53
+ model = self.new
54
+ (doc/:photo).each do |photo|
55
+ model.title = (photo/:title).innerHTML
56
+ model.description = (photo/:description).innerHTML
57
+ model.id = photo["id"]
58
+ model.farm = photo["farm"]
59
+ model.secret = photo["secret"]
60
+ model.server = photo["server"]
61
+ model.original_secret = photo["originalsecret"]
62
+ model.original_format = photo["originalformat"]
63
+
64
+ #visibility ispublic="1" isfriend="0" isfamily="0" />
65
+ #model.visible_to_public = (photo/:visibility).attr("ispublic")
66
+ #model.visible_to_family =
67
+ #model.visible_to_friends =
68
+
69
+ #dates posted="1210034906" taken="2008-05-04 13:30:49" takengranularity="0" lastupdate="1210034913" />
70
+ model.date_posted = (photo/:dates).attr("posted")
71
+ #editability cancomment="0" canaddmeta="0" />
72
+ #usage candownload="1" canblog="0" canprint="0" />
73
+ model.comments = (photo/:comments).innerHTML
74
+ model.notes = (photo/:notes).innerHTML
75
+ #tags
76
+ # <tag id="1407141-2469654388-6260" author="51797041@N00" raw="Manly" machine_tag="0">manly</tag>
77
+ #/tags>
78
+ #urls>
79
+ #t<url type="photopage">http://www.flickr.com/photos/jaimo/2469654388/</url>
80
+ #/urls>
81
+ #model.urls[:main] = (((photo/:urls).first)/:url).innerHTML
82
+ end
83
+ model
84
+ end
85
+
86
+ def thumbnail_url(size=:tiny)
87
+ thumb_size = THUMB_SIZES[size]
88
+ "http://farm#{@farm}.static.flickr.com/#{@server}/#{@id}_#{@secret}_#{thumb_size}.jpg"
89
+ end
90
+
91
+ def image_url(size=nil)
92
+ if size == :original
93
+ "http://farm#{@farm}.static.flickr.com/#{@server}/#{@id}_#{@original_secret}_o.#{@original_format}"
94
+ else
95
+ img_size = size.nil? ? "" : "_#{IMAGE_SIZES[size]}"
96
+ "http://farm#{@farm}.static.flickr.com/#{@server}/#{@id}_#{@secret}#{img_size}.jpg"
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,41 @@
1
+ class FlickrMapper::Photoset < FlickrMapper::Base
2
+
3
+ attr_accessor :id, :owner, :title, :description, :visibility, :date_posted, :editability, :comments, :notes, :urls
4
+
5
+ # Hack til I find a method to get the attributes
6
+ #@@attrs = %w{owner title description visibility dates_posted editability comments notes urls}
7
+
8
+ def self.find(param, args={})
9
+ if param.is_a? String
10
+ args = args.merge!(:photoset_id => param)
11
+ super('flickr.photosets.getInfo', args)
12
+ elsif param.is_a? Array
13
+ photosets = []
14
+ param.each do |p|
15
+ data = args.merge!(:photoset_id => p)
16
+ photosets << super('flickr.photosets.getInfo', data)
17
+ end
18
+ return photosets
19
+ end
20
+ end
21
+
22
+ def self.parse(doc)
23
+ model = self.new((doc/:photoset).attr("id"))
24
+ (doc/:photoset).each do |photoset|
25
+ model.title = (photoset/:title).innerHTML
26
+ model.description = (photoset/:description).innerHTML
27
+ end
28
+ model
29
+ end
30
+
31
+ def self.parse_photos(doc)
32
+ p_ids = doc.get_elements_by_tag_name("photo").map { |photo| photo["id"] }
33
+ FlickrMapper::Photo.find(p_ids)
34
+ end
35
+
36
+ def photos
37
+ raw = request_raw("flickr.photosets.getPhotos", {:photoset_id => @id })
38
+ FlickrMapper::Photoset.parse_photos(raw)
39
+ end
40
+
41
+ end
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "FlickrMapper" do
4
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'flickr_mapper'
6
+
7
+ Spec::Runner.configure do |config|
8
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: square-circle-triangle-flickr_mapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Square Circle Triangle
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-03 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"
24
+ version:
25
+ description:
26
+ email: sct@sct.com.au
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - flickr_mapper.gemspec
42
+ - lib/flickr_mapper.rb
43
+ - lib/flickr_mapper/base.rb
44
+ - lib/flickr_mapper/connection.rb
45
+ - lib/flickr_mapper/parser.rb
46
+ - lib/flickr_mapper/photo.rb
47
+ - lib/flickr_mapper/photoset.rb
48
+ - spec/flickr_mapper_spec.rb
49
+ - spec/spec_helper.rb
50
+ has_rdoc: false
51
+ homepage: http://github.com/square-circle-triangle/flickr_mapper
52
+ post_install_message:
53
+ rdoc_options:
54
+ - --charset=UTF-8
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ requirements: []
70
+
71
+ rubyforge_project:
72
+ rubygems_version: 1.2.0
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Flickr Mapper
76
+ test_files:
77
+ - spec/flickr_mapper_spec.rb
78
+ - spec/spec_helper.rb