flickraw_objects 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +55 -0
- data/lib/flickraw_objects.rb +115 -0
- data/lib/flickraw_objects.rb~ +119 -0
- data/lib/flickraw_objects/attributes.rb +67 -0
- data/lib/flickraw_objects/attributes.rb~ +70 -0
- data/lib/flickraw_objects/version.rb +3 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: df7408e7add3e776767afd2eca89d358acca1dd0
|
4
|
+
data.tar.gz: 78a0f0d0149323c9b0f08d5911a0a71bfe91d84f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fb5dbad31880564a5b5b01aece7d02a2527efafc5a609466380f9e44e81d9221f554754792c579b70a3c8bfd9cfb4524d0391f12e32ea69e8644aa82fa8899a4
|
7
|
+
data.tar.gz: 3218518629387806727fd88793a76950dc2d71fda8edf2f84e612317eb92d894096d2c8b7197252d5e42063fd4cef5c47c32af874321f78b6d6ee9c65878caee
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# FlickrawObjects
|
2
|
+
|
3
|
+
Use this gem as a simple way to map Flickraw results to a object-orientated "data model".
|
4
|
+
Classes for People and Photos are included: These are there by way of an example. I anticipate
|
5
|
+
users of this Gem will map the data they need - it's easy to do.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'flickraw_objects'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install flickraw_objects
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Create an initializer where you set your Flickr credentials.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
FlickrawObjects.configure do |config|
|
27
|
+
config.api_key = "Your Api Key"
|
28
|
+
config.shared_secret = "Shared Secret"
|
29
|
+
end
|
30
|
+
```
|
31
|
+
If you don't have them yet, you can apply for them [here](http://www.flickr.com/services/apps/create/apply).
|
32
|
+
|
33
|
+
|
34
|
+
Example usage:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
person = FlickrawObjects::Person.find_by_username "chrisfield1968"
|
38
|
+
puts "realname: #{person.realname}" # get_info api call happens automatically
|
39
|
+
|
40
|
+
puts "photos_count #{person.photos_count}" # returns as an Integer
|
41
|
+
puts "person.first_date_taken #{person.first_date_taken}" # returns as a Date
|
42
|
+
puts "professional?: #{person.professional?}" # returns as a true/false
|
43
|
+
|
44
|
+
person.get_photos.each_with_index do |item,i|
|
45
|
+
puts "item #{i}: #{item.title} - #{item.url} - #{item.public?}"
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it ( http://github.com/<my-github-username>/flickraw_objects/fork )
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create new Pull Request
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require "flickraw_objects/version"
|
2
|
+
require "flickraw_objects/attributes"
|
3
|
+
require "flickraw"
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
module FlickrawObjects
|
7
|
+
|
8
|
+
class Person
|
9
|
+
include Attributes
|
10
|
+
|
11
|
+
def self.find_by_username(username)
|
12
|
+
response = flickr.people.findByUsername username: username
|
13
|
+
Person.new(response)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_photos(params = {})
|
17
|
+
result = Array.new
|
18
|
+
response = flickr.people.getPhotos user_id: id
|
19
|
+
response.each do |photo|
|
20
|
+
result << Photo.new(photo)
|
21
|
+
end
|
22
|
+
result
|
23
|
+
end
|
24
|
+
alias photos get_photos
|
25
|
+
|
26
|
+
def get_photosets(params = {})
|
27
|
+
result = Array.new
|
28
|
+
response = flickr.photosets.getList user_id: id
|
29
|
+
response.each do |photoset|
|
30
|
+
result << Photoset.new(photoset)
|
31
|
+
end
|
32
|
+
result
|
33
|
+
end
|
34
|
+
alias photosets get_photosets
|
35
|
+
|
36
|
+
def get_info
|
37
|
+
@get_info ||= flickr.people.getInfo user_id: id
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
attribute :id
|
42
|
+
attribute :username
|
43
|
+
|
44
|
+
attribute_source :get_info
|
45
|
+
attribute :realname, path: [:realname]
|
46
|
+
attribute :photos_count, type: Integer, path: [:photos, :count]
|
47
|
+
attribute :professional, type: Boolean, path: [:ispro]
|
48
|
+
attribute :first_date_taken ,type: Time, path: [:photos, :firstdatetaken]
|
49
|
+
attribute :first_date, type: Time, path: [:firstdate]
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
class Photoset
|
54
|
+
include Attributes
|
55
|
+
|
56
|
+
def get_photos(params = {})
|
57
|
+
result = Array.new
|
58
|
+
response = flickr.photosets.getPhotos(photoset_id: id)
|
59
|
+
response["photo"].each do |photo|
|
60
|
+
result << Photo.new(photo)
|
61
|
+
end
|
62
|
+
result
|
63
|
+
end
|
64
|
+
|
65
|
+
alias photos get_photos
|
66
|
+
|
67
|
+
def get_info
|
68
|
+
@get_info ||= flickr.photosets.getInfo photoset_id: id
|
69
|
+
end
|
70
|
+
|
71
|
+
attribute :id
|
72
|
+
attribute :title
|
73
|
+
attribute :description
|
74
|
+
|
75
|
+
attribute_source :get_info
|
76
|
+
attribute :primary
|
77
|
+
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
class Photo
|
82
|
+
include Attributes
|
83
|
+
attribute :id
|
84
|
+
attribute :owner
|
85
|
+
attribute :secret
|
86
|
+
attribute :server
|
87
|
+
attribute :farm
|
88
|
+
attribute :title
|
89
|
+
attribute :public, type: Boolean, path: [:ispublic]
|
90
|
+
attribute :friend, type: Boolean, path: [:isfriend]
|
91
|
+
attribute :family, type: Boolean, path: [:isfamily]
|
92
|
+
|
93
|
+
def url_medium
|
94
|
+
FlickRaw.url(init)
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.url(letter, meaning)
|
98
|
+
define_method("url_#{meaning}") do
|
99
|
+
FlickRaw.send("url_#{letter}", init)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
url :s , :square
|
104
|
+
url :q , :large_square
|
105
|
+
url :t , :thumbnail
|
106
|
+
url :m , :small
|
107
|
+
url :n , :small_320
|
108
|
+
url :z , :medium_640
|
109
|
+
url :c , :medium_800
|
110
|
+
url :b , :large
|
111
|
+
url :o , :original
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require "flickraw_objects/version"
|
2
|
+
require 'date'
|
3
|
+
require "flickraw_objects/configuration"
|
4
|
+
require "flickraw_objects/attributes"
|
5
|
+
|
6
|
+
module FlickrawObjects
|
7
|
+
|
8
|
+
class Person
|
9
|
+
include Attributes
|
10
|
+
|
11
|
+
def self.find_by_username(username)
|
12
|
+
response = flickr.people.findByUsername username: username
|
13
|
+
Person.new(response)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_info
|
17
|
+
@get_info ||= flickr.people.getInfo user_id: id
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_photos
|
21
|
+
result = Array.new
|
22
|
+
response = flickr.people.getPhotos user_id: id
|
23
|
+
response.each do |photo|
|
24
|
+
result << Photo.new(photo)
|
25
|
+
end
|
26
|
+
result
|
27
|
+
end
|
28
|
+
alias photos get_photos
|
29
|
+
|
30
|
+
def get_photosets
|
31
|
+
PhotoSet.list(id)
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
attribute :id
|
36
|
+
attribute :username
|
37
|
+
|
38
|
+
attribute_source :get_info
|
39
|
+
attribute :realname, path: [:realname]
|
40
|
+
attribute :photos_count, type: Integer, path: [:photos, :count]
|
41
|
+
attribute :professional, type: Boolean, path: [:ispro]
|
42
|
+
attribute :first_date_taken ,type: Time, path: [:photos, :firstdatetaken]
|
43
|
+
attribute :first_date, type: Time, path: [:firstdate]
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
class PhotoSet
|
48
|
+
include Attributes
|
49
|
+
|
50
|
+
def self.list(user_id)
|
51
|
+
result = Array.new
|
52
|
+
response = flickr.photosets.getList user_id: user_id
|
53
|
+
response.each do |item|
|
54
|
+
result << PhotoSet.new(item)
|
55
|
+
end
|
56
|
+
result
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.find(photoset_id)
|
60
|
+
info = flickr.photosets.getInfo photoset_id: photoset_id
|
61
|
+
result = PhotoSet.new(info)
|
62
|
+
result.get_info = info
|
63
|
+
result
|
64
|
+
end
|
65
|
+
|
66
|
+
attr_writer :get_info
|
67
|
+
def get_info
|
68
|
+
@get_info ||= flickr.photosets.getInfo photoset_id: id
|
69
|
+
end
|
70
|
+
|
71
|
+
def get_photos
|
72
|
+
result = Array.new
|
73
|
+
response = flickr.photosets.getPhotos photoset_id: id
|
74
|
+
puts response.inspect
|
75
|
+
response.photo.each do |photo|
|
76
|
+
result << Photo.new(photo)
|
77
|
+
end
|
78
|
+
result
|
79
|
+
end
|
80
|
+
alias photos get_photos
|
81
|
+
|
82
|
+
attribute :id
|
83
|
+
attribute :primary
|
84
|
+
attribute :secret
|
85
|
+
attribute :server
|
86
|
+
attribute :photos_count, type: Integer, path: [:count_photos]
|
87
|
+
attribute :views_count, type: Integer, path: [:count_views]
|
88
|
+
attribute :comments_count, type: Integer, path: [:count_comments]
|
89
|
+
attribute :videos_count, type: Integer, path: [:count_videos]
|
90
|
+
attribute :can_comment, type: Boolean
|
91
|
+
attribute :created, type: Time, path: [:date_create]
|
92
|
+
attribute :updated, type: Time, path: [:date_update]
|
93
|
+
attribute :title
|
94
|
+
attribute :description
|
95
|
+
|
96
|
+
attribute_source :get_info
|
97
|
+
attribute :owner
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
class Photo
|
102
|
+
include Attributes
|
103
|
+
attribute :id
|
104
|
+
attribute :owner
|
105
|
+
attribute :secret
|
106
|
+
attribute :server
|
107
|
+
attribute :farm
|
108
|
+
attribute :title
|
109
|
+
attribute :public, type: Boolean, path: [:ispublic]
|
110
|
+
attribute :friend, type: Boolean, path: [:isfriend]
|
111
|
+
attribute :family, type: Boolean, path: [:isfamily]
|
112
|
+
|
113
|
+
def url
|
114
|
+
"http://farm#{farm}.staticflickr.com/#{server}/#{id}_#{secret}.jpg"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module FlickrawObjects
|
2
|
+
|
3
|
+
module Attributes
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
module Boolean
|
9
|
+
end
|
10
|
+
|
11
|
+
COERCIONS = {
|
12
|
+
String => lambda { |value| String(value) },
|
13
|
+
Boolean => lambda { |value| Integer(value) == 1 },
|
14
|
+
Integer => lambda { |value| Integer(value) },
|
15
|
+
Float => lambda { |value| Float(value) },
|
16
|
+
Time => lambda { |value|
|
17
|
+
begin
|
18
|
+
Time.at(Integer(value))
|
19
|
+
rescue
|
20
|
+
DateTime.parse(value).to_time
|
21
|
+
end
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
module ClassMethods
|
26
|
+
|
27
|
+
def attribute_source(value)
|
28
|
+
@attribute_source = value
|
29
|
+
end
|
30
|
+
|
31
|
+
def attribute(name, type: nil, path: [])
|
32
|
+
source = "@#{(@attribute_source || :init)}"
|
33
|
+
define_method(name) do
|
34
|
+
response = instance_variable_get(source)
|
35
|
+
if path.empty?
|
36
|
+
value = response.send name
|
37
|
+
else
|
38
|
+
value = path.inject(response) {|result, element| result.send element}
|
39
|
+
end
|
40
|
+
COERCIONS.fetch(type || String).call(value)
|
41
|
+
end
|
42
|
+
alias_method "#{name}?", name if type == Boolean
|
43
|
+
if @attribute_source
|
44
|
+
alias_method_chain(@attribute_source, name)
|
45
|
+
end
|
46
|
+
|
47
|
+
name
|
48
|
+
end
|
49
|
+
|
50
|
+
def alias_method_chain(first_method, second_method)
|
51
|
+
define_method("#{second_method}_with_#{first_method}") do
|
52
|
+
method(first_method).call
|
53
|
+
method("#{second_method}_without_#{first_method}").call
|
54
|
+
end
|
55
|
+
alias_method "#{second_method}_without_#{first_method}", second_method
|
56
|
+
alias_method second_method, "#{second_method}_with_#{first_method}"
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
attr_reader :init
|
62
|
+
|
63
|
+
def initialize(response)
|
64
|
+
@init = response
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module FlickrawObjects
|
2
|
+
|
3
|
+
module Attributes
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
module Boolean
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
|
13
|
+
def attribute_source(value)
|
14
|
+
@attribute_source = value
|
15
|
+
end
|
16
|
+
|
17
|
+
COERCIONS = {
|
18
|
+
Boolean => lambda { |value| Integer(value) == 1 },
|
19
|
+
Integer => lambda { |value| Integer(value) },
|
20
|
+
Float => lambda { |value| Float(value) },
|
21
|
+
Time =>
|
22
|
+
lambda { |value|
|
23
|
+
begin
|
24
|
+
Time.at(Integer(value))
|
25
|
+
rescue
|
26
|
+
DateTime.parse(value).to_time
|
27
|
+
end
|
28
|
+
},
|
29
|
+
String => lambda { |value| String(value) }
|
30
|
+
}
|
31
|
+
|
32
|
+
def attribute(name, type: nil, path: [])
|
33
|
+
source = "@#{(@attribute_source || :init)}"
|
34
|
+
coercion = COERCIONS.fetch(type || String)
|
35
|
+
|
36
|
+
define_method(name) do
|
37
|
+
response = instance_variable_get(source)
|
38
|
+
if path.empty?
|
39
|
+
value = response.send name
|
40
|
+
else
|
41
|
+
value = path.inject(response) {|result, element| result.send element}
|
42
|
+
end
|
43
|
+
coercion.call(value)
|
44
|
+
end
|
45
|
+
if @attribute_source
|
46
|
+
alias_method_chain(@attribute_source, name)
|
47
|
+
end
|
48
|
+
alias_method "#{name}?", name if type == Boolean
|
49
|
+
|
50
|
+
name
|
51
|
+
end
|
52
|
+
|
53
|
+
def alias_method_chain(first_method, second_method)
|
54
|
+
define_method("#{second_method}_with_#{first_method}") do
|
55
|
+
method(first_method).call
|
56
|
+
method("#{second_method}_without_#{first_method}").call
|
57
|
+
end
|
58
|
+
alias_method "#{second_method}_without_#{first_method}", second_method
|
59
|
+
alias_method second_method, "#{second_method}_with_#{first_method}"
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
attr_reader :init
|
65
|
+
|
66
|
+
def initialize(response)
|
67
|
+
@init = response
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flickraw_objects
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Field
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: flickraw
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: "Use this gem as a simple way to use Flickraw but with an object-orientated
|
56
|
+
\"data model\".\n Classes for Person, Photoset and Photos are included. I anticipate
|
57
|
+
\n users of this Gem will map other data they need. It's easy to do."
|
58
|
+
email:
|
59
|
+
- chris@christopherfield.co.uk
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- README.md
|
65
|
+
- lib/flickraw_objects.rb
|
66
|
+
- lib/flickraw_objects.rb~
|
67
|
+
- lib/flickraw_objects/attributes.rb
|
68
|
+
- lib/flickraw_objects/attributes.rb~
|
69
|
+
- lib/flickraw_objects/version.rb
|
70
|
+
homepage: https://github.com/chrisfield/flickraw_objects
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.2.1
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: A slim, customisable object-oriented Flickr api that uses flickraw to do
|
94
|
+
all the communication.
|
95
|
+
test_files: []
|
96
|
+
has_rdoc:
|