flickr-objects 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.
Files changed (52) hide show
  1. data/README.md +167 -0
  2. data/lib/flickr/api/flickr.rb +40 -0
  3. data/lib/flickr/api/media.rb +63 -0
  4. data/lib/flickr/api/person.rb +70 -0
  5. data/lib/flickr/api/photo.rb +11 -0
  6. data/lib/flickr/api/set.rb +70 -0
  7. data/lib/flickr/api/video.rb +11 -0
  8. data/lib/flickr/api.rb +50 -0
  9. data/lib/flickr/api_caller.rb +95 -0
  10. data/lib/flickr/client/methods_client.rb +22 -0
  11. data/lib/flickr/client/middleware/retry.rb +38 -0
  12. data/lib/flickr/client/middleware.rb +42 -0
  13. data/lib/flickr/client/upload_client.rb +75 -0
  14. data/lib/flickr/client.rb +57 -0
  15. data/lib/flickr/configuration.rb +23 -0
  16. data/lib/flickr/helpers/base_58.rb +15 -0
  17. data/lib/flickr/helpers/boolean.rb +4 -0
  18. data/lib/flickr/helpers/core_ext.rb +5 -0
  19. data/lib/flickr/helpers/inheritable_attr_accessor.rb +18 -0
  20. data/lib/flickr/object/attribute/converter.rb +49 -0
  21. data/lib/flickr/object/attribute/finder.rb +32 -0
  22. data/lib/flickr/object/attribute.rb +45 -0
  23. data/lib/flickr/object.rb +39 -0
  24. data/lib/flickr/objects/attribute_values/collection.rb +10 -0
  25. data/lib/flickr/objects/attribute_values/location.rb +14 -0
  26. data/lib/flickr/objects/attribute_values/media.rb +70 -0
  27. data/lib/flickr/objects/attribute_values/note.rb +11 -0
  28. data/lib/flickr/objects/attribute_values/permissions.rb +12 -0
  29. data/lib/flickr/objects/attribute_values/person.rb +23 -0
  30. data/lib/flickr/objects/attribute_values/photo.rb +19 -0
  31. data/lib/flickr/objects/attribute_values/set.rb +21 -0
  32. data/lib/flickr/objects/attribute_values/tag.rb +9 -0
  33. data/lib/flickr/objects/attribute_values/upload_ticket.rb +11 -0
  34. data/lib/flickr/objects/attribute_values/video.rb +27 -0
  35. data/lib/flickr/objects/attribute_values/visibility.rb +10 -0
  36. data/lib/flickr/objects/collection.rb +58 -0
  37. data/lib/flickr/objects/location.rb +26 -0
  38. data/lib/flickr/objects/media.rb +74 -0
  39. data/lib/flickr/objects/note.rb +14 -0
  40. data/lib/flickr/objects/permissions.rb +14 -0
  41. data/lib/flickr/objects/person.rb +42 -0
  42. data/lib/flickr/objects/photo.rb +48 -0
  43. data/lib/flickr/objects/set.rb +33 -0
  44. data/lib/flickr/objects/tag.rb +17 -0
  45. data/lib/flickr/objects/upload_ticket.rb +18 -0
  46. data/lib/flickr/objects/video.rb +24 -0
  47. data/lib/flickr/objects/visibility.rb +12 -0
  48. data/lib/flickr/objects.rb +28 -0
  49. data/lib/flickr/version.rb +3 -0
  50. data/lib/flickr-objects.rb +2 -0
  51. data/lib/flickr.rb +21 -0
  52. metadata +212 -0
@@ -0,0 +1,75 @@
1
+ class Flickr
2
+ class UploadClient < Client
3
+ def initialize(access_token)
4
+ super(access_token) do |builder|
5
+ builder.use Faraday::Request::Multipart
6
+ end
7
+ end
8
+
9
+ def upload(media, params = {})
10
+ file = get_file(media)
11
+ response = post "upload", {photo: file}.merge(params)
12
+ response.body
13
+ end
14
+
15
+ def replace(media, id, params = {})
16
+ file = get_file(media)
17
+ response = post "replace", {photo: file, photo_id: id}.merge(params)
18
+ response.body
19
+ end
20
+
21
+ def parser
22
+ FaradayMiddleware::ParseXml
23
+ end
24
+
25
+ private
26
+
27
+ def get_file(object)
28
+ file, content_type, file_path =
29
+ case object.class.name
30
+ when "String"
31
+ [File.open(object), determine_content_type(object), object]
32
+ when "File"
33
+ [object, determine_content_type(object.path), object.path]
34
+ when "ActionDispatch::Http::UploadedFile"
35
+ [object, object.content_type, object.tempfile]
36
+ when "Hash" && defined?(Sinatra)
37
+ [object[:tempfile], object[:type], object[:tempfile].path]
38
+ else
39
+ raise Error, "invalid file format"
40
+ end
41
+
42
+ Faraday::UploadIO.new(file, content_type, file_path)
43
+ end
44
+
45
+ def determine_content_type(path)
46
+ extension = File.extname(path)
47
+ array = CONTENT_TYPES.keys.find { |array| array.include?(extension) }
48
+
49
+ if array
50
+ CONTENT_TYPES[array]
51
+ else
52
+ raise Error, "content type for #{extension} is not known"
53
+ end
54
+ end
55
+
56
+ CONTENT_TYPES = {
57
+ %w[.jpg .jpeg .jpe .jif .jfif .jfi] => 'image/jpeg',
58
+ %w[.gif] => 'image/gif',
59
+ %w[.png] => 'image/png',
60
+ %w[.svg .svgz] => 'image/svg+xml',
61
+ %w[.tiff .tif] => 'image/tiff',
62
+ %w[.ico] => 'image/vnd.microsoft.icon',
63
+
64
+ %w[.mpg .mpeg .m1v .m1a .m2a .mpa .mpv] => 'video/mpeg',
65
+ %w[.mp4 .m4a .m4p .m4b .m4r .m4v] => 'video/mp4',
66
+ %w[.ogv .oga .ogx .ogg .spx] => 'video/ogg',
67
+ %w[.mov .qt] => 'video/quicktime',
68
+ %w[.webm] => 'video/webm',
69
+ %w[.mkv .mk3d .mka .mks] => 'video/x-matroska',
70
+ %w[.wmv] => 'video/x-ms-wmv',
71
+ %w[.flv .f4v .f4p .f4a .f4b] => 'video/x-flv',
72
+ %w[.avi] => 'video/avi'
73
+ }
74
+ end
75
+ end
@@ -0,0 +1,57 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "flickr/client/middleware"
4
+
5
+ class Flickr
6
+ class Client < Faraday::Connection
7
+ DEFAULTS = {
8
+ open_timeout: 3,
9
+ timeout: 4
10
+ }
11
+
12
+ def initialize(access_token)
13
+ api_key, shared_secret = Flickr.configuration.fetch(:api_key, :shared_secret)
14
+
15
+ open_timeout = Flickr.configuration.open_timeout || DEFAULTS[:open_timeout]
16
+ timeout = Flickr.configuration.timeout || DEFAULTS[:timeout]
17
+
18
+ url = Flickr.configuration.secure ? "https://secure.flickr.com/services" : "http://api.flickr.com/services"
19
+ proxy = Flickr.configuration.proxy
20
+
21
+ params = {
22
+ url: url,
23
+ params: {
24
+ format: "json",
25
+ nojsoncallback: 1,
26
+ api_key: api_key
27
+ },
28
+ request: {
29
+ open_timeout: open_timeout,
30
+ timeout: timeout
31
+ },
32
+ proxy: proxy
33
+ }
34
+
35
+ super(params) do |builder|
36
+ # Request
37
+ builder.use Middleware::Retry
38
+ builder.use FaradayMiddleware::OAuth,
39
+ consumer_key: api_key,
40
+ consumer_secret: shared_secret,
41
+ token: access_token.first,
42
+ token_secret: access_token.last
43
+ yield builder if block_given?
44
+
45
+ # Response
46
+ builder.use Middleware::CheckStatus
47
+ builder.use self.parser
48
+ builder.use Middleware::CheckOAuth
49
+
50
+ builder.adapter :net_http
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ require "flickr/client/methods_client"
57
+ require "flickr/client/upload_client"
@@ -0,0 +1,23 @@
1
+ class Flickr
2
+ class Configuration
3
+ attr_accessor :api_key
4
+ attr_accessor :shared_secret
5
+
6
+ attr_accessor :access_token_key
7
+ attr_accessor :access_token_secret
8
+
9
+ attr_accessor :open_timeout
10
+ attr_accessor :timeout
11
+
12
+ attr_accessor :secure
13
+ attr_accessor :proxy
14
+
15
+ def fetch(*attributes)
16
+ attributes.map { |attribute| send(attribute) }
17
+ end
18
+
19
+ def access_token
20
+ [access_token_key, access_token_secret]
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ class Flickr
2
+ module Base58
3
+ ALPHABET = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'.chars.to_a.freeze
4
+
5
+ def to_base58(value)
6
+ value = Integer(value)
7
+ begin
8
+ value, remainder = value.divmod(58)
9
+ result = ALPHABET[remainder] + (result || '')
10
+ end while value > 0
11
+
12
+ result
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ class Flickr
2
+ class Boolean
3
+ end
4
+ end
@@ -0,0 +1,5 @@
1
+ class Hash
2
+ def slice(*keys)
3
+ select { |key, value| keys.include?(key) }
4
+ end unless method_defined?(:slice)
5
+ end
@@ -0,0 +1,18 @@
1
+ class Flickr
2
+ module InheritableAttrAccessor
3
+ def inheritable_attr_accessor(*names)
4
+ names.each do |name|
5
+ attr_reader name
6
+
7
+ define_method("#{name}=") do |value|
8
+ instance_variable_set("@#{name}", value)
9
+ if respond_to?(:children)
10
+ children.each do |child|
11
+ child.send("#{name}=", send(name))
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,49 @@
1
+ require "date"
2
+ require "flickr/helpers/boolean"
3
+
4
+ class Flickr
5
+ class Object
6
+ class Attribute::Converter
7
+ def initialize(instance)
8
+ @instance = instance
9
+ end
10
+
11
+ def convert(value, type)
12
+ return value if value.nil?
13
+
14
+ if type.is_a?(Array)
15
+ return value.map {|item| convert(item, type.first) }
16
+ elsif Object.children.include?(type)
17
+ return type.new(value, @instance.client)
18
+ else
19
+ try_each(CONVERTERS[type]) do |converter|
20
+ return converter.call(value)
21
+ end
22
+ end
23
+
24
+ value
25
+ end
26
+
27
+ CONVERTERS = {
28
+ ::Object => [->(value) { value }],
29
+ String => [->(value) { String(value) }],
30
+ Time => [->(value) { Time.at(Integer(value)) }, ->(value) { DateTime.parse(value).to_time }],
31
+ Boolean => [->(value) { Integer(value) == 1 }],
32
+ Integer => [->(value) { Integer(value) }],
33
+ Float => [->(value) { Float(value) }],
34
+ Hash => [->(value) { value }],
35
+ }
36
+
37
+ private
38
+
39
+ def try_each(enum, &block)
40
+ enum.each do |element|
41
+ begin
42
+ yield element
43
+ rescue
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,32 @@
1
+ class Flickr
2
+ class Object
3
+ class Attribute::Finder
4
+ def initialize(instance)
5
+ @instance = instance
6
+ end
7
+
8
+ def find(attribute, *args)
9
+ attribute_values = @instance.class.attribute_values[attribute] || []
10
+ attribute_values << ->{ @hash.fetch(attribute.to_s) }
11
+
12
+ try_each(attribute_values) do |attribute_value|
13
+ result = @instance.instance_exec(*args, &attribute_value)
14
+ return result unless result.nil?
15
+ end
16
+
17
+ nil
18
+ end
19
+
20
+ private
21
+
22
+ def try_each(enum, &block)
23
+ enum.each do |element|
24
+ begin
25
+ yield element
26
+ rescue
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,45 @@
1
+ require "flickr/helpers/inheritable_attr_accessor"
2
+
3
+ class Flickr
4
+ class Object
5
+ module Attribute
6
+ def self.extended(base)
7
+ base.send(:include, InstanceMethods)
8
+ end
9
+
10
+ def attributes
11
+ @attributes ||= []
12
+ end
13
+
14
+ def attribute(name, type = ::Object, options = {})
15
+ attributes << name
16
+ children.each { |child| child.attributes << name } if respond_to?(:children)
17
+
18
+ define_method(name) do |*args|
19
+ value = attribute_finder.find(name, *args)
20
+ attribute_converter.convert(value, type)
21
+ end
22
+
23
+ Array(options[:aliases]).each do |alias_name|
24
+ alias_method alias_name, name
25
+ end
26
+ end
27
+
28
+ module InstanceMethods
29
+ def attribute_finder
30
+ Finder.new(self)
31
+ end
32
+
33
+ def attribute_converter
34
+ Converter.new(self)
35
+ end
36
+ end
37
+
38
+ extend InheritableAttrAccessor
39
+ inheritable_attr_accessor :attribute_values
40
+ end
41
+ end
42
+ end
43
+
44
+ require_relative "attribute/finder"
45
+ require_relative "attribute/converter"
@@ -0,0 +1,39 @@
1
+ require "flickr/object/attribute"
2
+ require "flickr/api_caller"
3
+
4
+ class Flickr
5
+ class Object
6
+ def self.children
7
+ @children ||= []
8
+ end
9
+
10
+ def self.inherited(child)
11
+ child.send(:extend, Attribute)
12
+ child.send(:include, ApiCaller)
13
+
14
+ children << child
15
+ Object.children << child if self != Object
16
+ end
17
+
18
+ def self.find(id)
19
+ new({"id" => id}, client)
20
+ end
21
+
22
+ def inspect
23
+ attribute_values = {}
24
+ self.class.attributes.each do |name|
25
+ attribute_values[name] = send(name) unless send(name).nil?
26
+ end
27
+ class_name = self.class.name
28
+ id = "0x%x" % (object_id << 1)
29
+ "#<#{class_name}:#{id} #{attribute_values.map { |k, v| "#{k}=#{v.inspect}" }.join(" ")}>"
30
+ end
31
+
32
+ protected
33
+
34
+ def initialize(hash, client)
35
+ @hash = hash || {}
36
+ @client = client
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,10 @@
1
+ class Flickr
2
+ class Collection < Object
3
+ self.attribute_values = {
4
+ current_page: [->{ @hash["page"] }],
5
+ per_page: [->{ @hash["per_page"] }, ->{ @hash["perpage"] }],
6
+ total_entries: [->{ @hash["total"] }],
7
+ total_pages: [->{ @hash["pages"] }],
8
+ }
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ class Flickr
2
+ class Location < Object
3
+ class Area < Object
4
+ self.attribute_values = {
5
+ name: [->{ @hash["_content"] }],
6
+ woe_id: [->{ @hash["woeid"] }],
7
+ }
8
+ end
9
+
10
+ self.attribute_values = {
11
+ woe_id: [->{ @hash["woeid"] }],
12
+ }
13
+ end
14
+ end
@@ -0,0 +1,70 @@
1
+ class Flickr
2
+ class Media < Object
3
+ self.attribute_values = {
4
+ uploaded_at: [->{ @hash["dateuploaded"] }, ->{ @hash["dateupload"] }],
5
+ favorite?: [->{ @hash["isfavorite"] }],
6
+ posted_at: [->{ @hash["dates"]["posted"] }],
7
+ taken_at: [->{ @hash["dates"]["taken"] }, ->{ @hash["datetaken"] }],
8
+ taken_at_granularity: [->{ @hash["dates"]["takengranularity"] }, ->{ @hash["datetakengranularity"] }],
9
+ updated_at: [->{ @hash["dates"]["lastupdate"] }, ->{ @hash["lastupdate"] }],
10
+ views_count: [->{ @hash["views"] }],
11
+ public_editability: [->{ @hash["publiceditability"] }],
12
+ comments_count: [->{ @hash["comments"]["_content"] }],
13
+ has_people?: [->{ @hash["people"]["haspeople"] }],
14
+ notes: [->{ @hash["notes"]["note"] }],
15
+ tags: [
16
+ ->{ @hash["tags"]["tag"].map { |h| h.merge("photo_id" => @hash["id"]) } },
17
+ ->{
18
+ [
19
+ *@hash["tags"].split(" ").map {|content| {"_content" => content, "machine_tag" => 0} },
20
+ *@hash["machine_tags"].split(" ").map {|content| {"_content" => content, "machine_tag" => 1} }
21
+ ]
22
+ }
23
+ ],
24
+ visibility: [->{ @hash["visibility"] }, ->{ @hash.slice("ispublic", "isfriend", "isfamily") if @hash["ispublic"] }],
25
+ title: [->{ @hash["title"]["_content"] }],
26
+ description: [->{ @hash["description"]["_content"] }],
27
+ owner: [
28
+ ->{
29
+ if @hash["owner"].is_a?(String)
30
+ {
31
+ "id" => @hash["owner"],
32
+ "username" => @hash["ownername"],
33
+ "iconserver" => @hash["iconserver"],
34
+ "iconfarm" => @hash["iconfarm"],
35
+ }
36
+ end
37
+ }
38
+ ],
39
+ path_alias: [->{ @hash["pathalias"] }],
40
+ location_visibility: [
41
+ ->{ @hash["geoperms"] },
42
+ ->{
43
+ {
44
+ "isfamily" => @hash.fetch("geo_is_family"),
45
+ "isfriend" => @hash.fetch("geo_is_friend"),
46
+ "iscontact" => @hash.fetch("geo_is_contact"),
47
+ "ispublic" => @hash.fetch("geo_is_public")
48
+ }
49
+ }
50
+ ],
51
+ location: [->{ @hash.slice("latitude", "longitude", "accuracy", "context", "place_id", "woeid") if @hash["latitude"] }],
52
+ largest_size: [->{ SIZES.key(SIZES.values.reverse.find { |abbr| @hash["url_#{abbr}"] }) }],
53
+ }
54
+
55
+ OTHER_SIZES = {
56
+ "Square 75" => "Square",
57
+ "Thumbnail" => "Thumbnail",
58
+ "Square 150" => "Large Square",
59
+ "Small 240" => "Small",
60
+ "Small 320" => "Small 320",
61
+ "Medium 500" => "Medium",
62
+ "Medium 640" => "Medium 640",
63
+ "Medium 800" => "Medium 800",
64
+ "Large 1024" => "Large",
65
+ "Large 1600" => "Large 1600",
66
+ "Large 2048" => "Large 2048",
67
+ "Original" => "Original"
68
+ }
69
+ end
70
+ end
@@ -0,0 +1,11 @@
1
+ class Flickr
2
+ class Note < Object
3
+ self.attribute_values = {
4
+ author: [->{ {"id" => @hash.fetch("author"), "username" => @hash["authorname"]} }],
5
+ coordinates: [->{ [@hash.fetch("x"), @hash.fetch("y")] }],
6
+ width: [->{ @hash["w"] }],
7
+ height: [->{ @hash["h"] }],
8
+ content: [->{ @hash["_content"] }],
9
+ }
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ class Flickr
2
+ class Permissions < Object
3
+ self.attribute_values = {
4
+ can_comment?: [->{ @hash["cancomment"] }, ->{ @hash["can_comment"] }],
5
+ can_add_meta?: [->{ @hash["canaddmeta"] }],
6
+ can_download?: [->{ @hash["candownload"] }],
7
+ can_blog?: [->{ @hash["canblog"] }],
8
+ can_print?: [->{ @hash["canprint"] }],
9
+ can_share?: [->{ @hash["canshare"] }],
10
+ }
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ class Flickr
2
+ class Person < Object
3
+ self.attribute_values = {
4
+ id: [->{ @hash["nsid"] }],
5
+ nsid: [->{ id }],
6
+ username: [->{ @hash["username"]["_content"] }],
7
+ real_name: [->{ @hash["realname"] }, ->{ @hash["realname"]["_content"] }],
8
+ icon_server: [->{ @hash["iconserver"] }],
9
+ icon_farm: [->{ @hash["iconfarm"] }],
10
+ has_pro_account?: [->{ @hash["ispro"] }],
11
+ location: [->{ @hash["location"]["_content"] }],
12
+ time_zone: [->{ @hash["timezone"] }],
13
+ description: [->{ @hash["description"]["_content"] }],
14
+ photos_url: [->{ @hash["photosurl"]["_content"] }],
15
+ profile_url: [->{ @hash["profileurl"]["_content"] }],
16
+ mobile_url: [->{ @hash["mobileurl"]["_content"] }],
17
+ first_photo_taken: [->{ @hash["photos"]["firstdatetaken"]["_content"] }],
18
+ first_photo_uploaded: [->{ @hash["photos"]["firstdate"]["_content"] }],
19
+ photos_count: [->{ @hash["photos"]["count"]["_content"] }],
20
+ photo_views_count: [->{ @hash["photos"]["views"]["_content"] }],
21
+ }
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ class Flickr
2
+ class Photo < Media
3
+ self.attribute_values = attribute_values.merge(
4
+ rotation: [->{ @hash["rotation"] }],
5
+ source_url: [
6
+ ->{ @hash["url_#{SIZES[size]}"] },
7
+ ->{ @hash["size"].find { |hash| hash["label"] == OTHER_SIZES[size] }["source"] }
8
+ ],
9
+ height: [
10
+ ->{ @hash["height_#{SIZES[size]}"] },
11
+ ->{ @hash["size"].find { |hash| hash["label"] == OTHER_SIZES[size] }["height"] }
12
+ ],
13
+ width: [
14
+ ->{ @hash["width_#{SIZES[size]}"] },
15
+ ->{ @hash["size"].find { |hash| hash["label"] == OTHER_SIZES[size] }["width"] }
16
+ ],
17
+ )
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ class Flickr
2
+ class Set < Object
3
+ self.attribute_values = {
4
+ owner: [-> { {"id" => @hash.fetch("owner"), "username" => @hash["username"]} }],
5
+ url: [-> { "http://www.flickr.com/photos/#{owner.id}/sets/#{id}/" }],
6
+ media_count: [-> { @hash["photos"] }],
7
+ views_count: [-> { @hash["count_views"] }],
8
+ comments_count: [-> { @hash["count_comments"] }],
9
+ photos_count: [-> { @hash["count_photos"] }, -> { @hash["photos"] }],
10
+ videos_count: [-> { @hash["count_videos"] }, -> { @hash["videos"] }],
11
+ title: [-> { @hash["title"]["_content"] }],
12
+ description: [-> { @hash["description"]["_content"] }],
13
+ permissions: [-> { @hash.slice("can_comment") }],
14
+ created_at: [-> { @hash["date_create"] }],
15
+ updated_at: [-> { @hash["date_update"] }],
16
+ primary_media: [-> { {"id" => @hash.fetch("primary")} }],
17
+ primary_photo: [-> { {"id" => @hash.fetch("primary")} }],
18
+ primary_video: [-> { {"id" => @hash.fetch("primary")} }],
19
+ }
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ class Flickr
2
+ class Tag < Object
3
+ self.attribute_values = {
4
+ author: [->{ {"id" => @hash.fetch("author")} }],
5
+ content: [->{ @hash["_content"] }],
6
+ machine_tag?: [->{ @hash["machine_tag"] }],
7
+ }
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class Flickr
2
+ class UploadTicket < Object
3
+ self.attribute_values = {
4
+ status: [->{ @hash["complete"] }],
5
+ invalid?: [->{ @hash["invalid"] || 0 }],
6
+ media: [->{ {"id" => @hash.fetch("photoid")} }],
7
+ photo: [->{ {"id" => @hash.fetch("photoid")} }],
8
+ video: [->{ {"id" => @hash.fetch("photoid")} }],
9
+ }
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ class Flickr
2
+ class Video < Media
3
+ self.attribute_values = attribute_values.merge(
4
+ ready?: [->{ @hash["video"]["ready"] }],
5
+ failed?: [->{ @hash["video"]["failed"] }],
6
+ pending?: [->{ @hash["video"]["pending"] }],
7
+ duration: [->{ @hash["video"]["duration"] }],
8
+ width: [->{ @hash["video"]["width"] }],
9
+ height: [->{ @hash["video"]["height"] }],
10
+ thumbnail_url: [
11
+ ->(size){ @hash["url_#{SIZES[size]}"] },
12
+ ->(size){ @hash["size"].find { |hash| hash["label"] == OTHER_SIZES[size] }["source"] }
13
+ ],
14
+ thumbnail_width: [
15
+ ->(size){ @hash["width_#{SIZES[size]}"] },
16
+ ->(size){ @hash["size"].find { |hash| hash["label"] == OTHER_SIZES[size] }["width"] }
17
+ ],
18
+ thumbnail_height: [
19
+ ->(size){ @hash["height_#{SIZES[size]}"] },
20
+ ->(size){ @hash["size"].find { |hash| hash["label"] == OTHER_SIZES[size] }["height"] }
21
+ ],
22
+ source_url: [->{ @hash["size"].find { |hash| hash["label"] == "Video Player" }["source"] }],
23
+ download_url: [->{ @hash["size"].find { |hash| hash["label"] == "Site MP4" }["source"] }],
24
+ mobile_download_url: [->{ @hash["size"].find { |hash| hash["label"] == "Mobile MP4" }["source"] }],
25
+ )
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ class Flickr
2
+ class Visibility < Object
3
+ self.attribute_values = {
4
+ public?: [->{ @hash["ispublic"] }],
5
+ friends?: [->{ @hash["isfriend"] }],
6
+ family?: [->{ @hash["isfamily"] }],
7
+ contacts?: [->{ @hash["iscontact"] }],
8
+ }
9
+ end
10
+ end