grin 0.9.4 → 1.0.0

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.
@@ -4,11 +4,11 @@ Grin is a simple Ruby wrapper for the Fotogger API v1 specification. It currentl
4
4
  an authenticated account.
5
5
 
6
6
  == Usage
7
-
7
+
8
8
  More documentation to come.
9
-
9
+
10
10
  == Note on Patches/Pull Requests
11
-
11
+
12
12
  * Fork the project.
13
13
  * Make your feature addition or bug fix.
14
14
  * Add tests for it. This is important so I don't break it in a
@@ -1,6 +1,6 @@
1
1
  module Grin
2
2
  class Album < Client
3
-
3
+
4
4
  def initialize(data)
5
5
  data.each do |key, value|
6
6
  instance_variable_set("@#{key}", value)
@@ -9,23 +9,23 @@ module Grin
9
9
  end
10
10
  end
11
11
  end
12
-
12
+
13
13
  def photos
14
14
  photos = []
15
15
  get("albums/#{id}/photos.json").each { |photo| photos << Photo.new(photo) }
16
16
  return photos
17
17
  end
18
-
18
+
19
19
  def photo(photo_id)
20
20
  if photo = get("albums/#{id}/photos/#{photo_id}.json")
21
21
  return Photo.new(photo)
22
22
  end
23
23
  end
24
-
24
+
25
25
  def create_photo(image_data)
26
26
  post("albums/#{id}/photos.json", { :photo => { :image => image_data } })
27
27
  end
28
-
28
+
29
29
  def find_or_create_photo(filename, image_data)
30
30
  if photo = photos.select { |p| p.filename == filename }.pop
31
31
  return photo
@@ -33,6 +33,6 @@ module Grin
33
33
  create_photo(image_data)
34
34
  end
35
35
  end
36
-
36
+
37
37
  end
38
38
  end
@@ -1,6 +1,6 @@
1
1
  module Grin
2
2
  class Category < Client
3
-
3
+
4
4
  def initialize(data)
5
5
  data.each do |key, value|
6
6
  instance_variable_set("@#{key}", value)
@@ -9,12 +9,12 @@ module Grin
9
9
  end
10
10
  end
11
11
  end
12
-
12
+
13
13
  def albums
14
14
  albums = []
15
15
  get('albums.json').select { |album| album['category']['id'] == id }.each { |album| albums << Album.new(album) }
16
16
  return albums
17
17
  end
18
-
18
+
19
19
  end
20
20
  end
@@ -1,31 +1,33 @@
1
+ require 'cgi'
1
2
  module Grin
2
3
 
3
4
  class Client
4
-
5
+
5
6
  API_VERSION = "v1"
6
-
7
+ DOMAIN = "fotogger.com"
8
+
7
9
  def initialize(subdomain, email, password)
8
10
  @@auth_string = CGI.escape(email) + ':' + CGI.escape(password) + "@" + subdomain
9
11
  end
10
-
12
+
11
13
  def albums
12
14
  albums = []
13
15
  get('albums.json').each { |album| albums << Album.new(album) }
14
16
  return albums
15
17
  end
16
-
18
+
17
19
  def album(id)
18
20
  if album = get("albums/#{id}.json")
19
21
  Album.new(album)
20
22
  end
21
23
  end
22
-
24
+
23
25
  def create_album(title, category_id = categories.first.id)
24
26
  if album = post("albums.json", { :album => { :title => title, :category_id => category_id } })
25
27
  return Album.new(album)
26
28
  end
27
29
  end
28
-
30
+
29
31
  def find_or_create_album(title, category_id)
30
32
  if album = albums.select { |a| a.title == title }.pop
31
33
  return album
@@ -33,25 +35,25 @@ module Grin
33
35
  create_album(title, category_id)
34
36
  end
35
37
  end
36
-
38
+
37
39
  def categories
38
40
  categories = []
39
41
  get('categories.json').each { |category| categories << Category.new(category) }
40
42
  return categories
41
43
  end
42
-
44
+
43
45
  def category(id)
44
46
  if category = get("categories/#{id}.json")
45
47
  Category.new(category)
46
48
  end
47
49
  end
48
-
50
+
49
51
  def create_category(name)
50
52
  if category = post("categories.json", { :category => { :name => name } })
51
53
  return Category.new(category)
52
54
  end
53
55
  end
54
-
56
+
55
57
  def find_or_create_category(name)
56
58
  if category = categories.select { |c| c.name == name }.pop
57
59
  return category
@@ -59,16 +61,16 @@ module Grin
59
61
  create_category(name)
60
62
  end
61
63
  end
62
-
64
+
63
65
  private
64
-
66
+
65
67
  def get(path)
66
- JSON.parse(RestClient.get("http://#{@@auth_string}.fotogger.com/api/#{API_VERSION}/#{path}").body)
68
+ JSON.parse(RestClient.get("http://#{@@auth_string}.#{DOMAIN}/api/#{API_VERSION}/#{path}"))
67
69
  end
68
-
70
+
69
71
  def post(path, params = {})
70
- JSON.parse(RestClient.post("http://#{@@auth_string}.fotogger.com/api/#{API_VERSION}/#{path}", params).body)
72
+ JSON.parse(RestClient.post("http://#{@@auth_string}.#{DOMAIN}/api/#{API_VERSION}/#{path}", params))
71
73
  end
72
-
74
+
73
75
  end
74
76
  end
@@ -1,6 +1,6 @@
1
1
  module Grin
2
2
  class Photo < Client
3
-
3
+
4
4
  def initialize(data)
5
5
  data.each do |key, value|
6
6
  instance_variable_set("@#{key}", value)
@@ -9,6 +9,6 @@ module Grin
9
9
  end
10
10
  end
11
11
  end
12
-
12
+
13
13
  end
14
14
  end
@@ -1,22 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'grin'
3
- require 'smirk'
4
3
 
5
- # smug = Smirk::Client.new("teamwylie@hotmail.com", "carter")
6
- # smug_album = smug.find_album(id, key)
7
- # smug_album.images(true).each do |image|
8
- # `curl #{image.originalurl} -o #{image.filename}`
9
- # end
10
-
11
- fotogger = Grin::Client.new("amp", "witty@bensie.com", "littlebuddy")
12
- #album = fotogger.create_album("Test")
13
- #album = fotogger.album(15)
14
- #puts fotogger.find_or_create_album("Dorman Family").inspect
15
- puts fotogger.categories.inspect
16
-
17
- puts fotogger.category(45).albums
18
-
19
- #puts fotogger.find_or_create_category("Test Category").inspect
20
- #puts fotogger.albums.select { |a| a.title == "Dorman Family"}.pop.inspect
21
-
22
- #puts album.create_photo(File.open("/Users/jkmiller/Desktop/Rome/Italy 2010-8157.jpg"))
4
+ @fotogger = Grin::Client.new("bensie", "bensie@gmail.com", "jkmeslyl")
5
+ p @fotogger.albums
@@ -1,4 +1,41 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestGrin < Test::Unit::TestCase
4
+ SUBDOMAIN = ""
5
+ EMAIL = ""
6
+ PASSWORD = ""
7
+
8
+ context "New connection" do
9
+
10
+ setup do
11
+ @fotogger = Grin::Client.new(SUBDOMAIN, EMAIL, PASSWORD)
12
+ end
13
+
14
+ should "return albums and categories without errors" do
15
+ assert_nothing_raised do
16
+ @fotogger.albums
17
+ @fotogger.categories
18
+ end
19
+ end
20
+
21
+ context "creating albums and categories" do
22
+ setup do
23
+ @category = @fotogger.find_or_create_category("My Category")
24
+ @album = @fotogger.find_or_create_album("My Album", @category.id)
25
+ end
26
+
27
+ should "return the category name" do
28
+ assert_equal @category.name, "My Category"
29
+ end
30
+
31
+ should "return the album title and category name" do
32
+ @category = @fotogger.find_or_create_category("My Category")
33
+
34
+ assert_equal @album.title, "My Album"
35
+ assert_equal @album.category['name'], @category.name
36
+ end
37
+ end
38
+
39
+ end
40
+
4
41
  end
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: 51
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
+ - 1
7
8
  - 0
8
- - 9
9
- - 4
10
- version: 0.9.4
9
+ - 0
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Miller
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-16 00:00:00 -07:00
18
+ date: 2010-08-26 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -24,14 +24,14 @@ dependencies:
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ">="
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- hash: 1
29
+ hash: 15
30
30
  segments:
31
31
  - 1
32
- - 5
33
- - 1
34
- version: 1.5.1
32
+ - 6
33
+ - 0
34
+ version: 1.6.0
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ">="
43
+ - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  hash: 1
46
46
  segments:
@@ -50,6 +50,20 @@ dependencies:
50
50
  version: 1.4.3
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: shoulda
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ type: :development
66
+ version_requirements: *id003
53
67
  description: Grin is a simple Ruby wrapper for the Fotogger API v1 specification. It currently supports finding and creating albums, photos, and categories.
54
68
  email: james@jk-tech.com
55
69
  executables: []