fotolia 0.0.1
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/.gitignore +3 -0
- data/LICENSE +19 -0
- data/README.rdoc +76 -0
- data/Rakefile +35 -0
- data/TODO +3 -0
- data/VERSION +1 -0
- data/fotolia.gemspec +67 -0
- data/lib/fotolia.rb +161 -0
- data/lib/fotolia/base.rb +294 -0
- data/lib/fotolia/categories.rb +53 -0
- data/lib/fotolia/category.rb +23 -0
- data/lib/fotolia/color.rb +14 -0
- data/lib/fotolia/colors.rb +39 -0
- data/lib/fotolia/conceptual_categories.rb +15 -0
- data/lib/fotolia/conceptual_category.rb +24 -0
- data/lib/fotolia/countries.rb +21 -0
- data/lib/fotolia/country.rb +14 -0
- data/lib/fotolia/galleries.rb +36 -0
- data/lib/fotolia/gallery.rb +65 -0
- data/lib/fotolia/language.rb +58 -0
- data/lib/fotolia/medium.rb +348 -0
- data/lib/fotolia/representative_categories.rb +15 -0
- data/lib/fotolia/representative_category.rb +24 -0
- data/lib/fotolia/search_result_set.rb +244 -0
- data/lib/fotolia/tag.rb +18 -0
- data/lib/fotolia/tags.rb +38 -0
- data/lib/fotolia/user.rb +200 -0
- metadata +94 -0
@@ -0,0 +1,53 @@
|
|
1
|
+
module Fotolia
|
2
|
+
#
|
3
|
+
# Base class for ConceptualCategories and RepresentativeCategories.
|
4
|
+
#
|
5
|
+
class Categories
|
6
|
+
#
|
7
|
+
# == Parameters
|
8
|
+
# fotolia_client:: A Fotolia::Base object
|
9
|
+
#
|
10
|
+
def initialize(fotolia_client)
|
11
|
+
@fotolia = fotolia_client
|
12
|
+
end
|
13
|
+
|
14
|
+
#
|
15
|
+
# Returns an array of Category objects. If no category is given, fetches
|
16
|
+
# the root level category. Otherwise the child categories of the given cat
|
17
|
+
# are returned.
|
18
|
+
#
|
19
|
+
# Raises a RuntimeError if not called on a ConceptualCategories or
|
20
|
+
# RepresentativeCategories object, i. e. <tt>@method</tt> and
|
21
|
+
# <tt>@klass</tt> has to be set.
|
22
|
+
#
|
23
|
+
def find(category = nil)
|
24
|
+
raise 'You have to use ConceptualCategories or RepresentativeCategories!' unless(@method && @klass)
|
25
|
+
|
26
|
+
k = if(category) then category.id else :root end
|
27
|
+
|
28
|
+
if(@categories && @categories[k]) # check if categories have been loaded already
|
29
|
+
@categories[k] # use cached categories
|
30
|
+
else
|
31
|
+
# get cats from fotolia
|
32
|
+
res = if(category && (category.kind_of?(String) || category.kind_of?(Fixnum)))
|
33
|
+
@fotolia.remote_call(@method, @fotolia.language.id, category.to_i)
|
34
|
+
elsif(category)
|
35
|
+
@fotolia.remote_call(@method, @fotolia.language.id, category.id.to_i)
|
36
|
+
else
|
37
|
+
@fotolia.remote_call(@method, @fotolia.language.id)
|
38
|
+
end
|
39
|
+
|
40
|
+
@categories = Hash.new unless(@categories)
|
41
|
+
|
42
|
+
@categories[k] = res.collect{|c| @klass.new(@fotolia, {'key' => c.first, 'parent_category' => category}.merge(c.last))}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Returns an array of all root level Category objects. See #find.
|
48
|
+
#
|
49
|
+
def root_level
|
50
|
+
self.find
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Fotolia
|
2
|
+
#
|
3
|
+
# Base class for ConceptualCategory and RepresentativeCategory.
|
4
|
+
#
|
5
|
+
class Category
|
6
|
+
# <Integer> The category's id at Fotolia
|
7
|
+
attr_reader :id
|
8
|
+
# <String> The category's name at Fotolia. Should be translated to the language the used Fotolia::Base object is set to.
|
9
|
+
attr_reader :name
|
10
|
+
# <Category> The parent of this category or nil if any.
|
11
|
+
attr_reader :parent_category
|
12
|
+
# <String> Don't know what this attribute means, but Fotolia's API delivers it...
|
13
|
+
attr_reader :key
|
14
|
+
|
15
|
+
def initialize(fotolia_client, attributes)
|
16
|
+
@fotolia = fotolia_client
|
17
|
+
@id = attributes['id'].to_i
|
18
|
+
@name = attributes['name']
|
19
|
+
@parent_category = attributes['parent_category']
|
20
|
+
@key = attributes['key']
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Fotolia
|
2
|
+
#
|
3
|
+
# Class fetching colors known to Fotolia's API.
|
4
|
+
#
|
5
|
+
# You should use Fotolia::Base#colors as shortcut instead of creating own
|
6
|
+
# instances.
|
7
|
+
#
|
8
|
+
class Colors
|
9
|
+
def initialize(fotolia_client)
|
10
|
+
@fotolia = fotolia_client
|
11
|
+
end
|
12
|
+
|
13
|
+
#
|
14
|
+
# Fetches colors from Fotolia's API and returns them as Array of
|
15
|
+
# Fotolia::Color objects.
|
16
|
+
#
|
17
|
+
# Colors at Fotolia may have children. Not passing anything to this method
|
18
|
+
# returns all root level colors. Passing a Fotolia::Color object returns
|
19
|
+
# its children.
|
20
|
+
#
|
21
|
+
def find_all(parent_color = nil)
|
22
|
+
rsp = if(parent_color.kind_of?(Fotolia::Color))
|
23
|
+
@fotolia.remote_call('getColors', parent_color.id)
|
24
|
+
elsif(parent_color)
|
25
|
+
@fotolia.remote_call('getColors', parent_color.to_i)
|
26
|
+
else
|
27
|
+
@fotolia.remote_call('getColors')
|
28
|
+
end
|
29
|
+
|
30
|
+
ret = Array.new
|
31
|
+
|
32
|
+
rsp['colors'].each_value do |color_response|
|
33
|
+
ret << Fotolia::Color.new(:id => color_response['id'].to_i, :name => color_response['name'])
|
34
|
+
end
|
35
|
+
|
36
|
+
ret
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Fotolia
|
2
|
+
#
|
3
|
+
# An interface to the conceptual categories at Fotolia.
|
4
|
+
#
|
5
|
+
# You should consider using Fotolia::Base#conceptual_categories as shortcut
|
6
|
+
# to an instance of this class.
|
7
|
+
#
|
8
|
+
class ConceptualCategories < Categories
|
9
|
+
def initialize(fotolia_client)
|
10
|
+
@method = 'getCategories2'
|
11
|
+
@klass = ConceptualCategory
|
12
|
+
super(fotolia_client)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Fotolia
|
2
|
+
#
|
3
|
+
# Represents a conceptual category at Fotolia.
|
4
|
+
#
|
5
|
+
class ConceptualCategory < Category
|
6
|
+
#
|
7
|
+
# Returns an array of ConceptualCategory objects which are children of this
|
8
|
+
# category.
|
9
|
+
#
|
10
|
+
def child_categories
|
11
|
+
@fotolia.conceptual_categories.find(self)
|
12
|
+
end
|
13
|
+
|
14
|
+
#
|
15
|
+
# Searches for media in this category. For the options hash, see
|
16
|
+
# Fotolia::Base#search.
|
17
|
+
#
|
18
|
+
# Returns a Fotolia::SearchResultSet.
|
19
|
+
#
|
20
|
+
def media(options = {})
|
21
|
+
@fotolia.search(options.merge({:conceptual_category => self}))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Fotolia
|
2
|
+
#
|
3
|
+
# Fetches all countries known to Fotolia from its API.
|
4
|
+
#
|
5
|
+
# You may use Fotolia::Base#countries as shortcut to an instance of this class.
|
6
|
+
#
|
7
|
+
class Countries
|
8
|
+
def initialize(fotolia_client)
|
9
|
+
@fotolia = fotolia_client
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# Returns an array of Fotolia::Country objects.
|
14
|
+
#
|
15
|
+
def find_all
|
16
|
+
rsp = @fotolia.remote_call('getCountries', @fotolia.language.id)
|
17
|
+
|
18
|
+
rsp.collect{|c| Fotolia::Country.new(c)}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Fotolia
|
2
|
+
#
|
3
|
+
# Interface to galleries at Fotolia.
|
4
|
+
#
|
5
|
+
# Use Fotolia::Base#galleries as shortcut to an instance of this class.
|
6
|
+
#
|
7
|
+
class Galleries
|
8
|
+
def initialize(fotolia_client)
|
9
|
+
@fotolia = fotolia_client
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# Returns public galleries in an array (of Fotolia::Gallery objects).
|
14
|
+
#
|
15
|
+
def find_all
|
16
|
+
rsp = @fotolia.remote_call('getGalleries', @fotolia.language.id)
|
17
|
+
|
18
|
+
rsp.collect{|g| Fotolia::Gallery.new(@fotolia, g)}
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# Creates a gallery for the logged in user.
|
23
|
+
#
|
24
|
+
# Requires an authenticated session, see Fotolia::Base#login.
|
25
|
+
#
|
26
|
+
# Not working with Partner API.
|
27
|
+
#
|
28
|
+
def create(name)
|
29
|
+
raise Fotolia::LoginRequiredError unless @fotolia.logged_in?
|
30
|
+
|
31
|
+
res = @fotolia.remote_call('createUserGallery', @fotolia.session_id, name)
|
32
|
+
|
33
|
+
Fotolia::Gallery.new(@fotolia, {'id' => res['id'], 'name' => name})
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Fotolia
|
2
|
+
#
|
3
|
+
# Represents a gallery at Fotolia.
|
4
|
+
#
|
5
|
+
class Gallery
|
6
|
+
attr_reader :name, :thumbnail_width, :thumbnail_html_tag, :id, :nb_media,
|
7
|
+
:thumbnail_height, :thumbnail_url
|
8
|
+
|
9
|
+
#
|
10
|
+
# == Parameters
|
11
|
+
# fotolia_client:: A Fotolia::Base object.
|
12
|
+
# attributes:: An hash containing the keys 'name', 'id', 'nb_media' and
|
13
|
+
# optional 'thumbnail_width', 'thumbnail_height',
|
14
|
+
# 'thumbnail_html_tag' and 'thumbnail_url'.
|
15
|
+
#
|
16
|
+
def initialize(fotolia_client, attributes)
|
17
|
+
@fotolia = fotolia_client
|
18
|
+
|
19
|
+
@name = attributes['name']
|
20
|
+
@thumbnail_width = attributes['thumbnail_width'] if(attributes['thumbnail_width'])
|
21
|
+
@thumbnail_html_tag = attributes['thumbnail_html_tag'] if(attributes['thumbnail_html_tag'])
|
22
|
+
@id = attributes['id']
|
23
|
+
@nb_media = attributes['nb_media']
|
24
|
+
@thumbnail_height = attributes['thumbnail_height'] if(attributes['thumbnail_height'])
|
25
|
+
@thumbnail_url = attributes['thumbnail_url'] if(attributes['thumbnail_url'])
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Returns the media in this gallery.
|
30
|
+
#
|
31
|
+
# ==options hash
|
32
|
+
# See Fotolia::Base#search
|
33
|
+
#
|
34
|
+
# ==Returns
|
35
|
+
# Fotolia::SearchResultSet
|
36
|
+
#
|
37
|
+
def media(options = {})
|
38
|
+
@fotolia.search(options.merge({:gallery => self}))
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# Deletes the gallery.
|
43
|
+
#
|
44
|
+
# Requires an authenticated session. The logged in user has to be the owner
|
45
|
+
# of the gallery.
|
46
|
+
#
|
47
|
+
# Not available in Partner API.
|
48
|
+
#
|
49
|
+
def delete
|
50
|
+
raise Fotolia::LoginRequiredError unless @fotolia.logged_in?
|
51
|
+
@fotolia.remote_call('deleteUserGallery', @fotolia.session_id, self.id)
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Add a medium to this gallery. The gallery has to be owned by the logged in
|
56
|
+
# user, so this methods requires an authenticated session. See
|
57
|
+
# Fotolia::Base#login.
|
58
|
+
#
|
59
|
+
# Not available in Partner API.
|
60
|
+
#
|
61
|
+
def << (medium)
|
62
|
+
medium.add_to_user_gallery(self)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Fotolia
|
2
|
+
# Error class raised if an unknwon symbol or id is given to Fotolia::Language#new.
|
3
|
+
class LanguageNotDefinedError < StandardError; end
|
4
|
+
|
5
|
+
#
|
6
|
+
# Represents a language at Fotolia. An object of this class may be given to
|
7
|
+
# Fotolia::Base#new:
|
8
|
+
#
|
9
|
+
# language = Fotolia::Language.new :de
|
10
|
+
# fotolia = Fotolia.new :api_key => 'AAAAA...', :language => language
|
11
|
+
#
|
12
|
+
# Most API calls on the fotolia object will deliver translated results then.
|
13
|
+
#
|
14
|
+
class Language
|
15
|
+
|
16
|
+
#
|
17
|
+
# Translate language code-like symbols to their ids at Fotolia.
|
18
|
+
#
|
19
|
+
LANGUAGE_IDS = {
|
20
|
+
:fr => 1,
|
21
|
+
:en_us => 2,
|
22
|
+
:en_uk => 3,
|
23
|
+
:de => 4,
|
24
|
+
:es => 5,
|
25
|
+
:it => 6,
|
26
|
+
:pt_pt => 7,
|
27
|
+
:pt_br => 8,
|
28
|
+
:jp => 9,
|
29
|
+
:pl => 11
|
30
|
+
}
|
31
|
+
|
32
|
+
def initialize(id_or_lang_sym)
|
33
|
+
if(id_or_lang_sym.is_a?(Symbol))
|
34
|
+
raise Fotolia::LanguageNotDefinedError and return nil unless(LANGUAGE_IDS.has_key?(id_or_lang_sym))
|
35
|
+
@language_sym = id_or_lang_sym
|
36
|
+
else
|
37
|
+
raise Fotolia::LanguageNotDefinedError and return nil unless(LANGUAGE_IDS.has_value?(id_or_lang_sym))
|
38
|
+
@language_sym = LANGUAGE_IDS.invert[id_or_lang_sym]
|
39
|
+
end
|
40
|
+
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
@language_sym.to_s
|
46
|
+
end
|
47
|
+
|
48
|
+
alias to_code to_s
|
49
|
+
|
50
|
+
def to_sym
|
51
|
+
@language_sym
|
52
|
+
end
|
53
|
+
|
54
|
+
def id
|
55
|
+
LANGUAGE_IDS[@language_sym]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,348 @@
|
|
1
|
+
module Fotolia
|
2
|
+
#
|
3
|
+
# Represents a medium in Fotolia's database.
|
4
|
+
#
|
5
|
+
class Medium
|
6
|
+
#
|
7
|
+
# A thumbnail attached to a Medium object. Just holds its url, width, height
|
8
|
+
# and an html tag to include it on web pages.
|
9
|
+
#
|
10
|
+
class Thumbnail
|
11
|
+
attr_reader :url, :html_tag, :width, :height
|
12
|
+
|
13
|
+
def initialize(attributes)
|
14
|
+
@url = attributes['thumbnail_url']
|
15
|
+
@html_tag = attributes['thumbnail_html_tag']
|
16
|
+
@width = attributes['thumbnail_width']
|
17
|
+
@height = attributes['thumbnail_height']
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# Represents a license in which Fotolia's media are available.
|
23
|
+
#
|
24
|
+
# See http://www.fotolia.com/Info/SizesAndUses for an overview of available
|
25
|
+
# licenses.
|
26
|
+
#
|
27
|
+
class License
|
28
|
+
attr_reader :name, :price
|
29
|
+
|
30
|
+
def initialize(medium, attributes)
|
31
|
+
@medium = medium
|
32
|
+
@name = attributes['name']
|
33
|
+
@price = attributes['price']
|
34
|
+
end
|
35
|
+
|
36
|
+
def width
|
37
|
+
begin
|
38
|
+
@width ||= @medium.details['licenses_details'][self.name]['width']
|
39
|
+
rescue
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def height
|
45
|
+
begin
|
46
|
+
@height ||= @medium.details['licenses_details'][self.name]['height']
|
47
|
+
rescue
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def dpi
|
53
|
+
begin
|
54
|
+
@dpi ||= @medium.details['licenses_details'][self.name]['dpi']
|
55
|
+
rescue
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def ratio
|
61
|
+
begin
|
62
|
+
@ratio ||= @medium.details['licenses_details'][self.name]['ratio']
|
63
|
+
rescue
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def phrase
|
69
|
+
begin
|
70
|
+
@phrase ||= @medium.details['licenses_details'][self.name]['phrase']
|
71
|
+
rescue
|
72
|
+
nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
#
|
78
|
+
# I never got to know what a CompImage should be, least Fotolia's API has a
|
79
|
+
# method to get one for a medium. So this is a class holding the info that
|
80
|
+
# method returns.
|
81
|
+
#
|
82
|
+
class CompImage
|
83
|
+
attr_reader :url, :width, :height
|
84
|
+
|
85
|
+
def initialize(attributes)
|
86
|
+
@url = attributes['url']
|
87
|
+
@width = attributes['width']
|
88
|
+
@height = attributes['height']
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.find(medium)
|
92
|
+
CompImage.new(medium.fotolia.remote_call('getMediaComp', medium.id))
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
#
|
97
|
+
# Fotolia has media in three types: Photo, illustration and vector. In the
|
98
|
+
# API they are referenced by ids, so we keep this hash to ease the handling
|
99
|
+
# for human developers...
|
100
|
+
#
|
101
|
+
MEDIA_TYPES = {1 => :photo, 2 => :illustration, 3 => :vector}
|
102
|
+
|
103
|
+
# The id of the medium in Fotolia's DB.
|
104
|
+
attr_reader :id
|
105
|
+
#
|
106
|
+
# The thumbnail attached to the medium. Note that its size may vary
|
107
|
+
# according to the :thumbnail_size option you give at Base#search.
|
108
|
+
#
|
109
|
+
attr_reader :thumbnail
|
110
|
+
# An array of Licenses the medium is available in.
|
111
|
+
attr_reader :licenses
|
112
|
+
attr_reader :fotolia #:nodoc:
|
113
|
+
|
114
|
+
#
|
115
|
+
# Needs an instance of Fotolia::Base (so you won't have to give the API_KEY
|
116
|
+
# each time you call a method which requires interaction with the API) and
|
117
|
+
# some attributes as parameters.
|
118
|
+
#
|
119
|
+
# Fotolia::Medium.new Fotolia.new(:api_key => 'AAA...'), :id => 12345678
|
120
|
+
#
|
121
|
+
# should be enough to get a valid object -- missing values will be collected
|
122
|
+
# from the API automatically (with an default size of 400px for the
|
123
|
+
# thumbnail).
|
124
|
+
#
|
125
|
+
def initialize(fotolia_client, attributes)
|
126
|
+
@fotolia = fotolia_client
|
127
|
+
@id = attributes['id'].to_i
|
128
|
+
@title = attributes['title'] if(attributes['title'])
|
129
|
+
@creator_id = attributes['creator_id'] if(attributes['creator_id'])
|
130
|
+
@creator_name = attributes['creator_name'] if(attributes['creator_name'])
|
131
|
+
@thumbnail = Thumbnail.new(attributes) if(attributes['thumbnail_url'])
|
132
|
+
@nb_views = attributes['nb_views'] if(attributes['nb_views'])
|
133
|
+
@nb_downloads = attributes['nb_downloads'] if(attributes['nb_downloads'])
|
134
|
+
@keywords = attributes['keywords'].split(',').collect{|k| k.strip} if(attributes['keywords'])
|
135
|
+
@licenses = attributes['licenses'].collect{|l| License.new(self, l)} if(attributes['licenses'])
|
136
|
+
end
|
137
|
+
|
138
|
+
#
|
139
|
+
# See Fotolia::Medium::CompImage
|
140
|
+
#
|
141
|
+
def comp_image
|
142
|
+
@comp_image ||= CompImage.find(self)
|
143
|
+
end
|
144
|
+
|
145
|
+
def details #:nodoc:
|
146
|
+
@details ||= @fotolia.remote_call('getMediaData', self.id, 400, @fotolia.language.id)
|
147
|
+
end
|
148
|
+
|
149
|
+
#
|
150
|
+
# Returns the number of times this medium has been viewed on Fotolia's page.
|
151
|
+
#
|
152
|
+
def nb_views
|
153
|
+
@nb_views ||= self.details['nb_views']
|
154
|
+
end
|
155
|
+
|
156
|
+
#
|
157
|
+
# Returns the number of times this medium has been purchased at Fotolia.
|
158
|
+
#
|
159
|
+
def nb_downloads
|
160
|
+
@nb_downloads ||= self.details['nb_downloads']
|
161
|
+
end
|
162
|
+
|
163
|
+
#
|
164
|
+
# Returns an array of keywords attached to this medium. May be translated to
|
165
|
+
# the language the client has been set to, but don't rely on it.
|
166
|
+
#
|
167
|
+
def keywords
|
168
|
+
unless(@keywords)
|
169
|
+
@keywords = []
|
170
|
+
@keywords = self.details['keywords'].collect{|k| k['name']} if(self.details['keywords'])
|
171
|
+
end
|
172
|
+
@keywords
|
173
|
+
end
|
174
|
+
|
175
|
+
#
|
176
|
+
# Returns the Fotolia::Country object associated with this medium.
|
177
|
+
#
|
178
|
+
def country
|
179
|
+
@country ||= Fotolia::Country.new({'id' => self.details['country_id'], 'name' => self.details['country_name']})
|
180
|
+
end
|
181
|
+
|
182
|
+
#
|
183
|
+
# Returns the Fotolia::ConceptualCategory object this medium is in.
|
184
|
+
#
|
185
|
+
# If the medium is in a child or grand-child category of the root level, the
|
186
|
+
# parent relations will be set properly. Call
|
187
|
+
# <tt>medium.conceptual_category.parent_category</tt> to use this feature.
|
188
|
+
#
|
189
|
+
def conceptual_category
|
190
|
+
#@conceptual_category ||= (self.details['cat2'] ? Fotolia::ConceptualCategory.new(@fotolia, self.details['cat2']) : nil)
|
191
|
+
unless(@conceptual_category)
|
192
|
+
@conceptual_category = if(self.details['cat2_hierarchy'])
|
193
|
+
cats = Array.new
|
194
|
+
self.details['cat2_hierarchy'].each_with_index do |cat, i|
|
195
|
+
parent = if(i > 0 && cats[i - 1]) then cats[i - 1] else nil end
|
196
|
+
cats[i] = Fotolia::ConceptualCategory.new(@fotolia, {'parent_category' => parent}.merge(cat))
|
197
|
+
end
|
198
|
+
cats.last
|
199
|
+
else
|
200
|
+
nil
|
201
|
+
end
|
202
|
+
end
|
203
|
+
@conceptual_category
|
204
|
+
end
|
205
|
+
|
206
|
+
#
|
207
|
+
# Same as Fotolia::Medium#conceptual_category, but returns the associated
|
208
|
+
# Fotolia::RepresentativeCategory instead.
|
209
|
+
#
|
210
|
+
def representative_category
|
211
|
+
#@representative_category ||= (self.details['cat1'] ? Fotolia::RepresentativeCategory.new(@fotolia, self.details['cat1']) : nil)
|
212
|
+
unless(@representative_category)
|
213
|
+
@representative_category = if(self.details['cat1_hierarchy'])
|
214
|
+
cats = Array.new
|
215
|
+
self.details['cat1_hierarchy'].each_with_index do |cat, i|
|
216
|
+
parent = if(i > 0 && cats[i - 1]) then cats[i - 1] else nil end
|
217
|
+
cats[i] = Fotolia::RepresentativeCategory.new(@fotolia, {'parent_category' => parent}.merge(cat))
|
218
|
+
end
|
219
|
+
cats.last
|
220
|
+
else
|
221
|
+
nil
|
222
|
+
end
|
223
|
+
end
|
224
|
+
@representative_category
|
225
|
+
end
|
226
|
+
|
227
|
+
#
|
228
|
+
# Returns the media type id used by Fotolia's API. See MEDIA_TYPES and
|
229
|
+
# #media_type
|
230
|
+
#
|
231
|
+
def media_type_id
|
232
|
+
@media_type_id ||= self.details['media_type_id']
|
233
|
+
end
|
234
|
+
|
235
|
+
#
|
236
|
+
# Returns the media type of this medium as symbol. May be one of :photo,
|
237
|
+
# :illustration, :vector or -- in desperate cases -- :unknown.
|
238
|
+
#
|
239
|
+
def media_type
|
240
|
+
MEDIA_TYPES[self.media_type_id] || :unknown
|
241
|
+
end
|
242
|
+
|
243
|
+
# No need for explanation, isn't there?
|
244
|
+
def title
|
245
|
+
@title ||= self.details['title']
|
246
|
+
end
|
247
|
+
|
248
|
+
# The id of the medium's creator. May be used to find more media by the same
|
249
|
+
# creator.
|
250
|
+
def creator_id
|
251
|
+
@creator_id ||= self.details['creator_id']
|
252
|
+
end
|
253
|
+
|
254
|
+
# The name of the creator.
|
255
|
+
def creator_name
|
256
|
+
@creator_name ||= self.details['creator_name']
|
257
|
+
end
|
258
|
+
|
259
|
+
#
|
260
|
+
# An array of licenses the medium is available in. See
|
261
|
+
# Fotolia::Medium::License.
|
262
|
+
#
|
263
|
+
def licenses
|
264
|
+
@licenses ||= self.details['licenses'].collect{|l| License.new(self, l)}
|
265
|
+
end
|
266
|
+
|
267
|
+
#
|
268
|
+
# A thumbnail for this medium. See Fotolia::Medium::Thumbnail.
|
269
|
+
#
|
270
|
+
def thumbnail
|
271
|
+
@thumbnail ||= Thumbnail.new(self.details)
|
272
|
+
end
|
273
|
+
|
274
|
+
# Returns true if this medium is a photo.
|
275
|
+
def is_photo?
|
276
|
+
:photo == self.media_type
|
277
|
+
end
|
278
|
+
|
279
|
+
# Returns true if this medium is an illustration.
|
280
|
+
def is_illustration?
|
281
|
+
:illustration == self.media_type
|
282
|
+
end
|
283
|
+
|
284
|
+
# Returns true if this medium is a vector image.
|
285
|
+
def is_vector?
|
286
|
+
:vector == self.media_type
|
287
|
+
end
|
288
|
+
|
289
|
+
#
|
290
|
+
# Searches for similar media to this medium.
|
291
|
+
#
|
292
|
+
# Note that this method takes the same options hash as Fotolia::Base#search.
|
293
|
+
#
|
294
|
+
def similar_media(options = {})
|
295
|
+
@fotolia.search(options.merge({:similia_id => self.id}))
|
296
|
+
end
|
297
|
+
|
298
|
+
# TODO:: implement function
|
299
|
+
#
|
300
|
+
# Does not work in Partner and Developer API.
|
301
|
+
#
|
302
|
+
def buy_and_save_as(license, file_path) #:nodoc:
|
303
|
+
end
|
304
|
+
|
305
|
+
#
|
306
|
+
# Adds this medium to the logged in user's lightbox or one of his galleries.
|
307
|
+
#
|
308
|
+
# Requires an authenticated session. Call Fotolia::Base#login on the fotolia
|
309
|
+
# client object used to get this medium object first!
|
310
|
+
#
|
311
|
+
# ==Parameters
|
312
|
+
# gallery:: A Fotolia::Gallery object or nil. If the latter, the user's lightbox is used.
|
313
|
+
#
|
314
|
+
# Does not work in Partner API.
|
315
|
+
#
|
316
|
+
def add_to_user_gallery(gallery = nil)
|
317
|
+
raise Fotolia::LoginRequiredError unless @fotolia.logged_in?
|
318
|
+
|
319
|
+
if(gallery)
|
320
|
+
# add to gallery
|
321
|
+
@fotolia.remote_call('addToUserGallery', @fotolia.session_id, self.id, gallery.id)
|
322
|
+
else
|
323
|
+
# add to lightbox
|
324
|
+
@fotolia.remote_call('addToUserGallery', @fotolia.session_id, self.id)
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
#
|
329
|
+
# Removes this medium from the logged in user's gallery or lightbox.
|
330
|
+
#
|
331
|
+
# Requires an authenticated session. Call Fotolia::Base#login first!
|
332
|
+
#
|
333
|
+
# ==Parameters
|
334
|
+
# gallery:: A Fotolia::Gallery object or nil. If the latter, the user's lightbox is used.
|
335
|
+
#
|
336
|
+
# Does not work in Partner API.
|
337
|
+
#
|
338
|
+
def remove_from_user_gallery(gallery = nil)
|
339
|
+
raise Fotolia::LoginRequiredError unless @fotolia.logged_in?
|
340
|
+
|
341
|
+
if(gallery)
|
342
|
+
@fotolia.remote_call('removeFromUserGallery', @fotolia.session_id, self.id, gallery.id)
|
343
|
+
else
|
344
|
+
@fotolia.remote_call('removeFromUserGallery', @fotolia.session_id, self.id)
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|
348
|
+
end
|