grin 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,7 @@ require 'json'
3
3
  require File.expand_path(File.dirname(__FILE__) + '/grin/client')
4
4
  require File.expand_path(File.dirname(__FILE__) + '/grin/album')
5
5
  require File.expand_path(File.dirname(__FILE__) + '/grin/photo')
6
+ require File.expand_path(File.dirname(__FILE__) + '/grin/category')
6
7
 
7
8
  module Grin
8
9
  class AccessDenied < StandardError; end
@@ -0,0 +1,15 @@
1
+ module Grin
2
+ class Category < Client
3
+
4
+ def initialize(data, auth_string)
5
+ data.each do |key, value|
6
+ instance_variable_set("@#{key}", value)
7
+ Category.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
@@ -20,13 +20,13 @@ module Grin
20
20
  end
21
21
  end
22
22
 
23
- def create_album(title, category_id = nil)
23
+ def create_album(title, category_id = categories.first.id)
24
24
  if album = post("albums.json", { :album => { :title => title, :category_id => category_id } })
25
25
  return Album.new(album, @auth_string)
26
26
  end
27
27
  end
28
28
 
29
- def find_or_create_album(title, category_id = nil)
29
+ def find_or_create_album(title, category_id)
30
30
  if album = albums.select { |a| a.title == title }.pop
31
31
  return album
32
32
  else
@@ -34,6 +34,32 @@ module Grin
34
34
  end
35
35
  end
36
36
 
37
+ def categories
38
+ categories = []
39
+ get('categories.json').each { |category| categories << Category.new(category, @auth_string) }
40
+ return categories
41
+ end
42
+
43
+ def category(id)
44
+ if category = get("categories/#{id}.json")
45
+ Category.new(category, @auth_string)
46
+ end
47
+ end
48
+
49
+ def create_category(name)
50
+ if category = post("categories.json", { :category => { :name => name } })
51
+ return Category.new(category, @auth_string)
52
+ end
53
+ end
54
+
55
+ def find_or_create_category(name)
56
+ if category = categories.select { |c| c.name == name }.pop
57
+ return category
58
+ else
59
+ create_category(name)
60
+ end
61
+ end
62
+
37
63
  private
38
64
 
39
65
  def get(path)
@@ -11,7 +11,12 @@ require 'smirk'
11
11
  fotogger = Grin::Client.new("amp", "witty@bensie.com", "littlebuddy")
12
12
  #album = fotogger.create_album("Test")
13
13
  #album = fotogger.album(15)
14
- puts fotogger.find_or_create_album("Dorman Family").inspect
14
+ #puts fotogger.find_or_create_album("Dorman Family").inspect
15
+ puts fotogger.categories.inspect
16
+
17
+ puts fotogger.category(45).inspect
18
+
19
+ puts fotogger.find_or_create_category("Test Category").inspect
15
20
  #puts fotogger.albums.select { |a| a.title == "Dorman Family"}.pop.inspect
16
21
 
17
22
  #puts album.create_photo(File.open("/Users/jkmiller/Desktop/Rome/Italy 2010-8157.jpg"))
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grin
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 61
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 2
10
- version: 0.9.2
9
+ - 3
10
+ version: 0.9.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Miller
@@ -50,7 +50,7 @@ dependencies:
50
50
  version: 1.4.3
51
51
  type: :runtime
52
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.
53
+ description: Grin is a simple Ruby wrapper for the Fotogger API v1 specification. It currently supports finding and creating albums, photos, and categories.
54
54
  email: james@jk-tech.com
55
55
  executables: []
56
56
 
@@ -63,6 +63,7 @@ files:
63
63
  - Rakefile
64
64
  - LICENSE
65
65
  - lib/grin/album.rb
66
+ - lib/grin/category.rb
66
67
  - lib/grin/client.rb
67
68
  - lib/grin/photo.rb
68
69
  - lib/grin.rb