phono 0.1 → 0.2

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.
Files changed (5) hide show
  1. data/.gitignore +1 -0
  2. data/README.md +7 -0
  3. data/lib/phono/client.rb +62 -51
  4. data/phono.gemspec +2 -1
  5. metadata +16 -5
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ Thumbs.db
4
4
  *.gem
5
5
  .rvmrc
6
6
  ~*
7
+ *.php
data/README.md CHANGED
@@ -69,3 +69,10 @@ Get a resized and cropped version :
69
69
  You can also force the resize (with deformation) :
70
70
 
71
71
  "#{instance['picture']}?size=300x200&force=true"
72
+
73
+ ## Cache control
74
+
75
+ All JSON responses are cached (5 minutes by default) for performance.
76
+ You can override this timeout by passing the value you want as a 2nd parameter to the client's constructor :
77
+
78
+ Phono::Client.new('424242424242424242424242', 3600) # responses will be cached for 1 hour
@@ -1,56 +1,67 @@
1
1
  require 'httparty'
2
+ require 'httparty-icebox'
2
3
  require 'active_support'
4
+ require 'active_support/core_ext/hash/keys'
3
5
 
4
6
  module Phono
5
- class Client
6
- include HTTParty
7
-
8
- base_uri 'http://phono.phonoid.com/api'
9
-
10
- def initialize(api_key)
11
- @api_key = api_key
12
- end
13
-
14
- def all(ref, params = {})
15
- self.class.get("/#{ref}.json", {
16
- :query => base_params.merge!(params)
17
- })
18
- end
19
-
20
- def find(ref, id)
21
- self.class.get("/#{ref}/#{id}.json", {
22
- :query => base_params
23
- })
24
- end
25
-
26
- def create(ref, attributes = {})
27
- self.class.post("/#{ref}.json", {
28
- :query => base_params.merge!({
29
- ref.singularize.to_sym => attributes
30
- })
31
- })
32
- end
33
-
34
- def update(ref, id, params = {})
35
- self.class.put("/#{ref}/#{id}.json", {
36
- :query => base_params.merge!({
37
- ref.singularize.to_sym => attributes
38
- })
39
- })
40
- end
41
-
42
- def destroy(ref, id)
43
- self.class.delete("/#{ref}/#{id}.json", {
44
- :query => base_params
45
- })
46
- end
47
-
48
- protected
49
-
50
- def base_params
51
- {
52
- :api_key => @api_key
53
- }
54
- end
55
- end
7
+ class Client
8
+ include HTTParty
9
+ include HTTParty::Icebox
10
+
11
+ base_uri 'http://phono.phonoid.com/api'
12
+
13
+ def initialize(api_key, params = {})
14
+ @api_key = api_key
15
+
16
+ self.class.cache(:timeout => params[:cache_timeout] || 60)
17
+ end
18
+
19
+ def all(ref, params = {})
20
+ params.stringify_keys!
21
+ method = params.delete('cache').nil? ? :get : :get_without_caching
22
+
23
+ self.class.send(method, "/#{ref}.json", {
24
+ :query => base_params.merge!(params)
25
+ })
26
+ end
27
+
28
+ def find(ref, id, params = {})
29
+ params.stringify_keys!
30
+ method = params.delete('cache').nil? ? :get : :get_without_caching
31
+
32
+ self.class.send(method, "/#{ref}/#{id}.json", {
33
+ :query => base_params
34
+ })
35
+ end
36
+
37
+ def create(ref, attributes = {})
38
+ self.class.post("/#{ref}.json", {
39
+ :query => base_params.merge!({
40
+ ref.singularize.to_sym => attributes
41
+ })
42
+ })
43
+ end
44
+
45
+ def update(ref, id, params = {})
46
+ self.class.put("/#{ref}/#{id}.json", {
47
+ :query => base_params.merge!({
48
+ ref.singularize.to_sym => attributes
49
+ })
50
+ })
51
+ end
52
+
53
+ def destroy(ref, id)
54
+ self.class.delete("/#{ref}/#{id}.json", {
55
+ :query => base_params
56
+ })
57
+ end
58
+
59
+ protected
60
+
61
+ def base_params
62
+ {
63
+ :api_key => @api_key
64
+ }
65
+ end
66
+ end
56
67
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{phono}
5
- s.version = "0.1"
5
+ s.version = "0.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Aurélien Malisart"]
@@ -29,5 +29,6 @@ Gem::Specification.new do |s|
29
29
  s.specification_version = 3
30
30
  s.add_dependency(%q<httparty>)
31
31
  s.add_dependency(%q<activesupport>, '>= 2.0.0')
32
+ s.add_dependency(%q<httparty-icebox>)
32
33
  end
33
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phono
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-04 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &2163328660 !ruby/object:Gem::Requirement
16
+ requirement: &2164742740 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2163328660
24
+ version_requirements: *2164742740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &2163328120 !ruby/object:Gem::Requirement
27
+ requirement: &2164741160 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,18 @@ dependencies:
32
32
  version: 2.0.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2163328120
35
+ version_requirements: *2164741160
36
+ - !ruby/object:Gem::Dependency
37
+ name: httparty-icebox
38
+ requirement: &2164739120 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2164739120
36
47
  description: Simple Ruby client for the Phono API
37
48
  email: aurelien.malisart@gmail.com
38
49
  executables: []