grin 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +22 -0
- data/Rakefile +14 -0
- data/lib/grin.rb +9 -0
- data/lib/grin/album.rb +27 -0
- data/lib/grin/client.rb +30 -0
- data/lib/grin/photo.rb +15 -0
- data/test/helper.rb +10 -0
- data/test/test_grin.rb +4 -0
- metadata +106 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 James Miller
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
= grin
|
2
|
+
|
3
|
+
Grin is a simple Ruby wrapper for the Fotogger API v1 specification. It currently supports finding and creating albums and photos behind
|
4
|
+
an authenticated account.
|
5
|
+
|
6
|
+
== Usage
|
7
|
+
|
8
|
+
More documentation to come.
|
9
|
+
|
10
|
+
== Note on Patches/Pull Requests
|
11
|
+
|
12
|
+
* Fork the project.
|
13
|
+
* Make your feature addition or bug fix.
|
14
|
+
* Add tests for it. This is important so I don't break it in a
|
15
|
+
future version unintentionally.
|
16
|
+
* Commit, do not mess with rakefile, version, or history.
|
17
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
18
|
+
* Send me a pull request. Bonus points for topic branches.
|
19
|
+
|
20
|
+
== Copyright
|
21
|
+
|
22
|
+
Copyright (c) 2010 James Miller. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
require 'rake/testtask'
|
5
|
+
Rake::TestTask.new(:test) do |test|
|
6
|
+
test.libs << 'lib' << 'test'
|
7
|
+
test.pattern = 'test/**/test_*.rb'
|
8
|
+
test.verbose = true
|
9
|
+
end
|
10
|
+
|
11
|
+
task :test => :check_dependencies
|
12
|
+
|
13
|
+
task :default => :test
|
14
|
+
|
data/lib/grin.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'json'
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/grin/client')
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/grin/album')
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + '/grin/photo')
|
6
|
+
|
7
|
+
module Grin
|
8
|
+
class AccessDenied < StandardError; end
|
9
|
+
end
|
data/lib/grin/album.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Grin
|
2
|
+
class Album < Client
|
3
|
+
|
4
|
+
def initialize(data, auth_string)
|
5
|
+
data.each do |key, value|
|
6
|
+
instance_variable_set("@#{key}", value)
|
7
|
+
Album.instance_eval do
|
8
|
+
attr_reader key.to_sym
|
9
|
+
end
|
10
|
+
end
|
11
|
+
@auth_string = auth_string
|
12
|
+
end
|
13
|
+
|
14
|
+
def photos
|
15
|
+
photos = []
|
16
|
+
get("albums/#{id}/photos.json").each { |photo| photos << Photo.new(photo, @auth_string) }
|
17
|
+
return photos
|
18
|
+
end
|
19
|
+
|
20
|
+
def photo(photo_id)
|
21
|
+
if photo = get("albums/#{id}/photos/#{photo_id}.json")
|
22
|
+
return Photo.new(photo, @auth_string)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/grin/client.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Grin
|
2
|
+
|
3
|
+
class Client
|
4
|
+
|
5
|
+
API_VERSION = "v1"
|
6
|
+
|
7
|
+
def initialize(subdomain, email, password)
|
8
|
+
@auth_string = CGI.escape(email) + ':' + CGI.escape(password) + "@" + subdomain
|
9
|
+
end
|
10
|
+
|
11
|
+
def albums
|
12
|
+
albums = []
|
13
|
+
get('albums.json').each { |album| albums << Album.new(album, @auth_string) }
|
14
|
+
return albums
|
15
|
+
end
|
16
|
+
|
17
|
+
def album(id)
|
18
|
+
if album = get("albums/#{id}.json")
|
19
|
+
Album.new(album, @auth_string)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def get(path, ssl = false)
|
26
|
+
JSON.parse(RestClient.get("http://#{@auth_string}.fotogger.com/api/#{API_VERSION}/#{path}").body)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
data/lib/grin/photo.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Grin
|
2
|
+
class Photo < Client
|
3
|
+
|
4
|
+
def initialize(data, auth_string)
|
5
|
+
data.each do |key, value|
|
6
|
+
instance_variable_set("@#{key}", value)
|
7
|
+
Photo.instance_eval do
|
8
|
+
attr_reader key.to_sym
|
9
|
+
end
|
10
|
+
end
|
11
|
+
@auth_string = auth_string
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
data/test/helper.rb
ADDED
data/test/test_grin.rb
ADDED
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: grin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 59
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 9
|
9
|
+
- 0
|
10
|
+
version: 0.9.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- James Miller
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-07-11 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rest-client
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 1
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 5
|
33
|
+
- 1
|
34
|
+
version: 1.5.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: json
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 1
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 4
|
49
|
+
- 3
|
50
|
+
version: 1.4.3
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
description: Grin is a simple Ruby wrapper for the Fotogger API v1 specification. It currently supports finding and creating albums and photos.
|
54
|
+
email: james@jk-tech.com
|
55
|
+
executables: []
|
56
|
+
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files: []
|
60
|
+
|
61
|
+
files:
|
62
|
+
- README.rdoc
|
63
|
+
- Rakefile
|
64
|
+
- LICENSE
|
65
|
+
- lib/grin/album.rb
|
66
|
+
- lib/grin/client.rb
|
67
|
+
- lib/grin/photo.rb
|
68
|
+
- lib/grin.rb
|
69
|
+
- test/helper.rb
|
70
|
+
- test/test_grin.rb
|
71
|
+
has_rdoc: true
|
72
|
+
homepage: http://github.com/bensie/grin
|
73
|
+
licenses: []
|
74
|
+
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: 3
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.3.7
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: Ruby wrapper for the Fotogger API
|
105
|
+
test_files: []
|
106
|
+
|