flickr-objects 0.0.2 → 0.1.0

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 (63) hide show
  1. data/README.md +55 -85
  2. data/lib/flickr/api/api_methods/flickr.rb +0 -1
  3. data/lib/flickr/api/api_methods/person.rb +3 -3
  4. data/lib/flickr/api/api_methods/photo.rb +12 -1
  5. data/lib/flickr/api/api_methods/set.rb +6 -5
  6. data/lib/flickr/api/flickr.rb +9 -9
  7. data/lib/flickr/api/person.rb +13 -29
  8. data/lib/flickr/api/photo.rb +51 -4
  9. data/lib/flickr/api/set.rb +20 -25
  10. data/lib/flickr/api/upload_ticket.rb +4 -2
  11. data/lib/flickr/api.rb +0 -2
  12. data/lib/flickr/api_caller.rb +5 -11
  13. data/lib/flickr/client/upload_client.rb +4 -16
  14. data/lib/flickr/client.rb +1 -1
  15. data/lib/flickr/configuration.rb +2 -0
  16. data/lib/flickr/errors.rb +19 -0
  17. data/lib/flickr/middleware.rb +63 -0
  18. data/lib/flickr/oauth.rb +109 -0
  19. data/lib/flickr/object/attribute/finder.rb +2 -2
  20. data/lib/flickr/object/attribute.rb +8 -8
  21. data/lib/flickr/object.rb +13 -2
  22. data/lib/flickr/objects/attribute_values/{collection.rb → list.rb} +1 -1
  23. data/lib/flickr/objects/attribute_values/photo.rb +81 -16
  24. data/lib/flickr/objects/attribute_values/set.rb +1 -5
  25. data/lib/flickr/objects/attribute_values/upload_ticket.rb +3 -5
  26. data/lib/flickr/objects/list.rb +86 -0
  27. data/lib/flickr/objects/location.rb +2 -0
  28. data/lib/flickr/objects/note.rb +3 -1
  29. data/lib/flickr/objects/permissions.rb +2 -0
  30. data/lib/flickr/objects/person.rb +8 -5
  31. data/lib/flickr/objects/photo.rb +98 -30
  32. data/lib/flickr/objects/set.rb +4 -5
  33. data/lib/flickr/objects/tag.rb +2 -0
  34. data/lib/flickr/objects/upload_ticket.rb +8 -6
  35. data/lib/flickr/objects/visibility.rb +2 -0
  36. data/lib/flickr/objects.rb +2 -7
  37. data/lib/flickr/version.rb +1 -1
  38. data/lib/flickr.rb +5 -0
  39. metadata +60 -32
  40. data/lib/flickr/api/api_methods/collection.rb +0 -4
  41. data/lib/flickr/api/api_methods/location.rb +0 -4
  42. data/lib/flickr/api/api_methods/media.rb +0 -14
  43. data/lib/flickr/api/api_methods/note.rb +0 -4
  44. data/lib/flickr/api/api_methods/permissions.rb +0 -4
  45. data/lib/flickr/api/api_methods/tag.rb +0 -4
  46. data/lib/flickr/api/api_methods/video.rb +0 -4
  47. data/lib/flickr/api/api_methods/visibility.rb +0 -4
  48. data/lib/flickr/api/collection.rb +0 -4
  49. data/lib/flickr/api/location.rb +0 -4
  50. data/lib/flickr/api/media.rb +0 -52
  51. data/lib/flickr/api/note.rb +0 -4
  52. data/lib/flickr/api/permissions.rb +0 -4
  53. data/lib/flickr/api/tag.rb +0 -4
  54. data/lib/flickr/api/video.rb +0 -11
  55. data/lib/flickr/api/visibility.rb +0 -4
  56. data/lib/flickr/client/middleware/retry.rb +0 -29
  57. data/lib/flickr/client/middleware.rb +0 -42
  58. data/lib/flickr/helpers/inheritable_attr_accessor.rb +0 -18
  59. data/lib/flickr/objects/attribute_values/media.rb +0 -70
  60. data/lib/flickr/objects/attribute_values/video.rb +0 -27
  61. data/lib/flickr/objects/collection.rb +0 -56
  62. data/lib/flickr/objects/media.rb +0 -72
  63. data/lib/flickr/objects/video.rb +0 -21
@@ -1,42 +0,0 @@
1
- require "cgi"
2
- require "flickr/client/middleware/retry"
3
-
4
- class Flickr
5
- class Client < Faraday::Connection
6
- module Middleware
7
- class CheckOAuth < Faraday::Response::Middleware
8
- def on_complete(env)
9
- if env[:status] != 200
10
- message = CGI.parse(env[:body])["oauth_problem"].first
11
- pretty_message = message.gsub('_', ' ').capitalize
12
- raise OAuthError, pretty_message
13
- end
14
- end
15
- end
16
-
17
- class CheckStatus < Faraday::Response::Middleware
18
- def on_complete(env)
19
- env[:body] = env[:body]["rsp"] || env[:body]
20
-
21
- if env[:body]["stat"] != "ok"
22
- message = env[:body]["message"] || env[:body]["err"]["msg"]
23
- code = env[:body]["code"] || env[:body]["err"]["code"]
24
- raise Error.new(message, code)
25
- end
26
- end
27
- end
28
- end
29
-
30
- class OAuthError < ArgumentError
31
- end
32
-
33
- class Error < StandardError
34
- attr_reader :code
35
-
36
- def initialize(message, code = nil)
37
- super(message)
38
- @code = code.to_i
39
- end
40
- end
41
- end
42
- end
@@ -1,18 +0,0 @@
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
@@ -1,70 +0,0 @@
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
@@ -1,27 +0,0 @@
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
@@ -1,56 +0,0 @@
1
- class Flickr
2
- class Collection < Object
3
- include Enumerable
4
-
5
- attribute :current_page, Integer
6
- attribute :per_page, Integer
7
- attribute :total_pages, Integer
8
- attribute :total_entries, Integer
9
-
10
- def initialize(collection, klass, hash, client)
11
- unless klass == Media
12
- objects = collection.map! do |hash|
13
- klass.new(hash, client)
14
- end
15
- else
16
- objects = collection.map! do |hash|
17
- klass = Flickr.const_get(hash["media"].capitalize)
18
- klass.new(hash, client)
19
- end
20
- end
21
-
22
- @hash = hash
23
- @objects = objects
24
- end
25
-
26
- def find(id = nil)
27
- if block_given?
28
- super
29
- else
30
- if id.is_a?(Array)
31
- ids = id.map(&:to_s)
32
- select { |object| ids.include?(object.id) }
33
- else
34
- super() { |object| object.id == id.to_s }
35
- end
36
- end
37
- end
38
-
39
- def each(&block)
40
- @objects.each(&block)
41
- end
42
-
43
- def empty?
44
- @objects.empty?
45
- end
46
-
47
- def select!(*args, &block)
48
- @objects.select!(*args, &block)
49
- self
50
- end
51
-
52
- def select(*args, &block)
53
- dup.select!(*args, &block)
54
- end
55
- end
56
- end
@@ -1,72 +0,0 @@
1
- require "flickr/helpers/base_58"
2
-
3
- class Flickr
4
- class Media < Object
5
- include Base58
6
-
7
- attribute :id, String
8
- attribute :secret, String
9
- attribute :server, String
10
- attribute :farm, Integer
11
- attribute :title, String
12
- attribute :description, String
13
- attribute :license, Integer
14
- attribute :visibility, Visibility
15
- attribute :safety_level, Integer
16
-
17
- attribute :owner, Person
18
-
19
- attribute :uploaded_at, Time
20
- attribute :posted_at, Time
21
- attribute :taken_at, Time
22
- attribute :taken_at_granularity, Integer
23
- attribute :updated_at, Time
24
-
25
- attribute :views_count, Integer
26
- attribute :comments_count, Integer
27
-
28
- attribute :editability, Permissions
29
- attribute :public_editability, Permissions
30
- attribute :usage, Permissions
31
-
32
- attribute :notes, Array(Note)
33
- attribute :tags, Array(Tag)
34
-
35
- attribute :has_people?, Boolean
36
- attribute :favorite?, Boolean
37
-
38
- attribute :path_alias
39
-
40
- attribute :location, Location
41
- attribute :location_visibility, Visibility
42
-
43
- attribute :largest_size, String
44
-
45
- SIZES = {
46
- "Square 75" => "sq",
47
- "Thumbnail" => "t",
48
- "Square 150" => "q",
49
- "Small 240" => "s",
50
- "Small 320" => "n",
51
- "Medium 500" => "m",
52
- "Medium 640" => "z",
53
- "Medium 800" => "c",
54
- "Large 1024" => "l",
55
- "Large 1600" => "h",
56
- "Large 2048" => "k",
57
- "Original" => "o"
58
- }
59
-
60
- def safe?; safety_level <= 1 end
61
- def moderate?; safety_level == 2 end
62
- def restricted?; safety_level == 3 end
63
-
64
- def url
65
- "http://www.flickr.com/photos/#{owner.id}/#{id}/" if owner
66
- end
67
-
68
- def short_url
69
- "http://flic.kr/p/#{to_base58(id)}"
70
- end
71
- end
72
- end
@@ -1,21 +0,0 @@
1
- class Flickr
2
- class Video < Media
3
-
4
- attribute :ready?, Boolean
5
- attribute :failed?, Boolean
6
- attribute :pending?, Boolean
7
-
8
- attribute :duration, Integer
9
- attribute :width, Integer
10
- attribute :height, Integer
11
-
12
- attribute :thumbnail_url, String
13
- attribute :thumbnail_width, Integer
14
- attribute :thumbnail_height, Integer
15
-
16
- attribute :source_url, String
17
- attribute :download_url, String
18
- attribute :mobile_download_url, String
19
-
20
- end
21
- end