rb-lomo 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 +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +63 -0
- data/Rakefile +10 -0
- data/lib/rb-lomo/camera.rb +15 -0
- data/lib/rb-lomo/film.rb +15 -0
- data/lib/rb-lomo/photo.rb +93 -0
- data/lib/rb-lomo/user.rb +36 -0
- data/lib/rb-lomo/version.rb +5 -0
- data/lib/rb-lomo.rb +93 -0
- data/test/unit/camera.rb +8 -0
- data/test/unit/film.rb +8 -0
- data/test/unit/photo.rb +12 -0
- metadata +84 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Gary Rafferty
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Rb::Lomo
|
2
|
+
|
3
|
+
This is a v1 Ruby wrapper for most of the lomography.com API.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'rb-lomo'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install rb-lomo
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
### Instantiate the client using your API-KEY
|
23
|
+
|
24
|
+
client = Rb::Lomo::Client.new('YOUR-API-KEY')
|
25
|
+
|
26
|
+
Currently, you need to request an API key from Lomography.
|
27
|
+
Emailing markus@lomography.com should hook you up with one.
|
28
|
+
|
29
|
+
### Call methods on the client
|
30
|
+
|
31
|
+
client.popular_photos.last.user.username
|
32
|
+
|
33
|
+
client.popular_photos.last.small_asset_url
|
34
|
+
|
35
|
+
client.cameras.last
|
36
|
+
|
37
|
+
client.popular_camera_photos(3314883).last
|
38
|
+
|
39
|
+
client.recent_camera_photos(3314883).last
|
40
|
+
|
41
|
+
client.recent_photos.first
|
42
|
+
|
43
|
+
client.selected_photos.last
|
44
|
+
|
45
|
+
client.films.last
|
46
|
+
|
47
|
+
client.popular_film_photos(871911028).last
|
48
|
+
|
49
|
+
client.recent_film_photos(871911028).last
|
50
|
+
|
51
|
+
## Todo
|
52
|
+
|
53
|
+
Write some tests,.... preferable using MiniTest.
|
54
|
+
|
55
|
+
Build a sample application to show the gem usage.
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
1. Fork it
|
60
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
61
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
62
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
63
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/rb-lomo/film.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
module Rb
|
2
|
+
module Lomo
|
3
|
+
class Photo
|
4
|
+
##
|
5
|
+
# The ID attribute of the Photo
|
6
|
+
attr_reader :id
|
7
|
+
|
8
|
+
##
|
9
|
+
# The title attribute of the Photo
|
10
|
+
attr_reader :title
|
11
|
+
|
12
|
+
##
|
13
|
+
# The description attribute of the Photo
|
14
|
+
attr_reader :description
|
15
|
+
|
16
|
+
##
|
17
|
+
# The URL attribute of the Photo
|
18
|
+
attr_reader :url
|
19
|
+
|
20
|
+
##
|
21
|
+
# The camera attributes of the Photo
|
22
|
+
# @return Camera object
|
23
|
+
attr_reader :camera
|
24
|
+
|
25
|
+
##
|
26
|
+
# The film attribute of the Photo
|
27
|
+
# @return Film object
|
28
|
+
attr_reader :film
|
29
|
+
|
30
|
+
##
|
31
|
+
# The user attribute of the Photo
|
32
|
+
# @return User object
|
33
|
+
attr_reader :user
|
34
|
+
|
35
|
+
##
|
36
|
+
# Expects a JSON object
|
37
|
+
def initialize json
|
38
|
+
@json = json
|
39
|
+
@id = @json['id']
|
40
|
+
@title = @json['title']
|
41
|
+
@description= @json['description']
|
42
|
+
@url = @json['url']
|
43
|
+
@user = User.new @json['user']
|
44
|
+
|
45
|
+
if @json['camera']
|
46
|
+
@camera = Camera.new @json['camera']
|
47
|
+
end
|
48
|
+
|
49
|
+
if @json['film']
|
50
|
+
@film = Film.new @json['film']
|
51
|
+
end
|
52
|
+
|
53
|
+
if @json['longitude'] && @json['latitude']
|
54
|
+
@longitude = @json['location']['longitude']
|
55
|
+
@latitude = @json['location']['latitude']
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def location
|
60
|
+
|
61
|
+
if @longitude && @latitude
|
62
|
+
{
|
63
|
+
longitude: @longitude,
|
64
|
+
latitude: @latitude
|
65
|
+
}
|
66
|
+
else
|
67
|
+
'Location unknown'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def small_asset_url
|
72
|
+
@json['assets']['small']['url']
|
73
|
+
end
|
74
|
+
|
75
|
+
def large_asset_url
|
76
|
+
@json['assets']['large']['url']
|
77
|
+
end
|
78
|
+
|
79
|
+
def size
|
80
|
+
{
|
81
|
+
small: {
|
82
|
+
width: @json['assets']['small']['width'],
|
83
|
+
height: @json['assets']['small']['height']
|
84
|
+
},
|
85
|
+
large: {
|
86
|
+
width: @json['assets']['large']['width'],
|
87
|
+
height: @json['assets']['large']['height']
|
88
|
+
}
|
89
|
+
}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/lib/rb-lomo/user.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Rb
|
2
|
+
module Lomo
|
3
|
+
class User
|
4
|
+
|
5
|
+
attr_reader :username
|
6
|
+
|
7
|
+
attr_reader :url
|
8
|
+
|
9
|
+
attr_reader :avatar
|
10
|
+
|
11
|
+
def initialize json_object
|
12
|
+
@username = json_object['username']
|
13
|
+
@url = json_object['url']
|
14
|
+
@avatar = Avatar.new json_object['avatar']
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Avatar
|
19
|
+
|
20
|
+
attr_reader :url
|
21
|
+
|
22
|
+
def initialize json_object
|
23
|
+
@url = json_object['url']
|
24
|
+
@width = json_object['width']
|
25
|
+
@height= json_object['height']
|
26
|
+
end
|
27
|
+
|
28
|
+
def size
|
29
|
+
{
|
30
|
+
width: @width,
|
31
|
+
height: @height
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/rb-lomo.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require "rb-lomo/version"
|
2
|
+
require "rb-lomo/camera"
|
3
|
+
require "rb-lomo/photo"
|
4
|
+
require "rb-lomo/film"
|
5
|
+
require "rb-lomo/user"
|
6
|
+
|
7
|
+
require 'rest_client'
|
8
|
+
require 'json'
|
9
|
+
require 'pp'
|
10
|
+
|
11
|
+
module Rb
|
12
|
+
module Lomo
|
13
|
+
|
14
|
+
API_BASE = 'http://api.lomography.com/v1'
|
15
|
+
|
16
|
+
class Client
|
17
|
+
|
18
|
+
def initialize api_key
|
19
|
+
@api_key = api_key
|
20
|
+
end
|
21
|
+
|
22
|
+
def photos_from url
|
23
|
+
resp = RestClient.get("#{API_BASE}/#{url}", params: { api_key: @api_key})
|
24
|
+
json = JSON.parse resp
|
25
|
+
|
26
|
+
retval = []
|
27
|
+
json['photos'].each {|p| retval << Photo.new(p)}
|
28
|
+
|
29
|
+
retval
|
30
|
+
end
|
31
|
+
|
32
|
+
def cameras_from url
|
33
|
+
resp = RestClient.get("#{API_BASE}/#{url}", params: { api_key: @api_key})
|
34
|
+
json = JSON.parse resp
|
35
|
+
|
36
|
+
retval = []
|
37
|
+
json['cameras'].each {|c| retval << Camera.new(c)}
|
38
|
+
|
39
|
+
retval
|
40
|
+
end
|
41
|
+
|
42
|
+
def films_from url
|
43
|
+
resp = RestClient.get("#{API_BASE}/#{url}", params: { api_key: @api_key})
|
44
|
+
json = JSON.parse resp
|
45
|
+
|
46
|
+
retval = []
|
47
|
+
json['films'].each {|f| retval << Film.new(f)}
|
48
|
+
|
49
|
+
retval
|
50
|
+
end
|
51
|
+
|
52
|
+
def popular_photos
|
53
|
+
photos_from '/photos/popular'
|
54
|
+
end
|
55
|
+
|
56
|
+
def recent_photos
|
57
|
+
photos_from '/photos/recent'
|
58
|
+
end
|
59
|
+
|
60
|
+
def selected_photos
|
61
|
+
photos_from 'photos/selected'
|
62
|
+
end
|
63
|
+
|
64
|
+
def cameras
|
65
|
+
cameras_from '/cameras'
|
66
|
+
end
|
67
|
+
|
68
|
+
def camera id
|
69
|
+
cameras_from "/cameras/#{id}"
|
70
|
+
end
|
71
|
+
|
72
|
+
def popular_camera_photos id
|
73
|
+
photos_from "/cameras/#{id}/photos/popular"
|
74
|
+
end
|
75
|
+
|
76
|
+
def recent_camera_photos id
|
77
|
+
photos_from "/cameras/#{id}/photos/recent"
|
78
|
+
end
|
79
|
+
|
80
|
+
def films
|
81
|
+
films_from '/films'
|
82
|
+
end
|
83
|
+
|
84
|
+
def popular_film_photos id
|
85
|
+
photos_from "/films/#{id}/photos/popular"
|
86
|
+
end
|
87
|
+
|
88
|
+
def recent_film_photos id
|
89
|
+
photos_from "/films/#{id}/photos/recent"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/test/unit/camera.rb
ADDED
data/test/unit/film.rb
ADDED
data/test/unit/photo.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$:.unshift(File.join(File.dirname(__FILE__),'..','..','lib'))
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'rb-lomo'
|
5
|
+
|
6
|
+
class Photo < MiniTest::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@client = Rb::Lomo::Client.new('API-KEY')
|
9
|
+
@photo = @client.popular_photos.sample
|
10
|
+
end
|
11
|
+
#TODO:
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rb-lomo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gary Rafferty
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: &10138300 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *10138300
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: json
|
27
|
+
requirement: &10137860 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *10137860
|
36
|
+
description: Ruby library for the Lomography API
|
37
|
+
email:
|
38
|
+
- gary.rafferty@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- LICENSE
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- lib/rb-lomo.rb
|
49
|
+
- lib/rb-lomo/camera.rb
|
50
|
+
- lib/rb-lomo/film.rb
|
51
|
+
- lib/rb-lomo/photo.rb
|
52
|
+
- lib/rb-lomo/user.rb
|
53
|
+
- lib/rb-lomo/version.rb
|
54
|
+
- test/unit/camera.rb
|
55
|
+
- test/unit/film.rb
|
56
|
+
- test/unit/photo.rb
|
57
|
+
homepage: https://github.com/gary-rafferty/Rb-Lomo
|
58
|
+
licenses: []
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.8.11
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: This gem covers most of the functionality from the Lomography API
|
81
|
+
test_files:
|
82
|
+
- test/unit/camera.rb
|
83
|
+
- test/unit/film.rb
|
84
|
+
- test/unit/photo.rb
|