slideshowpro 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Dan Hixon
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.md ADDED
@@ -0,0 +1,57 @@
1
+ SlideShowPro Director API Wrapper
2
+ ============
3
+
4
+ Ruby wrapper for the SlideShowPro Director API. Allows you to request album and gallery information.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Include in your Gemfile:
10
+
11
+ gem "slideshowpro"
12
+
13
+ Or just install it:
14
+
15
+ gem install slideshowpro
16
+
17
+ This gem currently requires 'curl' - it calls it using back ticks. TODO: use curb instead so the dependency can be declared.
18
+
19
+ Usage
20
+ -----
21
+
22
+ ssp = Slideshowpro::Director.new('http://yoururl.com/api/','your-api-key')
23
+
24
+ Get a Gallery:
25
+
26
+ albums = ssp.get_gallery(gallery_id, :preview=>{:size => '123x35',:crop => 1, :quality => 90})
27
+ albums.each do |album|
28
+ puts album['name']
29
+ puts album['id']
30
+ end
31
+
32
+ Get an Album:
33
+
34
+ album = ssp.get_album(album_id, {:large=>{:size => '225x350', :crop => 0, :quality => 95, :sharpening => 0}})
35
+ album.each do |image|
36
+ puts image["large"]["url"]
37
+ puts image["thumb"]["url"]
38
+ puts image["thumb"]["width"]
39
+ puts image["thumb"]["height"]
40
+ end
41
+
42
+ Caching
43
+ --------
44
+
45
+ This gem will cache the API responses if you define a CACHE constant in your app. Only tested with memcachd but should work with anything that responds to 'get' and 'set' methods.
46
+
47
+ Example:
48
+
49
+ require 'memcached'
50
+ CACHE = Memcached.new
51
+
52
+ Enjoy!
53
+
54
+ License
55
+ -------
56
+
57
+ Slideshowpro gem is Copyright © 2010-2011 Dan Hixon. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
@@ -0,0 +1,62 @@
1
+ require 'uri'
2
+ module Slideshowpro
3
+ class Director
4
+ attr_accessor :api_key, :url
5
+ def initialize(url, api_key, *options)
6
+ self.url = url
7
+ self.api_key = api_key
8
+ end
9
+ def post(method, options)
10
+ params = {
11
+ 'data[api_key]'=>self.api_key,
12
+ 'data[breaker]'=>'true',
13
+ 'data[format]'=>'json'
14
+ }
15
+ params.merge!(options)
16
+ data = URI.escape(params.map {|k,v| "#{URI.escape(k)}=#{URI.escape(v.to_s)}"}.join("&"))
17
+
18
+ if defined?(CACHE) && CACHE.respond_to?(:get)
19
+ require 'digest/md5'
20
+ data_key = Digest::MD5.hexdigest(method + "|" + data)
21
+ begin
22
+ json=CACHE.get(data_key)
23
+ rescue Memcached::NotFound
24
+ json = get_json(url, method, data)
25
+ CACHE.set(data_key, json)
26
+ rescue Memcached::ServerIsMarkedDead
27
+ puts "Memcache Down!"
28
+ #fall back to get data directly
29
+ json = get_json(url, method, data)
30
+ end
31
+ else
32
+ json = get_json(url, method, data)
33
+ end
34
+ return json
35
+ end
36
+ def get_album(album_id, formats={:thumb=>{:size=>'41x41',:quality=> 85},:large=>{:crop=>0,:size=>'750x750', :sharpening=>0}})
37
+ raw = post('get_album', format_hash(formats).merge('data[album_id]'=>album_id))
38
+ raw["data"]["contents"]
39
+ end
40
+ def get_gallery(gallery_id, formats={:preview=>{:size => '123x35',:crop => 1, :quality => 90}})
41
+ raw = post('get_gallery', format_hash(formats).merge('data[gallery_id]'=>gallery_id))
42
+ raw["data"]["albums"]
43
+ end
44
+ def format_hash(formats)
45
+ default_format_params = {:crop=>1, :quality=>'90', :sharpening=>1}
46
+ r = {}
47
+ formats.each do |name, format|
48
+ f = default_format_params.merge(format)
49
+ if name==:preview
50
+ r["data[preview]"] = "#{f[:size].gsub('x',',')},#{f[:crop]},#{f[:quality]},#{f[:sharpening]}"
51
+ else
52
+ r["data[size][#{name}]"] = "#{name},#{f[:size].gsub('x',',')},#{f[:crop]},#{f[:quality]},#{f[:sharpening]}"
53
+ end
54
+ end
55
+ r
56
+ end
57
+ protected
58
+ def get_json(url, method, data)
59
+ Crack::JSON.parse(`curl --silent #{url+method} --data "#{data}"`)
60
+ end
61
+ end
62
+ end
@@ -1,3 +1,3 @@
1
1
  module Slideshowpro
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slideshowpro
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dan Hixon
@@ -46,8 +46,11 @@ extra_rdoc_files: []
46
46
  files:
47
47
  - .gitignore
48
48
  - Gemfile
49
+ - MIT-LICENSE
50
+ - README.md
49
51
  - Rakefile
50
52
  - lib/slideshowpro.rb
53
+ - lib/slideshowpro/director.rb
51
54
  - lib/slideshowpro/version.rb
52
55
  - slideshowpro.gemspec
53
56
  has_rdoc: true