rb-lomo 0.0.1 → 0.0.2
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 +0 -1
- data/README.md +8 -2
- data/lib/rb-lomo/version.rb +1 -1
- data/lib/rb-lomo.rb +19 -32
- data/rb-lomo.gemspec +20 -0
- data/test/unit/camera.rb +12 -1
- data/test/unit/client.rb +66 -0
- data/test/unit/film.rb +12 -1
- data/test/unit/photo.rb +26 -1
- metadata +9 -6
data/README.md
CHANGED
@@ -48,9 +48,15 @@ client.popular_film_photos(871911028).last
|
|
48
48
|
|
49
49
|
client.recent_film_photos(871911028).last
|
50
50
|
|
51
|
-
##
|
51
|
+
## Testing
|
52
|
+
|
53
|
+
I've wrote up some tests using MiniTest.
|
54
|
+
Currently, you need to stick your API key into each test class as a
|
55
|
+
request is made to the api each time.
|
56
|
+
This could probably be mocked but I tend to prefer making the actual
|
57
|
+
request if its only for a small amount of times.
|
52
58
|
|
53
|
-
|
59
|
+
## Todo
|
54
60
|
|
55
61
|
Build a sample application to show the gem usage.
|
56
62
|
|
data/lib/rb-lomo/version.rb
CHANGED
data/lib/rb-lomo.rb
CHANGED
@@ -19,74 +19,61 @@ module Rb
|
|
19
19
|
@api_key = api_key
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def data_from url, type='photos'
|
23
23
|
resp = RestClient.get("#{API_BASE}/#{url}", params: { api_key: @api_key})
|
24
24
|
json = JSON.parse resp
|
25
25
|
|
26
26
|
retval = []
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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)}
|
27
|
+
case type
|
28
|
+
when 'photos'
|
29
|
+
json['photos'].each {|p| retval << Photo.new(p)}
|
30
|
+
when 'cameras'
|
31
|
+
json['cameras'].each {|c| retval << Camera.new(c)}
|
32
|
+
when 'films'
|
33
|
+
json['films'].each {|f| retval << Film.new(f)}
|
34
|
+
end
|
48
35
|
|
49
36
|
retval
|
50
37
|
end
|
51
38
|
|
52
39
|
def popular_photos
|
53
|
-
|
40
|
+
data_from '/photos/popular'
|
54
41
|
end
|
55
42
|
|
56
43
|
def recent_photos
|
57
|
-
|
44
|
+
data_from '/photos/recent'
|
58
45
|
end
|
59
46
|
|
60
47
|
def selected_photos
|
61
|
-
|
48
|
+
data_from 'photos/selected'
|
62
49
|
end
|
63
50
|
|
64
51
|
def cameras
|
65
|
-
|
52
|
+
data_from '/cameras', 'cameras'
|
66
53
|
end
|
67
54
|
|
68
55
|
def camera id
|
69
|
-
|
56
|
+
data_from "/cameras/#{id}", 'cameras'
|
70
57
|
end
|
71
58
|
|
72
59
|
def popular_camera_photos id
|
73
|
-
|
60
|
+
data_from "/cameras/#{id}/photos/popular"
|
74
61
|
end
|
75
62
|
|
76
63
|
def recent_camera_photos id
|
77
|
-
|
64
|
+
data_from "/cameras/#{id}/photos/recent"
|
78
65
|
end
|
79
66
|
|
80
67
|
def films
|
81
|
-
|
68
|
+
data_from '/films', 'films'
|
82
69
|
end
|
83
70
|
|
84
71
|
def popular_film_photos id
|
85
|
-
|
72
|
+
data_from "/films/#{id}/photos/popular"
|
86
73
|
end
|
87
74
|
|
88
75
|
def recent_film_photos id
|
89
|
-
|
76
|
+
data_from "/films/#{id}/photos/recent"
|
90
77
|
end
|
91
78
|
end
|
92
79
|
end
|
data/rb-lomo.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/rb-lomo/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Gary Rafferty"]
|
6
|
+
gem.email = ["gary.rafferty@gmail.com"]
|
7
|
+
gem.description = %q{Ruby library for the Lomography API}
|
8
|
+
gem.summary = %q{This gem covers most of the functionality from the Lomography API}
|
9
|
+
gem.homepage = "https://github.com/gary-rafferty/Rb-Lomo"
|
10
|
+
|
11
|
+
gem.add_dependency 'rest-client'
|
12
|
+
gem.add_dependency 'json'
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($\)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.name = "rb-lomo"
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.version = Rb::Lomo::VERSION
|
20
|
+
end
|
data/test/unit/camera.rb
CHANGED
@@ -4,5 +4,16 @@ require 'minitest/autorun'
|
|
4
4
|
require 'rb-lomo'
|
5
5
|
|
6
6
|
class CameraTest < MiniTest::Unit::TestCase
|
7
|
-
|
7
|
+
def setup
|
8
|
+
@client = Rb::Lomo::Client.new('API-KEY');
|
9
|
+
@camera = @client.cameras.sample
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_that_camera_has_an_id
|
13
|
+
refute_nil @camera.id
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_that_camera_has_a_name
|
17
|
+
refute_nil @camera.name
|
18
|
+
end
|
8
19
|
end
|
data/test/unit/client.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
$:.unshift(File.join(File.dirname(__FILE__),'..','..','lib'))
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'rb-lomo'
|
5
|
+
|
6
|
+
class Client < MiniTest::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@client = Rb::Lomo::Client.new('API-KEY')
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_popular_photos
|
12
|
+
@photos = @client.popular_photos
|
13
|
+
refute_empty @photos
|
14
|
+
assert_instance_of Array, @photos
|
15
|
+
assert_instance_of Rb::Lomo::Photo, @photos.sample
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_selected_photos
|
19
|
+
@photos = @client.selected_photos
|
20
|
+
refute_empty @photos
|
21
|
+
assert_instance_of Array, @photos
|
22
|
+
assert_instance_of Rb::Lomo::Photo, @photos.sample
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_cameras
|
26
|
+
@cameras = @client.cameras
|
27
|
+
refute_empty @cameras
|
28
|
+
assert_instance_of Array, @cameras
|
29
|
+
assert_instance_of Rb::Lomo::Camera, @cameras.sample
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_popular_camera_photos
|
33
|
+
@photos = @client.popular_camera_photos '3314883'
|
34
|
+
refute_empty @photos
|
35
|
+
assert_instance_of Array, @photos
|
36
|
+
assert_instance_of Rb::Lomo::Photo, @photos.sample
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_recent_camera_photos
|
40
|
+
@photos = @client.recent_camera_photos '3314883'
|
41
|
+
refute_empty @photos
|
42
|
+
assert_instance_of Array, @photos
|
43
|
+
assert_instance_of Rb::Lomo::Photo, @photos.sample
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_films
|
47
|
+
@films = @client.films
|
48
|
+
refute_empty @films
|
49
|
+
assert_instance_of Array, @films
|
50
|
+
assert_instance_of Rb::Lomo::Film, @films.sample
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_popular_film_photos
|
54
|
+
@photos = @client.popular_film_photos '871911028'
|
55
|
+
refute_empty @photos
|
56
|
+
assert_instance_of Array, @photos
|
57
|
+
assert_instance_of Rb::Lomo::Photo, @photos.sample
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_recent_film_photos
|
61
|
+
@photos = @client.recent_film_photos '871911028'
|
62
|
+
refute_empty @photos
|
63
|
+
assert_instance_of Array, @photos
|
64
|
+
assert_instance_of Rb::Lomo::Photo, @photos.sample
|
65
|
+
end
|
66
|
+
end
|
data/test/unit/film.rb
CHANGED
@@ -4,5 +4,16 @@ require 'minitest/autorun'
|
|
4
4
|
require 'rb-lomo'
|
5
5
|
|
6
6
|
class FilmTest < MiniTest::Unit::TestCase
|
7
|
-
|
7
|
+
def setup
|
8
|
+
@client = Rb::Lomo::Client.new('API-KEY');
|
9
|
+
@film = @client.films.sample
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_that_film_has_an_id
|
13
|
+
refute_nil @film.id
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_that_film_has_a_name
|
17
|
+
refute_nil @film.name
|
18
|
+
end
|
8
19
|
end
|
data/test/unit/photo.rb
CHANGED
@@ -8,5 +8,30 @@ class Photo < MiniTest::Unit::TestCase
|
|
8
8
|
@client = Rb::Lomo::Client.new('API-KEY')
|
9
9
|
@photo = @client.popular_photos.sample
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
|
+
def test_that_photo_has_an_id
|
13
|
+
refute_nil @photo.id
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_that_photo_has_a_url
|
17
|
+
refute_nil @photo.url
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_that_photo_returns_a_camera_object_if_data_available
|
21
|
+
if @photo.camera
|
22
|
+
assert_instance_of Rb::Lomo::Camera, @photo.camera
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_that_photo_returns_a_film_object_if_data_available
|
27
|
+
if @photo.film
|
28
|
+
assert_instance_of Rb::Lomo::Film, @photo.film
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_that_photo_returns_a_user_object_if_data_available
|
33
|
+
if @photo.user
|
34
|
+
assert_instance_of Rb::Lomo::User, @photo.user
|
35
|
+
end
|
36
|
+
end
|
12
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rb-lomo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
16
|
-
requirement: &
|
16
|
+
requirement: &18121240 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *18121240
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: json
|
27
|
-
requirement: &
|
27
|
+
requirement: &18146580 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *18146580
|
36
36
|
description: Ruby library for the Lomography API
|
37
37
|
email:
|
38
38
|
- gary.rafferty@gmail.com
|
@@ -51,7 +51,9 @@ files:
|
|
51
51
|
- lib/rb-lomo/photo.rb
|
52
52
|
- lib/rb-lomo/user.rb
|
53
53
|
- lib/rb-lomo/version.rb
|
54
|
+
- rb-lomo.gemspec
|
54
55
|
- test/unit/camera.rb
|
56
|
+
- test/unit/client.rb
|
55
57
|
- test/unit/film.rb
|
56
58
|
- test/unit/photo.rb
|
57
59
|
homepage: https://github.com/gary-rafferty/Rb-Lomo
|
@@ -80,5 +82,6 @@ specification_version: 3
|
|
80
82
|
summary: This gem covers most of the functionality from the Lomography API
|
81
83
|
test_files:
|
82
84
|
- test/unit/camera.rb
|
85
|
+
- test/unit/client.rb
|
83
86
|
- test/unit/film.rb
|
84
87
|
- test/unit/photo.rb
|