grin 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,8 +17,11 @@ module Grin
17
17
  end
18
18
 
19
19
  def photo(photo_id)
20
- if photo = get("albums/#{id}/photos/#{photo_id}.json")
21
- return Photo.new(photo)
20
+ photo = get("albums/#{id}/photos/#{photo_id}.json")
21
+ if photo.respond_to?(:[]) && photo['status'] == 'error'
22
+ return photo
23
+ else
24
+ Photo.new(photo)
22
25
  end
23
26
  end
24
27
 
@@ -17,14 +17,20 @@ module Grin
17
17
  end
18
18
 
19
19
  def album(id)
20
- if album = get("albums/#{id}.json")
20
+ album = get("albums/#{id}.json")
21
+ if album.respond_to?(:[]) && album['status'] == 'error'
22
+ return album
23
+ else
21
24
  Album.new(album)
22
25
  end
23
26
  end
24
27
 
25
28
  def create_album(title, category_id = categories.first.id)
26
- if album = post("albums.json", { :album => { :title => title, :category_id => category_id } })
27
- return Album.new(album)
29
+ album = post("albums.json", { :album => { :title => title, :category_id => category_id } })
30
+ if album.respond_to?(:[]) && album['status'] == 'error'
31
+ return album
32
+ else
33
+ Album.new(album)
28
34
  end
29
35
  end
30
36
 
@@ -43,19 +49,26 @@ module Grin
43
49
  end
44
50
 
45
51
  def category(id)
46
- if category = get("categories/#{id}.json")
52
+ category = get("categories/#{id}.json")
53
+ if category.respond_to?(:[]) && category['status'] == 'error'
54
+ return category
55
+ else
47
56
  Category.new(category)
48
57
  end
49
58
  end
50
59
 
51
60
  def create_category(name)
52
- if category = post("categories.json", { :category => { :name => name } })
53
- return Category.new(category)
61
+ category = post("categories.json", { :category => { :name => name } })
62
+ if category.respond_to?(:[]) && category['status'] == 'error'
63
+ return category
64
+ else
65
+ Category.new(category)
54
66
  end
55
67
  end
56
68
 
57
69
  def find_or_create_category(name)
58
- if category = categories.select { |c| c.name == name }.pop
70
+ category = categories.select { |c| c.name == name }.pop
71
+ if category
59
72
  return category
60
73
  else
61
74
  create_category(name)
@@ -65,15 +78,19 @@ module Grin
65
78
  private
66
79
 
67
80
  def get(path)
68
- JSON.parse(RestClient.get("http://#{@@auth_string}.#{DOMAIN}/api/#{API_VERSION}/#{path}"))
81
+ JSON.parse(RestClient.get(url(path)))
69
82
  end
70
83
 
71
84
  def post(path, params = {})
72
- JSON.parse(RestClient.post("http://#{@@auth_string}.#{DOMAIN}/api/#{API_VERSION}/#{path}", params))
85
+ JSON.parse(RestClient.post(url(path), params))
73
86
  end
74
87
 
75
88
  def delete(path)
76
- JSON.parse(RestClient.delete("http://#{@@auth_string}.#{DOMAIN}/api/#{API_VERSION}/#{path}"))
89
+ JSON.parse(RestClient.delete(url(path)))
90
+ end
91
+
92
+ def url(path)
93
+ "http://#{@@auth_string}.#{DOMAIN}/api/#{API_VERSION}/#{path}"
77
94
  end
78
95
 
79
96
  end
@@ -2,5 +2,8 @@ require 'rubygems'
2
2
  require 'grin'
3
3
 
4
4
  @fotogger = Grin::Client.new("bensie", "bensie@gmail.com", "jkmeslyl")
5
- p @fotogger.albums
6
- p @fotogger.category(17).destroy
5
+ #p @fotogger.categories.first.destroy
6
+ p @fotogger.category(234)
7
+ p x = @fotogger.find_or_create_category("Test") # 34
8
+ p x.destroy
9
+
@@ -37,7 +37,7 @@ class TestGrin < Test::Unit::TestCase
37
37
 
38
38
  should "not allow you to delete the category when the album exists" do
39
39
  response = @category.destroy
40
- assert_equal "Cannot delete category that contains albums", response['error']
40
+ assert_equal "Cannot delete record because of dependent albums", response['error']
41
41
  end
42
42
 
43
43
  should "delete the album followed by the category" do
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grin
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
5
4
  prerelease: false
6
5
  segments:
7
6
  - 1
8
- - 1
9
- - 1
10
- version: 1.1.1
7
+ - 2
8
+ - 0
9
+ version: 1.2.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - James Miller
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-08-27 00:00:00 -07:00
17
+ date: 2010-09-09 00:00:00 -07:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ~>
28
27
  - !ruby/object:Gem::Version
29
- hash: 15
30
28
  segments:
31
29
  - 1
32
30
  - 6
@@ -42,7 +40,6 @@ dependencies:
42
40
  requirements:
43
41
  - - ~>
44
42
  - !ruby/object:Gem::Version
45
- hash: 1
46
43
  segments:
47
44
  - 1
48
45
  - 4
@@ -58,7 +55,6 @@ dependencies:
58
55
  requirements:
59
56
  - - ">="
60
57
  - !ruby/object:Gem::Version
61
- hash: 3
62
58
  segments:
63
59
  - 0
64
60
  version: "0"
@@ -98,7 +94,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
94
  requirements:
99
95
  - - ">="
100
96
  - !ruby/object:Gem::Version
101
- hash: 3
102
97
  segments:
103
98
  - 0
104
99
  version: "0"
@@ -107,7 +102,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
102
  requirements:
108
103
  - - ">="
109
104
  - !ruby/object:Gem::Version
110
- hash: 3
111
105
  segments:
112
106
  - 0
113
107
  version: "0"