grin 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,25 +1,24 @@
1
1
  module Grin
2
2
  class Album < Client
3
3
 
4
- def initialize(data, auth_string)
4
+ def initialize(data)
5
5
  data.each do |key, value|
6
6
  instance_variable_set("@#{key}", value)
7
7
  Album.instance_eval do
8
8
  attr_reader key.to_sym
9
9
  end
10
10
  end
11
- @auth_string = auth_string
12
11
  end
13
12
 
14
13
  def photos
15
14
  photos = []
16
- get("albums/#{id}/photos.json").each { |photo| photos << Photo.new(photo, @auth_string) }
15
+ get("albums/#{id}/photos.json").each { |photo| photos << Photo.new(photo) }
17
16
  return photos
18
17
  end
19
18
 
20
19
  def photo(photo_id)
21
20
  if photo = get("albums/#{id}/photos/#{photo_id}.json")
22
- return Photo.new(photo, @auth_string)
21
+ return Photo.new(photo)
23
22
  end
24
23
  end
25
24
 
@@ -1,14 +1,19 @@
1
1
  module Grin
2
2
  class Category < Client
3
3
 
4
- def initialize(data, auth_string)
4
+ def initialize(data)
5
5
  data.each do |key, value|
6
6
  instance_variable_set("@#{key}", value)
7
7
  Category.instance_eval do
8
8
  attr_reader key.to_sym
9
9
  end
10
10
  end
11
- @auth_string = auth_string
11
+ end
12
+
13
+ def albums
14
+ albums = []
15
+ get('albums.json').select { |album| album['category']['id'] == id }.each { |album| albums << Album.new(album) }
16
+ return albums
12
17
  end
13
18
 
14
19
  end
@@ -5,24 +5,24 @@ module Grin
5
5
  API_VERSION = "v1"
6
6
 
7
7
  def initialize(subdomain, email, password)
8
- @auth_string = CGI.escape(email) + ':' + CGI.escape(password) + "@" + subdomain
8
+ @@auth_string = CGI.escape(email) + ':' + CGI.escape(password) + "@" + subdomain
9
9
  end
10
10
 
11
11
  def albums
12
12
  albums = []
13
- get('albums.json').each { |album| albums << Album.new(album, @auth_string) }
13
+ get('albums.json').each { |album| albums << Album.new(album) }
14
14
  return albums
15
15
  end
16
16
 
17
17
  def album(id)
18
18
  if album = get("albums/#{id}.json")
19
- Album.new(album, @auth_string)
19
+ Album.new(album)
20
20
  end
21
21
  end
22
22
 
23
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
- return Album.new(album, @auth_string)
25
+ return Album.new(album)
26
26
  end
27
27
  end
28
28
 
@@ -36,19 +36,19 @@ module Grin
36
36
 
37
37
  def categories
38
38
  categories = []
39
- get('categories.json').each { |category| categories << Category.new(category, @auth_string) }
39
+ get('categories.json').each { |category| categories << Category.new(category) }
40
40
  return categories
41
41
  end
42
42
 
43
43
  def category(id)
44
44
  if category = get("categories/#{id}.json")
45
- Category.new(category, @auth_string)
45
+ Category.new(category)
46
46
  end
47
47
  end
48
48
 
49
49
  def create_category(name)
50
50
  if category = post("categories.json", { :category => { :name => name } })
51
- return Category.new(category, @auth_string)
51
+ return Category.new(category)
52
52
  end
53
53
  end
54
54
 
@@ -63,11 +63,11 @@ module Grin
63
63
  private
64
64
 
65
65
  def get(path)
66
- JSON.parse(RestClient.get("http://#{@auth_string}.fotogger.com/api/#{API_VERSION}/#{path}").body)
66
+ JSON.parse(RestClient.get("http://#{@@auth_string}.fotogger.com/api/#{API_VERSION}/#{path}").body)
67
67
  end
68
68
 
69
69
  def post(path, params = {})
70
- JSON.parse(RestClient.post("http://#{@auth_string}.fotogger.com/api/#{API_VERSION}/#{path}", params).body)
70
+ JSON.parse(RestClient.post("http://#{@@auth_string}.fotogger.com/api/#{API_VERSION}/#{path}", params).body)
71
71
  end
72
72
 
73
73
  end
@@ -1,14 +1,13 @@
1
1
  module Grin
2
2
  class Photo < Client
3
3
 
4
- def initialize(data, auth_string)
4
+ def initialize(data)
5
5
  data.each do |key, value|
6
6
  instance_variable_set("@#{key}", value)
7
7
  Photo.instance_eval do
8
8
  attr_reader key.to_sym
9
9
  end
10
10
  end
11
- @auth_string = auth_string
12
11
  end
13
12
 
14
13
  end
@@ -14,9 +14,9 @@ fotogger = Grin::Client.new("amp", "witty@bensie.com", "littlebuddy")
14
14
  #puts fotogger.find_or_create_album("Dorman Family").inspect
15
15
  puts fotogger.categories.inspect
16
16
 
17
- puts fotogger.category(45).inspect
17
+ puts fotogger.category(45).albums
18
18
 
19
- puts fotogger.find_or_create_category("Test Category").inspect
19
+ #puts fotogger.find_or_create_category("Test Category").inspect
20
20
  #puts fotogger.albums.select { |a| a.title == "Dorman Family"}.pop.inspect
21
21
 
22
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: 61
4
+ hash: 51
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 3
10
- version: 0.9.3
9
+ - 4
10
+ version: 0.9.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Miller